feature request (with demo code): native websockets as controller callbacks.


I was thinking about this a lot and even found myself writing a whole server / framework with native websocket support to see what was possible.

Websockets is far too complicated to to easily utilize in it’s present state, since using websockets in Rails applications requires Rack and Middleware knowhow which is not expected from the average Rails developer and isn’t common.

I propose adding support for native websockets within the Controller class - by defining callback support for the following methods / events: pre_connect (before protocol upgrade, for updating cookies and HTTP data), on_connect (after protocol upgrade), on_message(data), on_disconnect.

this also might require adding support for controller class instance communication, assuming each connection has it’s own controller instance - this could allow us to broadcast messages and collect information from other connections directly (without pulling on databases or setting up flags)… I’ve managed an interesting solution within the broadcast and collect methods in my experimental framework.

If anyone thinks this is a good approach, please feel free to contact me about adapting my code (or writing new code) for the Rails 5.0 release.


You really need to rename your project. It’s 2014 almost 2015, we have to be wiser than this.



Ha… that’s probably true (lol)…

…It started as a pet project for myself - I was making a private joke at the expense of the ‘Thin’ server (which I love)…


I added code that automates the #broadcast to use a Redis server (if defined).

I think having these features in Rails, where a controller can respond to websocket events, is critical for moving forward.

Using middleware and dedicated event machines to handle parts of the application means that the developers are moving away from the framework and the code is less well organized and harder to maintain.

Having the framework respond to both RESTful requests and WebSocket requests, like in this experimental framework, feels essential in this worlds where http and webs apps act also as the backend for mobile apps and other advanced clients.

Feel free to ask any questions, I would love if these websocket features were assimilated in Rails.