sendDirectMessage method
Future<void>
sendDirectMessage({
- required String message,
- required HMSPeer peerTo,
- String type = "chat",
- HMSActionResultListener? hmsActionResultListener,
Sends a message to a particular peer only.
Parameters:
peerTo - The one specified HMSPeer.
message - contains the content of the message.
type - The type of the message, default is chat.
hmsActionResultListener - It contain informs about whether the message was successfully sent, or the kind of error if not.
Implementation
Future<void> sendDirectMessage(
{required String message,
required HMSPeer peerTo,
String type = "chat",
HMSActionResultListener? hmsActionResultListener}) async {
var arguments = {
"message": message,
"peer_id": peerTo.peerId,
"type": type
};
var result = await PlatformService.invokeMethod(
PlatformMethod.sendDirectMessage,
arguments: arguments);
if (hmsActionResultListener != null) {
if (result != null && result["error"] != null) {
hmsActionResultListener.onException(
methodType: HMSActionResultListenerMethod.sendDirectMessage,
arguments: {"message": message, "peer": peerTo, "type": type},
hmsException: HMSException.fromMap(result["error"]));
} else {
hmsActionResultListener.onSuccess(
methodType: HMSActionResultListenerMethod.sendDirectMessage,
arguments: _hmsMessageToMap(result));
}
}
}