Open paneq opened 12 years ago
Probably sender_id
and connection_uuid
should also be put into env hash.
Try to keep the API compatible with what Aaron describes here: http://www.youtube.com/watch?v=kufXhNkm5WU . Maybe just change the included module to M2R::Live
? Maybe that should be a different gem, but m2r
responsibility is to keep it possible to be implemented.
Related to #42
Idea: Allow to easily deliver notifications to clients from Rails/Rack apps using SSE.
Algorithm:
Subscription
From Rails/Rack application respond with
Transfer-Encoding: chunked
header for the request. Verify user and storesender_id
andconnection_uuid
of his request somewhere (current thread, db, redis, whatever). This leaves open connection in the browser that can be used later for delivering SSE.Sending notification
When there is an event that you would like to inform user about (ex. friend added a picture) send chunked part to the same
sender_id
,connection_uuid
that we stored in db. Mongrel2 allows it and will forward to the browser.If chunked response uses SSE format then it can be used by JS SSE API in HTML5 browsers.
Main areas of concern regarding integration with Rails
access from Rails app to handler
How can one use
#deliver
method from our handler in the Rails/Rack application. In other words, how can such higher level reach something from low-level ?We could expose the handler itself in rack env.
That would allow to reach it from Rails action in controller using:
subscribing to disconnected event
I don't have yet an idea as how to subscribe from Rails app to
on_disconnected
event in the handler. I would like to avoid foricing users to inhreit from the RackHandler to plug in their application behavior.