sendMessage method
roomId
: numeric ID of the room to join.
text
: content of the message to send, as a string.
ack
: true|false, whether the sender wants an ack for the sent message(s); optional, true by default
.
to
: username to send the message to; optional, only needed in case of private messages.
tos
: array of usernames to send the message to; optional, only needed in case of private messages.
Implementation
Future<void> sendMessage(dynamic roomId, String text,
{bool? ack, String? to, List<String>? tos}) async {
if (setupDone) {
var message = {
'transaction': randomString(),
"textroom": "message",
"room": roomId,
"text": text,
"to": to,
"tos": tos,
"ack": ack
}..removeWhere((key, value) => value == null);
_handleRoomIdTypeDifference(message);
_context._logger
.fine('sending text message to room:$roomId with payload:$message');
await this.sendData(stringify(message));
} else {
_context._logger.shout(
'method was called before calling setup(), hence aborting further operation.');
throw "method was called before calling setup(), hence aborting further operation.";
}
}