Skip to content

Instantly share code, notes, and snippets.

@shriyaRam
Last active June 14, 2020 13:29
Show Gist options
  • Save shriyaRam/49cf2823bbc3d924f700b7c1ea8a12b0 to your computer and use it in GitHub Desktop.
Save shriyaRam/49cf2823bbc3d924f700b7c1ea8a12b0 to your computer and use it in GitHub Desktop.
//send messages
sendbtn.addEventListener("click", ()=>{
channel.sendMessage({ text: msg.value }).then(() => {
/* Your code for handling events, such as a channel message-send success. */
chatbox.innerHTML += "<div class='message_holder'><span class='chat user1'>"+ msg.value + "</span></div>";
console.log("Successfully sent message!");
}).catch(error => {
/* Your code for handling events, such as a channel message-send failure. */
console.log("Error sending message!");
});
})
if(flag == true){
//receive channel messages
channel.on('ChannelMessage', ({ text }, senderId) => { // text: text of the received channel message; senderId: user ID of the sender.
/* Your code for handling events, such as receiving a channel message. */
chatbox.innerHTML +="<div class='message_holder'><span class='chat user2'>"+ text + "</span></div>";
msg.value="";
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment