Implementing chat in Rails

2019-09-14 22:52发布

问题:

I am trying to implement a chat module in my rails application. I looked into this railscast Faye tutorial. More through the tutorial, Ryan mentions about broadcasting the messages but what I want is more like private conversations between the clients instead of broadcasting.

Is it possible to do that through faye? or is there a better way of implementing chat in rails?

回答1:

There is a gem that handles the autentications for you for faye, so users can only listen on channels you subscribe them to. There is also a railscast talking about that gem. https://github.com/ryanb/private_pub



回答2:

I don't know much about Faye, but assuming the principles are the same as with something like pure node.js and websockets, you'd divide the channels that can be subscribed to down into as many chats as there are occurring, then you'd require some sort of authentication before a client can subscribe to that channel, of which there are numerous approaches, as with most authentication systems (e.g. shared secret, username/password, challenge/response etc).



回答3:

I have used Ryan's tutorial on private_pub to achieve an a Gmail like instant messaging feature. It's actually not very complex. See how I achieved it in this tutorial http://goo.gl/l3e8zN