mirror of
https://github.com/nasa/openmct.git
synced 2025-01-14 08:49:58 +00:00
Updates to broadcast channel lifecycle
This commit is contained in:
parent
53fea64152
commit
2c4b3c38fd
@ -112,14 +112,12 @@ export default {
|
|||||||
async fetchOrPromptForRole() {
|
async fetchOrPromptForRole() {
|
||||||
const UserAPI = this.openmct.user;
|
const UserAPI = this.openmct.user;
|
||||||
const activeRole = UserAPI.getActiveRole();
|
const activeRole = UserAPI.getActiveRole();
|
||||||
console.log('fetchOrPromptRole', activeRole)
|
this.selectedRole = activeRole;
|
||||||
if (!activeRole) {
|
if (!activeRole) {
|
||||||
// trigger role selection modal
|
// trigger role selection modal
|
||||||
this.promptForRoleSelection();
|
this.promptForRoleSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectedRole = activeRole;
|
|
||||||
|
|
||||||
this.role = await this.openmct.user.status.getStatusRoleForCurrentUser();
|
this.role = await this.openmct.user.status.getStatusRoleForCurrentUser();
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -134,14 +132,14 @@ export default {
|
|||||||
currentSelection: this.selectedRole,
|
currentSelection: this.selectedRole,
|
||||||
onChange: (event) => {
|
onChange: (event) => {
|
||||||
console.log('updateRole', event.target.value)
|
console.log('updateRole', event.target.value)
|
||||||
this.role = event.target.value;
|
this.selectedRole = event.target.value;
|
||||||
},
|
},
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
label: 'Select',
|
label: 'Select',
|
||||||
emphasis: true,
|
emphasis: true,
|
||||||
callback: () => {
|
callback: () => {
|
||||||
this.setRole(this.role);
|
this.setRole(this.selectedRole);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,22 +228,28 @@ export default {
|
|||||||
},
|
},
|
||||||
createRoleChannel() {
|
createRoleChannel() {
|
||||||
this.roleChannel = new BroadcastChannel(BROADCAST_CHANNEL_NAME);
|
this.roleChannel = new BroadcastChannel(BROADCAST_CHANNEL_NAME);
|
||||||
this.roleChannel.onmessage = (({data}) => {
|
this.roleChannel.onmessage = (event => {
|
||||||
const role = data;
|
const role = event.data;
|
||||||
this.openmct.user.setActiveRole(role);
|
this.openmct.user.setActiveRole(role);
|
||||||
});
|
});
|
||||||
this.roleChannel.onmessageerror = event => console.log(event);
|
|
||||||
},
|
},
|
||||||
unsubscribeToRole() {
|
unsubscribeToRole() {
|
||||||
this.roleChannel.close();
|
this.roleChannel.close();
|
||||||
},
|
},
|
||||||
broadcastNewRole(role) {
|
broadcastNewRole(role) {
|
||||||
// channel closed if name is no longer available
|
|
||||||
if (!this.roleChannel.name) {
|
if (!this.roleChannel.name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.roleChannel.postMessage(role);
|
try {
|
||||||
|
this.roleChannel.postMessage(role);
|
||||||
|
} catch (e) {
|
||||||
|
/** FIXME: there doesn't seem to be a reliable way to test for open/closed
|
||||||
|
* status of a broadcast channel; channel.name exists even after the channel is closed
|
||||||
|
* failure to update the subscribed tabs, should not block the focused tab's selection.
|
||||||
|
* An error will often be thrown if the dialog remains open during HMR
|
||||||
|
**/
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
noop() {}
|
noop() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user