Reputation: 2135
I'm using socket.io to chat from user (App) to admin (to browser). here admin msg has been received properly to the user but user message not received by the admin. I'm following https://www.sitepoint.com/using-socket-io-and-cordova-to-create-a-real-time-chat-app/ for the chat application. Also there is App to App chat, which is working fine for me.
here is my server side code
socket.on('send:message', function (msg) {
console.log("send:message", msg);
if (msg.orderChat) var q = models.orderChat.create(msg)
else var q = models.chat.create(msg)
q.then(function (ret) {
console.log(ret.get({ plain: true }));
socket.in(msg.chat_room).emit('send:message', msg);
//socket.emit('send:message', msg);
}).catch(function (err) {
console.log(err);
socket.in(msg.chat_room).emit('send:message', 'Server Error');
});
});
here is my Client side code
socket.on('send:message', function (msg) {
username = $('.pchat').attr('data-username');
console.log(msg);
$("#chat_div_" + username).chatbox("option", "boxManager").addMsg(username, msg.message);
})
update Also code work fine when to user chat in same browse but not in cross browse
Upvotes: 1
Views: 101
Reputation: 4051
I believe there are chance there are bugs outside of the code provided here,
In your Server side I have changed:
socket.in(msg.chat_room).emit('send:message', msg);
to
socket.in(msg.chat_room).emit('send:message', {
message: msg
});
Though if you could provide your full code I'll be able to help you troubleshoot further.
Upvotes: 1