8

I have created an Asynchronous version of Rails 3 that I would like to integrate with a WebSocket implementation.

I am using EventMachine, Ruby 1.9, Fibers and various em-flavoured libraries as documented by the wickedly good Ilya Grigorik.

I have been looking at em-websocket as the handler for WebSocket connections but unsure of the best approach for hooking this into a Rails app.

Ideally, this would work in a similar fashion to node.js with Express and Socket.io - incoming connections should be detected and dispatched to the WebSocket handler or the regular rails stack as indicated by the HTTP headers & etc.

TL;DR

  • WebSocket handler that plugs into an existing Rails application
  • Transparently dispatch incoming WebSocket requests to endpoints in the app
Toby Hede
  • 36,755
  • 28
  • 133
  • 162
  • 1
    you might consider breaking down your question into a series of more specific bullet points you want answered. – kanaka Nov 22 '10 at 15:58

3 Answers3

5

I know this question is old but hopefully this answer may help those that have been directed here from google.

I am working on a gem that satisfies the two main criteria in the original question. The gem is called websocket-rails and has been developed from the ground up to make using WebSockets inside of a Rails application drop dead simple. It is finally at a stable release, but there is a whole lot more functionality that I believe it needs.

Currently, event handling is very basic. There is an events.rb file where you map client side events to controller actions similar to the routes.rb file. All requests to /websocket are passed through to the embedded WebSocket server without the need for a separate server process.

The more ambitious goal of the project is to eventually move Rails to a more traditional MVC pattern where events on the client browser bubble up to the server for processing and updating a model will automatically trigger events on the client to update the rendered representation of that model.

Any feedback would be appreciated.

Dan Knox
  • 634
  • 5
  • 9
2

Check out Skinny.

You'll need to use Thin, but you can upgrade an HTTP request mid-stride. I use it in Sinatra apps, but it should be just as easily used in Rails.

sj26
  • 6,725
  • 2
  • 27
  • 24
1

Maybe try socky? As for now it's best and it's pretty easy to integrate it with Rails(both 2 and 3)

Bernard Potocki
  • 1,248
  • 8
  • 9
  • Socky is pretty cool, but not quite integrated into the Rails stack the way Express and Socket.io are. Might be able to use it as the basis of something more tightly wound into Rails. – Toby Hede Nov 27 '10 at 11:50