diff --git a/src/api/user/RoleChannel.js b/src/api/user/RoleChannel.js index 64619b0b6d..486514e630 100644 --- a/src/api/user/RoleChannel.js +++ b/src/api/user/RoleChannel.js @@ -1,17 +1,18 @@ import { BROADCAST_CHANNEL_NAME } from './constants'; class RoleChannel { + #roleChannel; + constructor(openmct, channelName = BROADCAST_CHANNEL_NAME) { this.openmct = openmct; this.channelName = channelName; - this.roleChannel = undefined; } createRoleChannel() { - this.roleChannel = new BroadcastChannel(this.channelName); + this.#roleChannel = new BroadcastChannel(this.channelName); } subscribeToRole(cb) { - this.roleChannel.onmessage = (event => { + this.#roleChannel.onmessage = (event => { const role = event.data; this.openmct.user.setActiveRole(role); if (cb) { @@ -20,21 +21,23 @@ class RoleChannel { }); } unsubscribeToRole() { - this.roleChannel.close(); + this.#roleChannel.close(); } reconnect() { - this.roleChannel.close(); + this.#roleChannel.close(); this.createRoleChannel(); } broadcastNewRole(role) { - if (!this.roleChannel.name) { + + if (!this.#roleChannel.name) { return false; } try { - this.roleChannel.postMessage(role); + this.#roleChannel.postMessage(role); } catch (e) { + console.error(e); this.reconnect(); this.broadcastNewRole(role); /** FIXME: there doesn't seem to be a reliable way to test for open/closed