-
Notifications
You must be signed in to change notification settings - Fork 5
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
Pipe()'s NodeJS EventEmitter Compatibility #101
Comments
The library stick to the Websocket standard, more than ws. But what you describe is in the Todo list and I will put it on top (next 10 days) knowing that someone else need it. Thanks for your comments. |
@SirNeural nice ticket, this helped me figure out what was wrong in my setup. const EventEmitterCompliantChannel = new Pipe(ws, 'A');
// heres the interface patching:
EventEmitterCompliantChannel.on = (event, cb) =>
EventEmitterCompliantChannel.addEventListener(event, (msg) => cb(msg.data)); |
@kmannislands Hey thanks for posting your solution, I did manage to do the same kind of interface patching in order to get this to work in the last few days, nice to see this helped someone out! |
I guess you need that for websocket-json-stream, it's also quite easy to replace this library and match the standard websocket client implementation. |
WIP #105 |
merging issue to #20 |
Hi,
First off, this is a great library @dcharbonnier, just what I felt was missing in the original ws library.
I've been trying to implement this in place of ws, but am experiencing difficulties in doing so because there is a slight difference between this and the original node ws library.
In the original node library event listeners can be attached like this:
`
const ws = new WebSocket('wss://server')
ws.on('open', OPEN_CALLBACK)
ws.on('message', MESSAGE_CALLBACK)
....
`
In this library, event listeners must be attached like this, similar to in web browser javascript:
`
const ws = new WebSocket('wss://server')
ws.addEventListener('open', OPEN_CALLBACK)
ws.addEventListener('message', MESSAGE_CALLBACK)
....
`
That alone isn't the cause of my problems, because the callback in the first example for the message event returns the message to the callback, as a string, but the second one returns an event object to the callback, with the message as a property attached to it; This breaks my existing code and would be a big hassle to change.
Since this is a big incompatibility with the node ws library, I think it would be nice if there could be support for .on() and the other node EventEmitter methods, that sends just the property instead of the entire event object (I think just extending from EventEmitter should work, not completely sure)
Thanks again for this great library!
The text was updated successfully, but these errors were encountered: