Skip to content

Commit 48c6092

Browse files
committed
Cleanup more listeners
1 parent ce80c73 commit 48c6092

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "detritus-client-socket",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "A TypeScript NodeJS library to interact with Discord's Gateway",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/basesocket.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ export class BaseSocket extends EventEmitter {
8888
): void {
8989
if (this.connected) {
9090
this.socket.close(code, reason);
91-
for (const [nonce, {reject}] of this.pings) {
92-
reject(new Error('Socket has closed.'));
93-
this.pings.delete(nonce);
94-
}
95-
this.pings.clear();
96-
this.removeAllListeners();
9791
}
92+
for (const [nonce, {reject}] of this.pings) {
93+
reject(new Error('Socket has closed.'));
94+
this.pings.delete(nonce);
95+
}
96+
this.pings.clear();
97+
this.socket.removeAllListeners();
98+
this.removeAllListeners();
9899
}
99100

100101
onPong(data: any): void {

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const Package = Object.freeze({
22
URL: 'https://github.com/detritusjs/client-socket',
3-
VERSION: '0.3.2',
3+
VERSION: '0.3.3',
44
});
55

66
function normalize(object: {[key: string]: any}) {

src/gateway.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ export class Socket extends EventEmitter {
545545
socket.kill(error);
546546
}
547547
this.emit(SocketEvents.KILLED, {error});
548+
this.removeAllListeners();
548549
}
549550
}
550551

src/media.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ export class Socket extends EventEmitter {
310310
reason = <string> SocketInternalCloseReasons[code];
311311
}
312312
this.socket.close(code, reason);
313+
this.socket = null;
313314
}
314-
this.socket = null;
315315
}
316316

317317
encode(data: any): null | string {
@@ -434,10 +434,12 @@ export class Socket extends EventEmitter {
434434
this.disconnect(SocketCloseCodes.NORMAL);
435435
if (this.transport) {
436436
this.transport.disconnect();
437+
this.transport.removeAllListeners();
437438
this.transport = null;
438439
}
439440
this.resolvePromises(error || new Error('Media Gateway was killed.'));
440441
this.emit(SocketEvents.KILLED);
442+
this.removeAllListeners();
441443
}
442444

443445
onClose(

0 commit comments

Comments
 (0)