jiti-meet/modules/remotecontrol/RemoteControlParticipant.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

/* @flow */
import { getLogger } from 'jitsi-meet-logger';
import {
REMOTE_CONTROL_EVENT_NAME
} from '../../service/remotecontrol/Constants';
const logger = getLogger(__filename);
declare var APP: Object;
/**
* Implements common logic for Receiver class and Controller class.
*/
export default class RemoteControlParticipant {
_enabled: boolean;
/**
* Creates new instance.
*/
constructor() {
this._enabled = false;
}
/**
* Enables / Disables the remote control.
*
* @param {boolean} enabled - The new state.
* @returns {void}
*/
enable(enabled: boolean) {
this._enabled = enabled;
}
/**
* Sends remote control event to other participant trough data channel.
*
* @param {string} to - The participant who will receive the event.
* @param {RemoteControlEvent} event - The remote control event.
* @param {Function} onDataChannelFail - Handler for data channel failure.
* @returns {void}
*/
sendRemoteControlEvent(
to: ?string,
event: Object,
onDataChannelFail: ?Function) {
if (!this._enabled || !to) {
logger.warn(
'Remote control: Skip sending remote control event. Params:',
this.enable,
to);
return;
2017-01-19 21:13:05 +00:00
}
try {
APP.conference.sendEndpointMessage(to, {
name: REMOTE_CONTROL_EVENT_NAME,
...event
});
} catch (e) {
logger.error(
'Failed to send EndpointMessage via the datachannels',
2017-01-19 21:13:05 +00:00
e);
if (typeof onDataChannelFail === 'function') {
onDataChannelFail(e);
}
}
}
}