Last active
June 26, 2021 15:52
-
-
Save digitallysavvy/d6db7afe727ade7f4a32dd0b8fa14bae to your computer and use it in GitHub Desktop.
A snippet for using an creating an Agora RTM message using JSON
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
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