Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.

Removing Event Listeners #280

Open
macharborguy opened this issue Jul 24, 2018 · 1 comment
Open

Removing Event Listeners #280

macharborguy opened this issue Jul 24, 2018 · 1 comment

Comments

@macharborguy
Copy link

I am implementing Discord.io into our Twitch channel bot to work both in Twitch IRC and our Discord server. Part of my workflow involves an initial connection to the server via an Async.js "series" control flow.

With the Twitch library I use, I have the connection event on a .once() listener, and after a successful connection I have an .on() handler for the connection event to deal with reconnections.

With Discord.io, I want to have two .once() handlers, one for the successful initial connection, and one for a potential connection error. However, I would also like to remove these listeners after a successful connection or failed connection (on success, remove disconnect listener, on failure, remove connection listener). After removal and successful connection, i would create a new disconnect handler to deal with reconnections and other web socket errors.

However, it appears that while .on() and .once() ARE supported, .off() and .removeEventListener() are not supported. They both throw an error that "client.off / client.removeEventListener are not functions".

Is there a way with the client object to remove listeners as needed?

@macharborguy macharborguy changed the title Removing Events Removing Event Listeners Jul 24, 2018
@macharborguy
Copy link
Author

After doing what I should have done and looked at the source code, i found 'removeListener'. I forgot that Node's 'Events' module uses removeListener and not removeEventListener. Although, could the 'off' method be added as an alias to removeListener?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant