publish method
Future<Published?>
publish(
- String topic, {
- List? arguments,
- Map<
String, dynamic> ? argumentsKeywords, - PublishOptions? options,
This publishes an event to a topic
with the given arguments
and argumentsKeywords
.
Implementation
Future<Published?> publish(String topic,
{List<dynamic>? arguments,
Map<String, dynamic>? argumentsKeywords,
PublishOptions? options}) {
var pubArguments = arguments;
var pubArgumentsKeywords = argumentsKeywords;
if (options?.pptScheme == 'wamp') {
// It's E2EE payload
pubArguments =
E2EEPayload.packE2EEPayload(arguments, argumentsKeywords, options!);
pubArgumentsKeywords = null;
} else if (options?.pptScheme != null) {
// It's some variation of PPT
pubArguments =
PPTPayload.packPPTPayload(arguments, argumentsKeywords, options!);
pubArgumentsKeywords = null;
}
var publish = Publish(nextPublishId++, topic,
arguments: pubArguments,
argumentsKeywords: pubArgumentsKeywords,
options: options);
_transport.send(publish);
if (options?.acknowledge == null || options?.acknowledge == false) {
return Future.value(null);
}
var publishStream = _openSessionStreamController.stream.where((message) {
if (message is Published &&
message.publishRequestId == publish.requestId) {
return true;
}
if (message is Error &&
message.requestTypeId == MessageTypes.codePublish &&
message.requestId == publish.requestId) {
throw message;
}
return false;
}).cast<Published>();
return publishStream.first;
}