em-websocket
em-websocket copied to clipboard
Offer a direct migration from faye-websockets
This is part feature request, part documentation request.
I am using https://github.com/faye/faye-websocket-ruby in my current project, mainly cause it offers a simple integration point with Rack and Thin.
To get it going it monkey patches Thin so essentially the EM connection is exposed.
I would much prefer to use em-websockets, since
- protocol support is way more comprehensive
- it is far more active
however
- It is unclear if a bind to an existing EM connection semantics is supported, though it seems I could simply initiate a handler. with the connection as an init param
- I would have to roll my own monkey patch (I am fine with that) - though I think thin and rainbows should attach the EM connection to env to avoid this nonsense
- faye includes native masking https://github.com/faye/faye-websocket-ruby/tree/master/ext/faye_websocket_mask I am unclear about the perf implications
Thoughts?
Sam, what you've described is pretty much exactly what we did in Goliath to provide websocket support: https://github.com/postrank-labs/goliath/blob/master/lib/goliath/websocket.rb
As long as you have access to the underlying EM connection object, you should be able to pretty much translate that code to work with thin as well. You just have to map the right Thin callbacks..
I started writing an adapter, a big issue is that https://github.com/igrigorik/em-websocket/blob/master/lib/em-websocket/connection.rb is not reusable so I need to copy and paste wholesale, perhaps it should be moved to a module?
Another painful issue seems to be the heavy reliance on httpparser.rb I need to do a bit of magic code converting rack request to httpparser ones
Not sure how you're structuring your code, but notice that the Goliath code did not have to copy the connection class - we simply implemented the necessary shims and mapped to http_parser.rb.. which is what Goliath uses (no dependencies to em-websocket).
yeah, I follow, my thin implementation takes a slightly different approach.
I got it going though the secure stuff is not working yet, https://github.com/SamSaffron/thin-em-websocket/blob/master/examples/config.ru
will publish the gem once it is a bit more battle tested