time, such * as name, device name, version... this runtimeInfo should be used rather than calling * APIs on the client. */ getRuntimeInfoByRemoteId(remoteId) { const key = this._getKeyByRemoteId(remoteId); return this._runtimeInfoMap.get(key); } /** * Retrieve a managed client for a remote id. The remote id should have been generated * using getRemoteId. */ getConnectionTypeByRemoteId(remoteId) { const key = this._getKeyByRemoteId(remoteId); for (const type of Object.values(CONNECTION_TYPES)) { if (key.endsWith(type)) { return type; } } return CONNECTION_TYPES.UNKNOWN; } _getKey(id, type) { return id + "-" + type; } _getKeyByRemoteId(remoteId) { if (!remoteId) { // If no remote id was provided, return the key corresponding to the local // this-firefox runtime. const { THIS_FIREFOX } = CONNECTION_TYPES; return this._getKey(THIS_FIREFOX, THIS_FIREFOX); } return decodeURIComponent(remoteId); } _removeClientByKey(key) { const client = this._clients.get(key); if (client) { client.off("closed", this._onClientClosed); this._clients.delete(key); this._runtimeInfoMap.delete(key); } } /** * Cleanup all closed clients when a "closed" notification is received from a client. */ _onClientClosed() { const closedClientKeys = [...this._clients.keys()].filter(key => { return this._clients.get(key)._transportClosed; }); for (const key of closedClientKeys) { this._removeClientByKey(key); } } } // Expose a singleton of RemoteClientManager. module.exports = { remoteClientManager: new RemoteClientManager(), }; PK