-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from muzzammilshahid/wamp-actions
Add functions for basic WAMP actions
- Loading branch information
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import "package:wampproto/auth.dart"; | ||
import "package:wampproto/serializers.dart"; | ||
import "package:xconn/exports.dart"; | ||
|
||
import "package:xconn_ui/constants.dart"; | ||
|
||
Serializer _getSerializer(String? serializerString) { | ||
switch (serializerString) { | ||
case jsonSerializer: | ||
return JSONSerializer(); | ||
case cborSerializer: | ||
return CBORSerializer(); | ||
case msgPackSerializer: | ||
return MsgPackSerializer(); | ||
|
||
default: | ||
throw Exception("invalid serializer $serializerString"); | ||
} | ||
} | ||
|
||
Future<Session> connect( | ||
String url, | ||
String realm, | ||
String serializerStr, { | ||
String? authid, | ||
String? authrole, | ||
String? ticket, | ||
String? secret, | ||
String? privateKey, | ||
}) async { | ||
var serializer = _getSerializer(serializerStr); | ||
Client client; | ||
|
||
if (ticket != null) { | ||
client = Client(serializer: serializer, authenticator: TicketAuthenticator(ticket, authid ?? "")); | ||
} else if (secret != null) { | ||
client = Client(serializer: serializer, authenticator: WAMPCRAAuthenticator(secret, authid ?? "", {})); | ||
} else if (privateKey != null) { | ||
client = Client(serializer: serializer, authenticator: CryptoSignAuthenticator(authid ?? "", privateKey)); | ||
} else { | ||
client = Client(serializer: serializer); | ||
} | ||
|
||
return client.connect(url, realm); | ||
} | ||
|
||
Future<Registration> register(Session session, String procedure) { | ||
return session.register(procedure, (Invocation inv) { | ||
return Result(args: inv.args, kwargs: inv.kwargs); | ||
}); | ||
} | ||
|
||
Future<Result> call(Session session, String procedure, {List? args, Map<String, dynamic>? kwargs}) { | ||
return session.call(procedure, args: args, kwargs: kwargs); | ||
} | ||
|
||
Future<Subscription> subscribe(Session session, String topic) { | ||
return session.subscribe(topic, (Event event) {}); | ||
} | ||
|
||
Future<void>? publish(Session session, String topic, {List? args, Map<String, dynamic>? kwargs}) { | ||
return session.publish(topic, args: args, kwargs: kwargs); | ||
} |