-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Description
Hi,
When the pusher singleton is reset or re-initialised with an onConnectionStateChange() listener, these listeners are not being removed.
Pusher::init() calls removeAllListeners() prior to adding the new options being passed in, but this doesn't include a call to remove the PusherEventName.ON_CONNECTION_STATE_CHANGE
private removeAllListeners() {
// Missing?: this.pusherEventEmitter.removeAllListeners(PusherEventName.ON_CONNECTION_STATE_CHANGE);
this.pusherEventEmitter.removeAllListeners(PusherEventName.ON_AUTHORIZER);
this.pusherEventEmitter.removeAllListeners(PusherEventName.ON_ERROR);
this.pusherEventEmitter.removeAllListeners(PusherEventName.ON_EVENT);
this.pusherEventEmitter.removeAllListeners(PusherEventName.ON_MEMBER_ADDED);
this.pusherEventEmitter.removeAllListeners(
PusherEventName.ON_MEMBER_REMOVED
);
}This results in multiple OnConnectionStateChange handlers being triggered after the re-init...
const initOptions = {
apiKey: pusherKey,
cluster: 'eu',
onConnectionStateChange: (currentState: string, previousState: string) => {
console.log(`Pusher connection: ${previousState} => ${currentState}`);
},
onSubscriptionSucceeded: (channelName: string) => {
console.log(`Subscribed: ${channelName}`);
},
onSubscriptionError: (channelName: string) => {
console.log(`Error: ${channelName}`);
},
onEvent: (event: PusherEvent) => {
console.log('Global Event...');
console.log({event});
},
onError(message: string, code: Number, e: any) {
console.log(`Error ${code}: ${message}`);
console.log({e});
},
};
await pusher.init(initOptions);
await pusher.connect();Resulting in the following output after a number of resets...
LOG Pusher connection: DISCONNECTED => CONNECTING
LOG Pusher connection: DISCONNECTED => CONNECTING
LOG Pusher connection: DISCONNECTED => CONNECTING
LOG Pusher connection: CONNECTING => CONNECTED
LOG Pusher connection: CONNECTING => CONNECTED
LOG Pusher connection: CONNECTING => CONNECTED
aoenstar, lolJS and allan-scopely
Metadata
Metadata
Assignees
Labels
No labels