ngauthier / tubesock

Websocket interface on Rack Hijack w/ Rails support
MIT License
620 stars 43 forks source link

Send data to all connected clients? #30

Closed Deekor closed 10 years ago

Deekor commented 10 years ago

Looks like a great gem! Before diving into it though could someone answer if you can send data to all connected clients?

In theory i'd like to make a message board / chat room hybrid type app that whenever a new message gets stored to the database it live updates the message onto the page.

ngauthier commented 10 years ago

Hi Dee,

Tubesock is just responsible for the communication between the server and the client. It's up to you to build the application the way you want it.

So, yes, tubesock can be part of an application that broadcasts to whichever groups of clients you'd like.

For and example of a one-room chat client, check out sock chat:

https://github.com/ngauthier/sock-chat

It uses redis's pub/sub to make a chat channel. You can see in the controller it just has one channel called "chat":

https://github.com/ngauthier/sock-chat/blob/master/app/controllers/chat_controller.rb

But, theoretically, you could replace "chat" with "chat-#{id}" where id is the database id of a chat room model. That way you would have multiple channels.

All tubesock does it allow you to communicate over websockets via threads. It's up to you what you want to say and to whom.

Nick