I have implemented chat feature using sockjs-tornado and could store the messages in RethinkDB.
Could you please help me on how do I establish private channel for me
My answer makes the assumption that all clients in the current solution connect to a SockJS server with a channel name that is used for broadcasts of the chat messages (or something close to this scenario). I further assume that the round-trip when a user sends a message from the client is:
[Sender (Client)] ------- Message (POST) --> [App Server] --- Message --> [Database]
|
Message
v
[Receiver(s) (Client)] <-- Message (WS) -- [SockJS Server]
There are multiple solutions to this problem. I will only outline the one I think is simplest and most robust here:
Another, slightly more complex, and inelegant solution would be to create ad hoc channels for each private pair when needed. However, how would you get User B
to subscribe to the (newly created) private channel when User A
wants to chat with User B
? One way would be to broadcast a request for User B
to connect to that channel, but that would tell all the other clients (at the code level) about this private chat that will take place; and if any of those clients are compromised, that information can be misused for, for example, eavesdropping or crashing the private party.
I would also like to mention that since I wrote my sockjs - example of implementing rooms answer, I have changed my own architecture to (still) use SockJS
in the front-end, but with RabbitMQ using the Web-STOMP plugin on the back-end. That way,
The whole new solution is placed behind HAProxy which terminates HTTPS and SSL/TLS-encrypted WebSocket connections.
Although sockjs-tornado does not implement such a thing like channels, nor rooms, there is example multiplex how one could implement that. Also look at sockjs - example of implementing rooms. Solution is based on structured msg
- within message you additional info is sent - channel name.