mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
background - stream disconnection fix
This commit is contained in:
parent
2f79781ab9
commit
fc3a53ec7b
@ -122,17 +122,16 @@ function setupController (initState) {
|
||||
// remote features
|
||||
//
|
||||
|
||||
function setupControllerConnection (stream) {
|
||||
controller.stream = stream
|
||||
function setupControllerConnection (outStream) {
|
||||
var api = controller.getApi()
|
||||
var dnode = Dnode(api)
|
||||
stream.pipe(dnode).pipe(stream)
|
||||
outStream.pipe(dnode).pipe(outStream)
|
||||
dnode.on('remote', (remote) => {
|
||||
// push updates to popup
|
||||
var sendUpdate = remote.sendUpdate.bind(remote)
|
||||
controller.on('update', sendUpdate)
|
||||
// teardown on disconnect
|
||||
eos(stream, () => {
|
||||
eos(outStream, () => {
|
||||
controller.removeListener('update', sendUpdate)
|
||||
popupIsOpen = false
|
||||
})
|
||||
|
@ -1,4 +1,5 @@
|
||||
const Through = require('through2')
|
||||
const endOfStream = require('end-of-stream')
|
||||
const ObjectMultiplex = require('./obj-multiplex')
|
||||
|
||||
module.exports = {
|
||||
@ -24,11 +25,11 @@ function jsonStringifyStream () {
|
||||
function setupMultiplex (connectionStream) {
|
||||
var mx = ObjectMultiplex()
|
||||
connectionStream.pipe(mx).pipe(connectionStream)
|
||||
mx.on('error', function (err) {
|
||||
console.error(err)
|
||||
endOfStream(mx, function (err) {
|
||||
if (err) console.error(err)
|
||||
})
|
||||
connectionStream.on('error', function (err) {
|
||||
console.error(err)
|
||||
endOfStream(connectionStream, function (err) {
|
||||
if (err) console.error(err)
|
||||
mx.destroy()
|
||||
})
|
||||
return mx
|
||||
|
Loading…
Reference in New Issue
Block a user