From cabfa939e7eb9203c468b8499a84b98f3c0a7bbb Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 16 Nov 2018 15:18:16 -0500 Subject: [PATCH] fix(ipc): sends requests and events only when connected Fixes #1063 --- src/lib/core/ipc.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/core/ipc.js b/src/lib/core/ipc.js index 520836d14..8b073935a 100644 --- a/src/lib/core/ipc.js +++ b/src/lib/core/ipc.js @@ -65,7 +65,10 @@ class IPC { ipc.server.emit(client, 'message', message); } - listenTo(action, callback) { + listenTo(action, callback = () => {}) { + if (!this.connected) { + return callback(); + } ipc.of['embark'].on(action, (messageString) => { callback(parse(messageString)); }); @@ -75,7 +78,10 @@ class IPC { ipc.server.broadcast(action, stringify(data)); } - once(action, cb) { + once(action, cb = () => {}) { + if (!this.connected) { + return cb(); + } ipc.of['embark'].once('message', function(messageString) { const message = parse(messageString); if (message.action !== action) { @@ -86,6 +92,10 @@ class IPC { } request(action, data, cb) { + if (!this.connected) { + cb = cb || (() => {}); + return cb(); + } if (cb) { this.once(action, cb); }