Is there a way in sails.js or a tutorial that would help me build a peer to peer chat, using sockets, something like pubnub.
I am trying to implement a personalized chat feature using sails.js What that would mean is that I have say multiple users in my application and a user can chat with another user. So if user A sends a message in user B chatbox, B(only) receives and vice-versa.
I have gone through http://sailsjs.org/#!documentation/sockets , the documentation by it gives examples using the models. So I guess it is not for one-to-one chat, but for something like user list and user profile changes kind of stuff.
So I know that I need to use native socket.io code for that. What I need is that the client can open a socket for a particular channel, and then whenever user A types in to user B, that message is stored in the db, as well as written on the socket. I don't know how to get this functionality in Sails.
I can write the code in index event of the MessagesController. So I would need to compute the channel name based on the user A and user B details and write it on the socket for that channel. But I don't know how to write it to the socket for that particular channel. I hope I am clear with what I want. I found this piece of code as an example:
//Code For Server
var io = require("socket.io");
io.sockets.on("connection", function (sock) {
sock.emit("welcomeMessage", { hello: "world" });
}
io.listen(80);
//Code For Client
var sock = io.connect('http://localhost');
sock.on('welcomeMessage', function (json) {
//Handle Event Received
});
But it doesn't tell me, how do I write to this particular socket for channel "welcomeMessage" from any controller I want. Something like what PubNub supports (http://www.pubnub.com/) .