2016-12-20 22:15:13 +00:00
|
|
|
/* global APP, config */
|
2017-01-19 21:13:05 +00:00
|
|
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
2016-12-20 22:15:13 +00:00
|
|
|
import Controller from "./Controller";
|
|
|
|
import Receiver from "./Receiver";
|
2017-01-06 01:18:07 +00:00
|
|
|
import {EVENT_TYPES, DISCO_REMOTE_CONTROL_FEATURE}
|
2016-12-28 00:46:55 +00:00
|
|
|
from "../../service/remotecontrol/Constants";
|
2016-12-20 22:15:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the remote control functionality.
|
|
|
|
*/
|
|
|
|
class RemoteControl {
|
|
|
|
/**
|
|
|
|
* Constructs new instance. Creates controller and receiver properties.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
this.controller = new Controller();
|
|
|
|
this.receiver = new Receiver();
|
|
|
|
this.enabled = false;
|
|
|
|
this.initialized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the remote control - checks if the remote control should be
|
|
|
|
* enabled or not, initializes the API module.
|
|
|
|
*/
|
|
|
|
init() {
|
2017-01-06 01:18:07 +00:00
|
|
|
if(config.disableRemoteControl || this.initialized
|
|
|
|
|| !APP.conference.isDesktopSharingEnabled) {
|
2016-12-20 22:15:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-19 21:13:05 +00:00
|
|
|
logger.log("Initializing remote control.");
|
2016-12-20 22:15:13 +00:00
|
|
|
this.initialized = true;
|
|
|
|
APP.API.init({
|
|
|
|
forceEnable: true,
|
|
|
|
});
|
|
|
|
this.controller.enable(true);
|
2017-01-06 01:18:07 +00:00
|
|
|
if(this.enabled) { // supported message came before init.
|
|
|
|
this._onRemoteControlSupported();
|
|
|
|
}
|
2016-12-20 22:15:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 00:46:55 +00:00
|
|
|
/**
|
2017-01-18 00:16:18 +00:00
|
|
|
* Handles remote control events from the API module. Currently only events
|
|
|
|
* with type = EVENT_TYPES.supported or EVENT_TYPES.permissions
|
2017-01-19 23:19:58 +00:00
|
|
|
* @param {RemoteControlEvent} event the remote control event.
|
2016-12-28 00:46:55 +00:00
|
|
|
*/
|
|
|
|
onRemoteControlAPIEvent(event) {
|
|
|
|
switch(event.type) {
|
|
|
|
case EVENT_TYPES.supported:
|
|
|
|
this._onRemoteControlSupported();
|
|
|
|
break;
|
|
|
|
case EVENT_TYPES.permissions:
|
|
|
|
this.receiver._onRemoteControlPermissionsEvent(
|
|
|
|
event.userId, event.action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-20 22:15:13 +00:00
|
|
|
/**
|
|
|
|
* Handles API event for support for executing remote control events into
|
|
|
|
* the wrapper application.
|
|
|
|
*/
|
2016-12-28 00:46:55 +00:00
|
|
|
_onRemoteControlSupported() {
|
2017-01-19 21:13:05 +00:00
|
|
|
logger.log("Remote Control supported.");
|
2016-12-28 00:46:55 +00:00
|
|
|
if(!config.disableRemoteControl) {
|
2016-12-20 22:15:13 +00:00
|
|
|
this.enabled = true;
|
|
|
|
if(this.initialized) {
|
|
|
|
this.receiver.enable(true);
|
|
|
|
}
|
2017-01-19 21:13:05 +00:00
|
|
|
} else {
|
|
|
|
logger.log("Remote Control disabled.");
|
2016-12-20 22:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-06 01:18:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the passed user supports remote control or not
|
|
|
|
* @param {JitsiParticipant} user the user to be tested
|
|
|
|
* @returns {Promise<boolean>} the promise will be resolved with true if
|
|
|
|
* the user supports remote control and with false if not.
|
|
|
|
*/
|
|
|
|
checkUserRemoteControlSupport(user) {
|
|
|
|
return user.getFeatures().then(features =>
|
|
|
|
features.has(DISCO_REMOTE_CONTROL_FEATURE), () => false
|
|
|
|
);
|
|
|
|
}
|
2016-12-20 22:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new RemoteControl();
|