Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for streaming / SSE #15

Open
paneq opened this issue Jul 14, 2012 · 5 comments
Open

Support for streaming / SSE #15

paneq opened this issue Jul 14, 2012 · 5 comments
Labels

Comments

@paneq
Copy link
Collaborator

paneq commented Jul 14, 2012

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 store sender_id and connection_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.

env = {
  "rack.version" => Rack::VERSION,
  "rack.url_scheme" => "http",
  "rack.input" => StringIO.new(req.body),
  "rack.errors" => $stderr,
  "rack.multithread" => true,
  "rack.multiprocess" => true,
  "rack.run_once" => false,

  "mongrel2.pattern" => req.headers["PATTERN"],
  "mongrel2.handler" => self  # !!!

  "REQUEST_METHOD" => req.headers["METHOD"],
  "SCRIPT_NAME" => script_name,
  "PATH_INFO" => req.headers["PATH"].gsub(script_name, ''),
  "QUERY_STRING" => req.headers["QUERY"]
}

That would allow to reach it from Rails action in controller using:

request.env["mongrel2.handler"].deliver(...)

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.

@paneq
Copy link
Collaborator Author

paneq commented Jul 15, 2012

Probably sender_id and connection_uuid should also be put into env hash.

@paneq
Copy link
Collaborator Author

paneq commented Oct 28, 2012

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.

@paneq
Copy link
Collaborator Author

paneq commented Oct 28, 2012

Related to #42

@paneq
Copy link
Collaborator Author

paneq commented Nov 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant