Integrating WebSockets with Rails using Rack and Event Machine
- by Toby Hede
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