2016-12-28 00:46:55 +00:00
|
|
|
/* global APP */
|
2017-05-02 22:39:36 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
REMOTE_CONTROL_EVENT_NAME
|
|
|
|
} from "../../service/remotecontrol/Constants";
|
|
|
|
|
2017-01-19 21:13:05 +00:00
|
|
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
2016-12-28 00:46:55 +00:00
|
|
|
|
|
|
|
export default class RemoteControlParticipant {
|
|
|
|
/**
|
|
|
|
* Creates new instance.
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
this.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables / Disables the remote control
|
|
|
|
* @param {boolean} enabled the new state.
|
|
|
|
*/
|
|
|
|
enable(enabled) {
|
|
|
|
this.enabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends remote control event to other participant trough data channel.
|
2017-01-19 23:19:58 +00:00
|
|
|
* @param {RemoteControlEvent} event the remote control event.
|
2016-12-28 00:46:55 +00:00
|
|
|
* @param {Function} onDataChannelFail handler for data channel failure.
|
|
|
|
*/
|
|
|
|
_sendRemoteControlEvent(to, event, onDataChannelFail = () => {}) {
|
2017-01-19 21:13:05 +00:00
|
|
|
if(!this.enabled || !to) {
|
2017-05-02 22:39:36 +00:00
|
|
|
logger.warn(
|
|
|
|
"Remote control: Skip sending remote control event. Params:",
|
|
|
|
this.enable,
|
|
|
|
to);
|
2016-12-28 00:46:55 +00:00
|
|
|
return;
|
2017-01-19 21:13:05 +00:00
|
|
|
}
|
2016-12-28 00:46:55 +00:00
|
|
|
try{
|
2017-05-01 22:11:26 +00:00
|
|
|
APP.conference.sendEndpointMessage(to, {
|
2017-05-02 22:39:36 +00:00
|
|
|
name: REMOTE_CONTROL_EVENT_NAME,
|
2017-05-01 22:11:26 +00:00
|
|
|
...event
|
|
|
|
});
|
2016-12-28 00:46:55 +00:00
|
|
|
} catch (e) {
|
2017-05-02 22:39:36 +00:00
|
|
|
logger.error(
|
|
|
|
"Failed to send EndpointMessage via the datachannels",
|
2017-01-19 21:13:05 +00:00
|
|
|
e);
|
2016-12-28 00:46:55 +00:00
|
|
|
onDataChannelFail(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|