From 94c7d9e8cc31159f8ee78335105b3b543404da51 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 24 Jul 2018 19:29:07 -0300 Subject: [PATCH] [FIX] Close websocket (#379) * Fixed a bug when closing websocket * removeListener fixed --- app/lib/ddp.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/lib/ddp.js b/app/lib/ddp.js index bf6ebc93e..74e9fff27 100644 --- a/app/lib/ddp.js +++ b/app/lib/ddp.js @@ -37,6 +37,9 @@ class EventEmitter { if (idx > -1) { this.events[event].splice(idx, 1); } + if (this.events[event].length === 0) { + delete this.events[event]; + } } } emit(event, ...args) { @@ -51,11 +54,10 @@ class EventEmitter { } } once(event, listener) { - this.on(event, function g(...args) { + return this.on(event, function g(...args) { this.removeListener(event, g); listener.apply(this, args); }); - return listener; } } @@ -175,7 +177,7 @@ export default class Socket extends EventEmitter { this.ddp.once(id, (data) => { // console.log(data); this.lastping = new Date(); - this.ddp.removeListener(id, cancel); + this.ddp.removeListener('disconnected', cancel); return (data.error ? reject(data.error) : resolve({ id, ...data })); }); }); @@ -187,7 +189,7 @@ export default class Socket extends EventEmitter { try { // this.connection && this.connection.readyState > 1 && this.connection.close && this.connection.close(300, 'disconnect'); if (this.connection && this.connection.close) { - this.connection.close(300, 'disconnect'); + this.connection.close(); delete this.connection; } } catch (e) {