Monday, April 24, 2017

How to private chat using node.js and

Create a room with conversation_id and make users to subscribe to that room, 
so that you can emit a private message to that room it by,

var socket = io.connect('http://ip:port'); socket.emit('subscribe', conversation_id); socket.emit('send message', { room: conversation_id, message: "Some message" }); socket.on('conversation private post', function(data) { //display data.message });
Server -------
socket.on('subscribe', function(room) { console.log('joining room', room); socket.join(room); }); socket.on('send message', function(data) { console.log('sending room post',;'conversation private post', { message: data.message }); });
Here is my Stackoverflow answer :

No comments: