-
Notifications
You must be signed in to change notification settings - Fork 186
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
There is no way to run EM::WebSocket listener EM-way #79
Comments
This does what you're looking for: https://github.com/postrank-labs/goliath/blob/master/lib/goliath/websocket.rb |
Still -- EventMachine is quite widely used, so having well-written WebSockets implementation might help some projects. What do you think about porting solution introduced in Goliath to this gem? |
I'm still not sure what you're after.. If you have a specific proposal, outline it and we can discuss it. "Well written" is ambiguous :-) |
I'm only referring to defining you own WS handlers as modules, maybe suggesting that it is not "well written" could sound a bit nasty ;) I don't have currently whole idea of internal implementation. I have in mind interface that I would like to use in my application, that would be analogous to other handlers that I have written. Solution provided by Goliath seems to be one way to do it. |
Providing a subclassed Here's what the example echo client would look like (I may commit this to the examples folder for reference):
|
This is solution I was using up to now, but I considered it a bit "hacky" -- as long as it is not documented it can't be safely used as further gem development could possibly break it. Using EM::WebSocket as a mixin, and keeping consistent names of methods (without trigger_ prefix) seems a bit cleaner for me. |
I jusr ran into this situation, I think it would be nice to have em-websocket abstracted to so one can use it like a class and start it with EM.start_server('0.0.0.0', 8080, myWsHandlerClass). The main advantage is modularization as we don't have to write all the code inside the ...end |
What I would like to achieve is writing my own module/class containing
onopen
,onmessage
and other events' handlers, includeEM::WebSocket
in it and just runEM.start_server
providing this module as parameter. This way it is possible to keep code quite readable and clean, while having multiple listeners plugged in single EM instance.Right now I was unable to find any clean way of using
EM::WebSocket
gem without cluttering myEventMachine::run
block with code specific to supporting this one listener.I'm willing to refactor parts of em-websocket code, while keeping support for current
EM::WebSocket.start
method, but I'd like to hear feedback about the idea first.The text was updated successfully, but these errors were encountered: