From dcf871f3a02dd022897e7b6bf3cfc2ff2b9b3760 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 9 May 2019 17:44:38 -0500 Subject: [PATCH] fix: guard against socket going away --- server/traits/informed.trait.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/traits/informed.trait.js b/server/traits/informed.trait.js index 3537198..c6979b1 100644 --- a/server/traits/informed.trait.js +++ b/server/traits/informed.trait.js @@ -259,9 +259,6 @@ export class Informed extends decorate(Trait) { return { inform: (state) => { - if (!this._socket) { - return; - } // Reduce state. const reducedState = this.reduceState(state); // Take a pure JS diff. @@ -278,10 +275,14 @@ export class Informed extends decorate(Trait) { // Emit! const keys = this._packer.computeNewKeys(steps); if (0 !== keys[0].length) { - this._socket.send(new StateKeysPacket(keys)); + if (this._socket) { + this._socket.send(new StateKeysPacket(keys)); + } } const packed = this._packer.pack(steps); - this._socket.send(new StatePacket(packed)); + if (this._socket) { + this._socket.send(new StatePacket(packed)); + } }, seesEntity: (entity) => {