Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dependabot/github_actions/action…
Browse files Browse the repository at this point in the history
…s/dependency-review-action-3.1.4' into dependabot/github_actions/actions/dependency-review-action-3.1.4
  • Loading branch information
sitaram-kalluri committed Dec 7, 2023
2 parents 0c93f2c + 144dab6 commit d2c62c0
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/at_client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.0.69
- feat: Add AtRpcClient for a much cleaner developer experience for sending AtRpc requests
## 3.0.68
- feat: have AtRpc use ephemeral notifications
## 3.0.67
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AtClientConfig {

/// Represents the at_client version.
/// Must always be the same as the actual version in pubspec.yaml
final String atClientVersion = '3.0.68';
final String atClientVersion = '3.0.69';

/// Represents the client commit log compaction time interval
///
Expand Down
74 changes: 74 additions & 0 deletions packages/at_client/lib/src/rpc/at_rpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,80 @@ abstract class AtRpcCallbacks {
Future<void> handleResponse(AtRpcResp response);
}

@experimental
class AtRpcClient implements AtRpcCallbacks {
static final AtSignLogger logger = AtSignLogger(' AtRpcClient ',
loggingHandler: AtSignLogger.stdErrLoggingHandler);

late final String serverAtsign;
late final AtRpc rpc;

Map<int, Completer<Map<String, dynamic>>> completerMap = {};

AtRpcClient({
required String serverAtsign,
required AtClient atClient,
required String baseNameSpace, // e.g. my_app
String rpcsNameSpace = '__rpcs',
required String domainNameSpace, // e.g. math_evaluator
}) {
this.serverAtsign = AtUtils.fixAtSign(serverAtsign);
rpc = AtRpc(
atClient: atClient,
baseNameSpace: baseNameSpace,
rpcsNameSpace: rpcsNameSpace,
domainNameSpace: domainNameSpace,
callbacks: this,
allowList: {},
);
rpc.start();
}

Future<Map<String, dynamic>> call(Map<String, dynamic> payload) async {
AtRpcReq request = AtRpcReq.create(payload);
completerMap[request.reqId] = Completer();
logger.info('Sending request to $serverAtsign : $request');
await rpc.sendRequest(toAtSign: serverAtsign, request: request);
return completerMap[request.reqId]!.future;
}

@override
Future<AtRpcResp> handleRequest(AtRpcReq request, String fromAtSign) {
// We're just a client, we don't handle requests
throw UnimplementedError();
}

@override
Future<void> handleResponse(AtRpcResp response) async {
logger.info('Got response ${response.payload}');

final Completer? completer = completerMap[response.reqId];

if (completer == null || completer.isCompleted) {
logger.warning('Ignoring response, no completer found : $response');
return;
}

switch (response.respType) {
case AtRpcRespType.ack:
// We don't complete the future when we get an ack
logger.info('Got ack : $response');
break;
case AtRpcRespType.success:
logger.info('Got success response : $response');
completer.complete(response.payload);
completerMap.remove(response.reqId);
break;
default:
logger.warning('Got non-success response '
' : $response');
completer.completeError('Got non-success response : $response');
completerMap.remove(response.reqId);
break;
}
}
}

/// A simple rpc request-response abstraction which uses atProtocol
/// notifications under the hood.
/// - 'requests' are sent as notifications with a 'key' like:
Expand Down
6 changes: 6 additions & 0 deletions packages/at_client/lib/src/rpc/at_rpc_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class AtRpcReq {
static AtRpcReq fromJson(Map<String, dynamic> json) {
return AtRpcReq(reqId: json['reqId'], payload: json['payload']);
}

@override
String toString() => toJson().toString();
}

/// The types of responses which the responder can send back to the requester
Expand Down Expand Up @@ -92,4 +95,7 @@ class AtRpcResp {
'payload': payload,
'message': message
};

@override
String toString() => toJson().toString();
}
2 changes: 1 addition & 1 deletion packages/at_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: The at_client library is the non-platform specific Client SDK which
##
##
## NB: When incrementing the version, please also increment the version in AtClientConfig file
version: 3.0.68
version: 3.0.69
## NB: When incrementing the version, please also increment the version in AtClientConfig file
##

Expand Down

0 comments on commit d2c62c0

Please sign in to comment.