feat: hook up event listeners

This commit is contained in:
Mazzella, Jesse D. (ARC-TI)[KBR Wyle Services, LLC] 2024-01-29 15:58:31 -08:00
parent d0c9d8b07d
commit 4047014f87
2 changed files with 12 additions and 2 deletions

View File

@ -32,6 +32,7 @@ export default class StatusAPI extends EventEmitter {
this.onProviderStatusChange = this.onProviderStatusChange.bind(this);
this.onProviderPollQuestionChange = this.onProviderPollQuestionChange.bind(this);
this.onMissionRoleStatusChange = this.onMissionRoleStatusChange.bind(this);
this.listenToStatusEvents = this.listenToStatusEvents.bind(this);
this.#openmct.once('destroy', () => {
@ -40,6 +41,7 @@ export default class StatusAPI extends EventEmitter {
if (typeof provider?.off === 'function') {
provider.off('statusChange', this.onProviderStatusChange);
provider.off('pollQuestionChange', this.onProviderPollQuestionChange);
provider.off('missionRoleStatusChange', this.onMissionRoleStatusChange);
}
});
@ -316,6 +318,7 @@ export default class StatusAPI extends EventEmitter {
if (typeof provider.on === 'function') {
provider.on('statusChange', this.onProviderStatusChange);
provider.on('pollQuestionChange', this.onProviderPollQuestionChange);
provider.on('missionRoleStatusChange', this.onMissionRoleStatusChange);
}
}
@ -332,6 +335,13 @@ export default class StatusAPI extends EventEmitter {
onProviderPollQuestionChange(pollQuestion) {
this.emit('pollQuestionChange', pollQuestion);
}
/**
* @private
*/
onMissionRoleStatusChange(role, newStatus) {
this.emit('missionRoleStatusChange', role, newStatus);
}
}
/**

View File

@ -23,12 +23,12 @@ import UserProvider from './UserProvider.js';
export default class StatusUserProvider extends UserProvider {
/**
* @param {('statusChange'|'pollQuestionChange')} event the name of the event to listen to
* @param {('statusChange'|'pollQuestionChange'|'missionRoleStatusChange')} event the name of the event to listen to
* @param {Function} callback a function to invoke when this event occurs
*/
on(event, callback) {}
/**
* @param {('statusChange'|'pollQuestionChange')} event the name of the event to stop listen to
* @param {('statusChange'|'pollQuestionChange'|'missionRoleStatusChange')} event the name of the event to stop listen to
* @param {Function} callback the callback function used to register the listener
*/
off(event, callback) {}