From 6444e9139e723120753a033c64e79c1b515229f8 Mon Sep 17 00:00:00 2001 From: Michael Rogers Date: Tue, 20 Jun 2023 17:28:52 -0500 Subject: [PATCH] Moved roleChannel to private field --- src/api/user/RoleChannel.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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