Skip to content

Instantly share code, notes, and snippets.

@digitallysavvy
Last active June 26, 2021 15:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitallysavvy/d6db7afe727ade7f4a32dd0b8fa14bae to your computer and use it in GitHub Desktop.
Save digitallysavvy/d6db7afe727ade7f4a32dd0b8fa14bae to your computer and use it in GitHub Desktop.
A snippet for using an creating an Agora RTM message using JSON
function sendChannelMessage(property, direction){
if (localStreams.rtmActive) {
// use a JSON object to send our instructions in a structured way
const jsonMsg = {
property: property,
direction: direction
};
// build the Agora RTM Message
const msg = {
description: undefined,
messageType: 'TEXT',
rawMessage: undefined,
text: JSON.stringify(jsonMsg)
};
rtmChannel.sendMessage(msg).then(() => {
// channel message-send success
console.log('sent msg success');
}).catch(error => {
// channel message-send failure
console.log('sent msg failure');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment