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

3 Answers
3

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.

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 HedeNov 27 '10 at 11:50