fix: guard against socket going away

This commit is contained in:
cha0s 2019-05-09 17:44:38 -05:00
parent 457940a90e
commit dcf871f3a0

View File

@ -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) => {