mirror of
https://github.com/nasa/openmct.git
synced 2024-12-26 08:11:05 +00:00
Moved roleChannel to private field
This commit is contained in:
parent
af1fc68766
commit
6444e9139e
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user