From 3e5215ca40ba1478e7f4689bb72c259fd9313d27 Mon Sep 17 00:00:00 2001 From: Muzzammil Shahid Date: Mon, 13 May 2024 14:44:58 +0500 Subject: [PATCH 1/2] Add name of parameters in invocation and event function --- lib/src/session.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/session.dart b/lib/src/session.dart index 210b127..a2e5224 100644 --- a/lib/src/session.dart +++ b/lib/src/session.dart @@ -133,7 +133,7 @@ class Session { return completer.future; } - Future register(String procedure, Result Function(Invocation) endpoint) { + Future register(String procedure, Result Function(Invocation invocation) endpoint) { var register = msg.Register(_nextID, procedure); var completer = Completer(); @@ -174,7 +174,7 @@ class Session { return null; } - Future subscribe(String topic, void Function(Event) endpoint) { + Future subscribe(String topic, void Function(Event event) endpoint) { var subscribe = msg.Subscribe(_nextID, topic); var completer = Completer(); From a9f06913102a15440073f4bf0421fef8baff2ce7 Mon Sep 17 00:00:00 2001 From: Muzzammil Shahid Date: Tue, 14 May 2024 15:58:50 +0500 Subject: [PATCH 2/2] Add example for local server and client --- example/in_memory_router.dart | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 example/in_memory_router.dart diff --git a/example/in_memory_router.dart b/example/in_memory_router.dart new file mode 100644 index 0000000..1ecf7ef --- /dev/null +++ b/example/in_memory_router.dart @@ -0,0 +1,42 @@ +import "package:wampproto/serializers.dart"; + +import "package:xconn/exports.dart"; +import "package:xconn/src/types.dart"; + +const procedureName = "io.xconn.example_procedure"; +const topicName = "io.xconn.example_topic"; + +void main() async { + var router = Router()..addRealm("realm1"); + + var serializer = JSONSerializer(); + var clientSideBase = ClientSideLocalBaseSession(1, "realm1", "local", "local", serializer, router); + var serverSideBase = ServerSideLocalBaseSession(1, "realm1", "local", "local", serializer, other: clientSideBase); + + router.attachClient(serverSideBase); + + var session = Session(clientSideBase); + + // register a procedure + var registration = await session.register(procedureName, (inv) { + return Result(args: inv.args, kwargs: inv.kwargs, details: inv.details); + }); + + // call a procedure + var result = await session.call(procedureName, args: ["abc"]); + print("Result: args=${result.args}, kwargs=${result.kwargs}, details=${result.details}"); + + // unregister a procedure + await session.unregister(registration); + + // subscribe to a topic + var subscription = await session.subscribe(topicName, (event) { + print("Event: args=${event.args}, kwargs=${event.kwargs}, details=${event.details}"); + }); + + // publish to a topic + await session.publish(topicName, args: ["abc"], kwargs: {"one": 1}, options: {"acknowledge": true}); + + // unsubscribe from a topic + await session.unsubscribe(subscription); +}