metamask controller - track active controller connections

feature/default_network_editable
kumavis 6 years ago
parent babd59a2dc
commit 3ac2b40dcf
  1. 12
      app/scripts/metamask-controller.js

@ -67,6 +67,10 @@ module.exports = class MetamaskController extends EventEmitter {
const initState = opts.initState || {} const initState = opts.initState || {}
this.recordFirstTimeInfo(initState) this.recordFirstTimeInfo(initState)
// this keeps track of how many "controllerStream" connections are open
// the only thing that uses controller connections are open metamask UI instances
this.activeControllerConnections = 0
// platform-specific api // platform-specific api
this.platform = opts.platform this.platform = opts.platform
@ -1209,11 +1213,19 @@ module.exports = class MetamaskController extends EventEmitter {
setupControllerConnection (outStream) { setupControllerConnection (outStream) {
const api = this.getApi() const api = this.getApi()
const dnode = Dnode(api) const dnode = Dnode(api)
// report new active controller connection
this.activeControllerConnections++
this.emit('controllerConnectionChanged', this.activeControllerConnections)
// connect dnode api to remote connection
pump( pump(
outStream, outStream,
dnode, dnode,
outStream, outStream,
(err) => { (err) => {
// report new active controller connection
this.activeControllerConnections--
this.emit('controllerConnectionChanged', this.activeControllerConnections)
// report any error
if (err) log.error(err) if (err) log.error(err)
} }
) )

Loading…
Cancel
Save