node.js - socket.io private chat with nodejs -
how can manage chat user user
user ,b , user c login user send message user c user c see message when send message receiver side socket not receive message
use multiple method msg not receive how manage socket.io node js how manage system please me
io.sockets.on('connection', function (socket) { socket.on('connection', function (data, callback) { if (data in users) { callback(false); } else { callback(true); socket.nickname = data; users[socket.nickname] = socket; updatanicknames(); var list= object.keys(users); io.sockets.on('connection', function (socket) { socket.on('send-message', function (messages) { var msg_number = fs.readfilesync('creditional/database.txt', 'utf8'); var msg_id = msg_number.tostring(); var next_msg_id = (msg_id - 0) + (1 - 0); fs.writefile('creditional/database.txt', next_msg_id, function (err) { if (err) return console.log(err); }); var text = messages.message; var image_url = messages.image_url; var email = messages.email; var sid = messages.sid; var rid = messages.rid; var type = messages.msg; var name = messages.name; var sname = messages.sname; var time = messages.msgts; var mess_set = { "messageid": msg_id, "ishtml": false, "servermsgts": time, "msgts": time, "rid": rid, "sname": sname, "text": text, "sid": sid, "type": "0", "rname": "rname", "imgname": image_url, } var message_data = json.stringify(mess_set); var stanza = new xmpp.element('message', {to: rid + '@testing.twodegrees.io', type: 'chat', id: rid}). c('body').t(message_data) var msg_stat = connection.send(stanza); console.log('message status..:', msg_stat); }) }); io.once('connection', function (socket) { connection.on('stanza', function (stanza) { var body = stanza.getchild('body'); var message = body.gettext(); var data = json.parse(message); var name2 = data.rid; var name =name2.trim(); console.log('reciver chat id',name); if (name in users) { console.log(users[name]); users[name].emit('newmessage',{messages: data}); } else { console.log('in else', name); } }); }); }); });
Comments
Post a Comment