Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var channel = pusher.subscribe('your-chat-room');
- channel.bind('new-message', function (data) {
- // append message to chat UI. Here an item in unordered list.
- var messageThread = document.getElementById("chat");
- var newMessage = document.createElement("li");
- newMessage.appendChild(document.createTextNode("data.message"));
- newMessage.setAttribute("id",data.messageId)
- messageThread.appendChild(newMessage)
- });
- channel.bind('new-reaction', function (data) {
- // If you save the likeCount in your backend,
- // you will trigger an event everytime a new like is sent by a user.
- // Bind to an event on the same chatroom.
- // In this example, we are storing that value on an attribute of the <li> object.
- var message = document.querySelector("#"+data.messageId);
- var likeCount = parseInt(message.getAttribute("likeCount"));
- newMessage.setAttribute("likeCount",likeCount+1);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement