Hi,
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.