geckosio / geckos.io

🦎 Real-time client/server communication over UDP using WebRTC and Node.js http://geckos.io
BSD 3-Clause "New" or "Revised" License
1.34k stars 84 forks source link

.on() doesnt register multiple listeners #203

Open yesitsfebreeze opened 2 years ago

yesitsfebreeze commented 2 years ago

Discussed in https://github.com/geckosio/geckos.io/discussions/202

Originally posted by **yesitsfebreeze** May 13, 2022 Would it be possible to implement the on listener in a different way to this? Currently the problem is that you cant register multiple listeners via `.on`, due to the fact that the callback is passed into the lambda. https://github.com/geckosio/geckos.io/blob/master/packages/server/src/geckos/channel.ts#L272 this would be sufficient i guess: ``` listener = (callback, ....) => { ... }.bind(callback) this.eventEmitter.on(eventName, listener) ```
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 10 days.

bananu7 commented 1 year ago

Actually, does that mean that only one listener can be active at a time? I was struggling a bit because there's no removeListener/removeAllListeners exposed...

bananu7 commented 1 year ago

I've just tested and it seems that the subsequent calls to .on() are ignored. For reference, I worked around it by binding via a proxy:

this.channel.on('spectating', (data: Data) => {
    if (this._onSpectating)
        this._onSpectating(data);
});

That's a bit more annoying than just being able to override the handler.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 500 days with no activity. Remove stale label or comment or this will be closed in 10 days.