diff options
refactor - push data to popup
Diffstat (limited to 'app/scripts/lib/port-stream.js')
-rw-r--r-- | app/scripts/lib/port-stream.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js index d256efc9a..7f3e8072e 100644 --- a/app/scripts/lib/port-stream.js +++ b/app/scripts/lib/port-stream.js @@ -12,6 +12,7 @@ function PortDuplexStream(port){ }) this._port = port port.onMessage.addListener(this._onMessage.bind(this)) + port.onDisconnect.addListener(this._onDisconnect.bind(this)) } // private @@ -21,6 +22,15 @@ PortDuplexStream.prototype._onMessage = function(msg){ this.push(msg) } +PortDuplexStream.prototype._onDisconnect = function(msg){ + // console.log('PortDuplexStream - saw message', msg) + try { + this.end() + } catch(err){ + this.emit('error', err) + } +} + // stream plumbing PortDuplexStream.prototype._read = noop |