mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
metamask controller - track active controller connections
This commit is contained in:
parent
babd59a2dc
commit
3ac2b40dcf
@ -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…
x
Reference in New Issue
Block a user