From bd98d661d3cc8e2a2c8edb44c7a65b15a736660a Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Mon, 23 Jan 2017 12:07:08 -0600 Subject: [PATCH] ref(remotecontrol): Moves hangup logic to remote control module --- ConferenceEvents.js | 4 ++++ conference.js | 27 ++++++++++++++++++++++++--- modules/remotecontrol/Receiver.js | 14 ++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 ConferenceEvents.js diff --git a/ConferenceEvents.js b/ConferenceEvents.js new file mode 100644 index 000000000..2dfa4cd87 --- /dev/null +++ b/ConferenceEvents.js @@ -0,0 +1,4 @@ +/** + * Notifies interested parties that hangup procedure will start. + */ +export const BEFORE_HANGUP = "conference.before_hangup"; diff --git a/conference.js b/conference.js index eb3472dd1..ffda92fb2 100644 --- a/conference.js +++ b/conference.js @@ -14,11 +14,11 @@ import {reportError} from './modules/util/helpers'; import UIEvents from './service/UI/UIEvents'; import UIUtil from './modules/UI/util/UIUtil'; +import * as JitsiMeetConferenceEvents from './ConferenceEvents'; import analytics from './modules/analytics/analytics'; -// For remote control testing: -// import remoteControlReceiver from './modules/remotecontrol/Receiver'; +import EventEmitter from "events"; const ConnectionEvents = JitsiMeetJS.events.connection; const ConnectionErrors = JitsiMeetJS.errors.connection; @@ -31,6 +31,8 @@ const TrackErrors = JitsiMeetJS.errors.track; const ConnectionQualityEvents = JitsiMeetJS.events.connectionQuality; +const eventEmitter = new EventEmitter(); + let room, connection, localAudio, localVideo; /** @@ -1783,8 +1785,8 @@ export default { * requested */ hangup (requestFeedback = false) { + eventEmitter.emit(JitsiMeetConferenceEvents.BEFORE_HANGUP); APP.UI.hideRingOverLay(); - APP.remoteControl.receiver.enable(false); let requestFeedbackPromise = requestFeedback ? APP.UI.requestFeedbackOnHangup() // false - because the thank you dialog shouldn't be displayed @@ -1846,5 +1848,24 @@ export default { */ sendEndpointMessage (to, payload) { room.sendEndpointMessage(to, payload); + }, + + /** + * Adds new listener. + * @param {String} eventName the name of the event + * @param {Function} listener the listener. + */ + addListener (eventName, listener) { + eventEmitter.addListener(eventName, listener); + }, + + /** + * Removes listener. + * @param {String} eventName the name of the event that triggers the + * listener + * @param {Function} listener the listener. + */ + removeListener (eventName, listener) { + eventEmitter.removeListener(eventName, listener); } }; diff --git a/modules/remotecontrol/Receiver.js b/modules/remotecontrol/Receiver.js index 2ffdc5afd..9b856e0d1 100644 --- a/modules/remotecontrol/Receiver.js +++ b/modules/remotecontrol/Receiver.js @@ -3,6 +3,7 @@ const logger = require("jitsi-meet-logger").getLogger(__filename); import {DISCO_REMOTE_CONTROL_FEATURE, REMOTE_CONTROL_EVENT_TYPE, EVENT_TYPES, PERMISSIONS_ACTIONS} from "../../service/remotecontrol/Constants"; import RemoteControlParticipant from "./RemoteControlParticipant"; +import * as JitsiMeetConferenceEvents from '../../ConferenceEvents'; const ConferenceEvents = JitsiMeetJS.events.conference; @@ -23,6 +24,7 @@ export default class Receiver extends RemoteControlParticipant { this._remoteControlEventsListener = this._onRemoteControlEvent.bind(this); this._userLeftListener = this._onUserLeft.bind(this); + this._hangupListener = this._onHangup.bind(this); } /** @@ -40,6 +42,8 @@ export default class Receiver extends RemoteControlParticipant { APP.conference.addConferenceListener( ConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, this._remoteControlEventsListener); + APP.conference.addListener(JitsiMeetConferenceEvents.BEFORE_HANGUP, + this._hangupListener); } else { logger.log("Remote control receiver disabled."); this._stop(true); @@ -47,6 +51,9 @@ export default class Receiver extends RemoteControlParticipant { APP.conference.removeConferenceListener( ConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, this._remoteControlEventsListener); + APP.conference.removeListener( + JitsiMeetConferenceEvents.BEFORE_HANGUP, + this._hangupListener); } } @@ -174,4 +181,11 @@ export default class Receiver extends RemoteControlParticipant { this._stop(); } } + + /** + * Handles hangup events. Disables the receiver. + */ + _onHangup() { + this.enable(false); + } }