2017-05-03 23:57:52 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
import { getLogger } from 'jitsi-meet-logger';
|
|
|
|
|
2017-10-10 23:31:40 +00:00
|
|
|
import {
|
|
|
|
JitsiConferenceEvents
|
|
|
|
} from '../../react/features/base/lib-jitsi-meet';
|
2020-05-20 10:57:03 +00:00
|
|
|
import UIEvents from '../../service/UI/UIEvents';
|
2017-05-02 22:39:36 +00:00
|
|
|
import {
|
2017-06-22 21:28:57 +00:00
|
|
|
EVENTS,
|
2017-05-02 22:39:36 +00:00
|
|
|
PERMISSIONS_ACTIONS,
|
2017-06-22 21:28:57 +00:00
|
|
|
REMOTE_CONTROL_MESSAGE_NAME
|
2017-05-03 23:57:52 +00:00
|
|
|
} from '../../service/remotecontrol/Constants';
|
2017-08-17 16:43:22 +00:00
|
|
|
import * as RemoteControlEvents
|
|
|
|
from '../../service/remotecontrol/RemoteControlEvents';
|
2020-05-20 10:57:03 +00:00
|
|
|
import * as KeyCodes from '../keycode/keycode';
|
2017-05-03 23:57:52 +00:00
|
|
|
|
|
|
|
import RemoteControlParticipant from './RemoteControlParticipant';
|
|
|
|
|
|
|
|
declare var $: Function;
|
|
|
|
declare var APP: Object;
|
2016-12-28 00:46:55 +00:00
|
|
|
|
2017-05-03 23:57:52 +00:00
|
|
|
const logger = getLogger(__filename);
|
2016-12-09 23:15:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the keyboard key from the keyboard event.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} event - The event.
|
|
|
|
* @returns {KEYS} The key that is pressed or undefined.
|
2016-12-09 23:15:04 +00:00
|
|
|
*/
|
|
|
|
function getKey(event) {
|
|
|
|
return KeyCodes.keyboardEventToKey(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the modifiers from the keyboard event.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} event - The event.
|
|
|
|
* @returns {Array} With possible values: "shift", "control", "alt", "command".
|
2016-12-09 23:15:04 +00:00
|
|
|
*/
|
|
|
|
function getModifiers(event) {
|
2017-05-03 23:57:52 +00:00
|
|
|
const modifiers = [];
|
|
|
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
modifiers.push('shift');
|
2016-12-09 23:15:04 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 23:57:52 +00:00
|
|
|
if (event.ctrlKey) {
|
|
|
|
modifiers.push('control');
|
2016-12-09 23:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-03 23:57:52 +00:00
|
|
|
if (event.altKey) {
|
|
|
|
modifiers.push('alt');
|
2016-12-09 23:15:04 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 23:57:52 +00:00
|
|
|
if (event.metaKey) {
|
|
|
|
modifiers.push('command');
|
2016-12-09 23:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents the controller party for a remote controller session.
|
|
|
|
* It listens for mouse and keyboard events and sends them to the receiver
|
|
|
|
* party of the remote control session.
|
|
|
|
*/
|
2016-12-28 00:46:55 +00:00
|
|
|
export default class Controller extends RemoteControlParticipant {
|
2017-05-03 23:57:52 +00:00
|
|
|
_area: ?Object;
|
|
|
|
_controlledParticipant: string | null;
|
|
|
|
_isCollectingEvents: boolean;
|
|
|
|
_largeVideoChangedListener: Function;
|
|
|
|
_requestedParticipant: string | null;
|
|
|
|
_stopListener: Function;
|
|
|
|
_userLeftListener: Function;
|
|
|
|
|
2016-12-09 23:15:04 +00:00
|
|
|
/**
|
|
|
|
* Creates new instance.
|
|
|
|
*/
|
2016-12-20 22:15:13 +00:00
|
|
|
constructor() {
|
2016-12-28 00:46:55 +00:00
|
|
|
super();
|
2017-05-03 23:57:52 +00:00
|
|
|
this._isCollectingEvents = false;
|
|
|
|
this._controlledParticipant = null;
|
|
|
|
this._requestedParticipant = null;
|
2017-01-06 01:18:07 +00:00
|
|
|
this._stopListener = this._handleRemoteControlStoppedEvent.bind(this);
|
|
|
|
this._userLeftListener = this._onUserLeft.bind(this);
|
2017-01-10 18:51:25 +00:00
|
|
|
this._largeVideoChangedListener
|
|
|
|
= this._onLargeVideoIdChanged.bind(this);
|
2016-12-20 22:15:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 16:43:22 +00:00
|
|
|
/**
|
|
|
|
* Returns the current active participant's id.
|
|
|
|
*
|
|
|
|
* @returns {string|null} - The id of the current active participant.
|
|
|
|
*/
|
|
|
|
get activeParticipant(): string | null {
|
|
|
|
return this._requestedParticipant || this._controlledParticipant;
|
|
|
|
}
|
|
|
|
|
2016-12-20 22:15:13 +00:00
|
|
|
/**
|
2016-12-28 00:46:55 +00:00
|
|
|
* Requests permissions from the remote control receiver side.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {string} userId - The user id of the participant that will be
|
2016-12-28 00:46:55 +00:00
|
|
|
* requested.
|
2017-05-03 23:57:52 +00:00
|
|
|
* @param {JQuerySelector} eventCaptureArea - The area that is going to be
|
2017-01-20 20:26:25 +00:00
|
|
|
* used mouse and keyboard event capture.
|
2017-05-03 23:57:52 +00:00
|
|
|
* @returns {Promise<boolean>} Resolve values - true(accept), false(deny),
|
|
|
|
* null(the participant has left).
|
2016-12-20 22:15:13 +00:00
|
|
|
*/
|
2017-12-01 21:07:58 +00:00
|
|
|
requestPermissions(
|
|
|
|
userId: string,
|
|
|
|
eventCaptureArea: Object
|
|
|
|
): Promise<boolean | null> {
|
2017-05-16 17:45:39 +00:00
|
|
|
if (!this._enabled) {
|
2017-05-03 23:57:52 +00:00
|
|
|
return Promise.reject(new Error('Remote control is disabled!'));
|
2016-12-28 00:46:55 +00:00
|
|
|
}
|
2017-08-17 16:43:22 +00:00
|
|
|
this.emit(RemoteControlEvents.ACTIVE_CHANGED, true);
|
2017-05-03 23:57:52 +00:00
|
|
|
this._area = eventCaptureArea;// $("#largeVideoWrapper")
|
|
|
|
logger.log(`Requsting remote control permissions from: ${userId}`);
|
|
|
|
|
2016-12-28 00:46:55 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-05-03 23:57:52 +00:00
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
let onUserLeft, permissionsReplyListener;
|
|
|
|
|
2017-01-06 01:18:07 +00:00
|
|
|
const clearRequest = () => {
|
2017-05-03 23:57:52 +00:00
|
|
|
this._requestedParticipant = null;
|
2017-01-06 01:18:07 +00:00
|
|
|
APP.conference.removeConferenceListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
|
2017-01-06 01:18:07 +00:00
|
|
|
permissionsReplyListener);
|
|
|
|
APP.conference.removeConferenceListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConferenceEvents.USER_LEFT,
|
2017-01-06 01:18:07 +00:00
|
|
|
onUserLeft);
|
|
|
|
};
|
2017-05-03 23:57:52 +00:00
|
|
|
|
|
|
|
permissionsReplyListener = (participant, event) => {
|
2016-12-28 00:46:55 +00:00
|
|
|
let result = null;
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2016-12-28 00:46:55 +00:00
|
|
|
try {
|
|
|
|
result = this._handleReply(participant, event);
|
|
|
|
} catch (e) {
|
2017-05-03 23:57:52 +00:00
|
|
|
clearRequest();
|
2017-08-17 16:43:22 +00:00
|
|
|
this.emit(RemoteControlEvents.ACTIVE_CHANGED, false);
|
2016-12-28 00:46:55 +00:00
|
|
|
reject(e);
|
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
if (result !== null) {
|
2017-01-06 01:18:07 +00:00
|
|
|
clearRequest();
|
2017-08-17 16:43:22 +00:00
|
|
|
if (result === false) {
|
|
|
|
this.emit(RemoteControlEvents.ACTIVE_CHANGED, false);
|
|
|
|
}
|
2016-12-28 00:46:55 +00:00
|
|
|
resolve(result);
|
|
|
|
}
|
|
|
|
};
|
2017-05-03 23:57:52 +00:00
|
|
|
onUserLeft = id => {
|
|
|
|
if (id === this._requestedParticipant) {
|
2017-01-06 01:18:07 +00:00
|
|
|
clearRequest();
|
2017-08-17 16:43:22 +00:00
|
|
|
this.emit(RemoteControlEvents.ACTIVE_CHANGED, false);
|
2017-01-06 01:18:07 +00:00
|
|
|
resolve(null);
|
|
|
|
}
|
|
|
|
};
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2016-12-28 00:46:55 +00:00
|
|
|
APP.conference.addConferenceListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
|
2016-12-28 00:46:55 +00:00
|
|
|
permissionsReplyListener);
|
2017-10-10 23:31:40 +00:00
|
|
|
APP.conference.addConferenceListener(
|
|
|
|
JitsiConferenceEvents.USER_LEFT,
|
2017-01-06 01:18:07 +00:00
|
|
|
onUserLeft);
|
2017-05-03 23:57:52 +00:00
|
|
|
this._requestedParticipant = userId;
|
2017-12-01 21:07:58 +00:00
|
|
|
this.sendRemoteControlEndpointMessage(
|
|
|
|
userId,
|
|
|
|
{
|
|
|
|
type: EVENTS.permissions,
|
|
|
|
action: PERMISSIONS_ACTIONS.request
|
|
|
|
},
|
|
|
|
e => {
|
|
|
|
clearRequest();
|
|
|
|
reject(e);
|
|
|
|
});
|
2016-12-28 00:46:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the reply of the permissions request.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {JitsiParticipant} participant - The participant that has sent the
|
|
|
|
* reply.
|
|
|
|
* @param {RemoteControlEvent} event - The remote control event.
|
2017-12-01 21:07:58 +00:00
|
|
|
* @returns {boolean|null}
|
2016-12-28 00:46:55 +00:00
|
|
|
*/
|
2017-05-03 23:57:52 +00:00
|
|
|
_handleReply(participant: Object, event: Object) {
|
2016-12-28 00:46:55 +00:00
|
|
|
const userId = participant.getId();
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-05-16 17:45:39 +00:00
|
|
|
if (this._enabled
|
2017-06-22 21:28:57 +00:00
|
|
|
&& event.name === REMOTE_CONTROL_MESSAGE_NAME
|
|
|
|
&& event.type === EVENTS.permissions
|
2017-05-03 23:57:52 +00:00
|
|
|
&& userId === this._requestedParticipant) {
|
|
|
|
if (event.action !== PERMISSIONS_ACTIONS.grant) {
|
|
|
|
this._area = undefined;
|
2017-01-20 20:26:25 +00:00
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
switch (event.action) {
|
|
|
|
case PERMISSIONS_ACTIONS.grant: {
|
|
|
|
this._controlledParticipant = userId;
|
|
|
|
logger.log('Remote control permissions granted to:', userId);
|
|
|
|
this._start();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case PERMISSIONS_ACTIONS.deny:
|
|
|
|
return false;
|
|
|
|
case PERMISSIONS_ACTIONS.error:
|
|
|
|
throw new Error('Error occurred on receiver side');
|
|
|
|
default:
|
|
|
|
throw new Error('Unknown reply received!');
|
2016-12-28 00:46:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-03 23:57:52 +00:00
|
|
|
// different message type or another user -> ignoring the message
|
2016-12-28 00:46:55 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles remote control stopped.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {JitsiParticipant} participant - The participant that has sent the
|
|
|
|
* event.
|
|
|
|
* @param {Object} event - EndpointMessage event from the data channels.
|
|
|
|
* @property {string} type - The function process only events with
|
2017-06-22 21:28:57 +00:00
|
|
|
* name REMOTE_CONTROL_MESSAGE_NAME.
|
2017-05-03 23:57:52 +00:00
|
|
|
* @returns {void}
|
2016-12-28 00:46:55 +00:00
|
|
|
*/
|
2017-05-03 23:57:52 +00:00
|
|
|
_handleRemoteControlStoppedEvent(participant: Object, event: Object) {
|
2017-05-16 17:45:39 +00:00
|
|
|
if (this._enabled
|
2017-06-22 21:28:57 +00:00
|
|
|
&& event.name === REMOTE_CONTROL_MESSAGE_NAME
|
|
|
|
&& event.type === EVENTS.stop
|
2017-05-03 23:57:52 +00:00
|
|
|
&& participant.getId() === this._controlledParticipant) {
|
2016-12-28 00:46:55 +00:00
|
|
|
this._stop();
|
|
|
|
}
|
2016-12-20 22:15:13 +00:00
|
|
|
}
|
2016-12-09 23:15:04 +00:00
|
|
|
|
|
|
|
/**
|
2017-01-10 18:51:25 +00:00
|
|
|
* Starts processing the mouse and keyboard events. Sets conference
|
|
|
|
* listeners. Disables keyboard events.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @returns {void}
|
2016-12-09 23:15:04 +00:00
|
|
|
*/
|
2016-12-28 00:46:55 +00:00
|
|
|
_start() {
|
2017-05-03 23:57:52 +00:00
|
|
|
logger.log('Starting remote control controller.');
|
2017-01-10 18:51:25 +00:00
|
|
|
APP.UI.addListener(UIEvents.LARGE_VIDEO_ID_CHANGED,
|
|
|
|
this._largeVideoChangedListener);
|
2016-12-28 00:46:55 +00:00
|
|
|
APP.conference.addConferenceListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
|
2017-01-06 01:18:07 +00:00
|
|
|
this._stopListener);
|
2017-10-10 23:31:40 +00:00
|
|
|
APP.conference.addConferenceListener(JitsiConferenceEvents.USER_LEFT,
|
2017-01-06 01:18:07 +00:00
|
|
|
this._userLeftListener);
|
2017-01-10 18:51:25 +00:00
|
|
|
this.resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables the keyboatd shortcuts. Starts collecting remote control
|
2017-05-03 23:57:52 +00:00
|
|
|
* events. It can be used to resume an active remote control session wchich
|
|
|
|
* was paused with this.pause().
|
2017-01-10 18:51:25 +00:00
|
|
|
*
|
2017-05-03 23:57:52 +00:00
|
|
|
* @returns {void}
|
2017-01-10 18:51:25 +00:00
|
|
|
*/
|
|
|
|
resume() {
|
2017-12-01 21:07:58 +00:00
|
|
|
let area;
|
|
|
|
|
|
|
|
if (!this._enabled
|
|
|
|
|| this._isCollectingEvents
|
|
|
|
|| !(area = this._area)) {
|
2017-01-10 18:51:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
logger.log('Resuming remote control controller.');
|
|
|
|
this._isCollectingEvents = true;
|
2017-01-10 18:51:25 +00:00
|
|
|
APP.keyboardshortcut.enable(false);
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
area.mousemove(event => {
|
|
|
|
const area = this._area; // eslint-disable-line no-shadow
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
if (!area) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
const position = area.position();
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
this.sendRemoteControlEndpointMessage(this._controlledParticipant, {
|
|
|
|
type: EVENTS.mousemove,
|
|
|
|
x: (event.pageX - position.left) / area.width(),
|
|
|
|
y: (event.pageY - position.top) / area.height()
|
2016-12-09 23:15:04 +00:00
|
|
|
});
|
|
|
|
});
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
area.mousedown(this._onMouseClickHandler.bind(this, EVENTS.mousedown));
|
|
|
|
area.mouseup(this._onMouseClickHandler.bind(this, EVENTS.mouseup));
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
area.dblclick(
|
2017-06-22 21:28:57 +00:00
|
|
|
this._onMouseClickHandler.bind(this, EVENTS.mousedblclick));
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
area.contextmenu(() => false);
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
area[0].onmousewheel = event => {
|
2017-08-11 12:25:47 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2017-06-22 21:28:57 +00:00
|
|
|
this.sendRemoteControlEndpointMessage(this._controlledParticipant, {
|
|
|
|
type: EVENTS.mousescroll,
|
2016-12-09 23:15:04 +00:00
|
|
|
x: event.deltaX,
|
|
|
|
y: event.deltaY
|
|
|
|
});
|
2017-08-11 12:25:47 +00:00
|
|
|
|
|
|
|
return false;
|
2016-12-09 23:15:04 +00:00
|
|
|
};
|
2017-12-01 21:07:58 +00:00
|
|
|
|
2016-12-20 22:15:13 +00:00
|
|
|
$(window).keydown(this._onKeyPessHandler.bind(this,
|
2017-06-22 21:28:57 +00:00
|
|
|
EVENTS.keydown));
|
|
|
|
$(window).keyup(this._onKeyPessHandler.bind(this, EVENTS.keyup));
|
2016-12-09 23:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-06 01:18:07 +00:00
|
|
|
* Stops processing the mouse and keyboard events. Removes added listeners.
|
2017-01-10 18:51:25 +00:00
|
|
|
* Enables the keyboard shortcuts. Displays dialog to notify the user that
|
|
|
|
* remote control session has ended.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @returns {void}
|
2016-12-09 23:15:04 +00:00
|
|
|
*/
|
2016-12-28 00:46:55 +00:00
|
|
|
_stop() {
|
2017-05-03 23:57:52 +00:00
|
|
|
if (!this._controlledParticipant) {
|
2017-01-06 01:18:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
logger.log('Stopping remote control controller.');
|
2017-01-10 18:51:25 +00:00
|
|
|
APP.UI.removeListener(UIEvents.LARGE_VIDEO_ID_CHANGED,
|
|
|
|
this._largeVideoChangedListener);
|
2016-12-28 00:46:55 +00:00
|
|
|
APP.conference.removeConferenceListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
|
2017-01-06 01:18:07 +00:00
|
|
|
this._stopListener);
|
2017-10-10 23:31:40 +00:00
|
|
|
APP.conference.removeConferenceListener(JitsiConferenceEvents.USER_LEFT,
|
2017-01-06 01:18:07 +00:00
|
|
|
this._userLeftListener);
|
2017-01-10 18:51:25 +00:00
|
|
|
this.pause();
|
2017-06-22 21:28:57 +00:00
|
|
|
this._controlledParticipant = null;
|
2017-05-03 23:57:52 +00:00
|
|
|
this._area = undefined;
|
2017-08-17 16:43:22 +00:00
|
|
|
this.emit(RemoteControlEvents.ACTIVE_CHANGED, false);
|
2017-07-10 03:01:48 +00:00
|
|
|
APP.UI.messageHandler.notify(
|
2017-05-03 23:57:52 +00:00
|
|
|
'dialog.remoteControlTitle',
|
|
|
|
'dialog.remoteControlStopMessage'
|
2017-01-06 01:18:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-03 23:57:52 +00:00
|
|
|
* Executes this._stop() mehtod which stops processing the mouse and
|
|
|
|
* keyboard events, removes added listeners, enables the keyboard shortcuts,
|
|
|
|
* displays dialog to notify the user that remote control session has ended.
|
|
|
|
* In addition sends stop message to the controlled participant.
|
2017-01-10 18:51:25 +00:00
|
|
|
*
|
2017-05-03 23:57:52 +00:00
|
|
|
* @returns {void}
|
2017-01-06 01:18:07 +00:00
|
|
|
*/
|
|
|
|
stop() {
|
2017-05-03 23:57:52 +00:00
|
|
|
if (!this._controlledParticipant) {
|
2017-01-06 01:18:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-06-22 21:28:57 +00:00
|
|
|
this.sendRemoteControlEndpointMessage(this._controlledParticipant, {
|
|
|
|
type: EVENTS.stop
|
2017-01-06 01:18:07 +00:00
|
|
|
});
|
|
|
|
this._stop();
|
2016-12-09 23:15:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 18:51:25 +00:00
|
|
|
/**
|
|
|
|
* Pauses the collecting of events and enables the keyboard shortcus. But
|
|
|
|
* it doesn't removes any other listeners. Basically the remote control
|
|
|
|
* session will be still active after this.pause(), but no events from the
|
2017-05-03 23:57:52 +00:00
|
|
|
* controller side will be captured and sent. You can resume the collecting
|
|
|
|
* of the events with this.resume().
|
2017-01-10 18:51:25 +00:00
|
|
|
*
|
2017-05-03 23:57:52 +00:00
|
|
|
* @returns {void}
|
2017-01-10 18:51:25 +00:00
|
|
|
*/
|
|
|
|
pause() {
|
2017-05-03 23:57:52 +00:00
|
|
|
if (!this._controlledParticipant) {
|
2017-01-10 18:51:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
logger.log('Pausing remote control controller.');
|
|
|
|
this._isCollectingEvents = false;
|
2017-01-10 18:51:25 +00:00
|
|
|
APP.keyboardshortcut.enable(true);
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
const area = this._area;
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
if (area) {
|
|
|
|
area.off('contextmenu');
|
|
|
|
area.off('dblclick');
|
|
|
|
area.off('mousedown');
|
|
|
|
area.off('mousemove');
|
|
|
|
area.off('mouseup');
|
2017-05-03 23:57:52 +00:00
|
|
|
|
2017-12-01 21:07:58 +00:00
|
|
|
area[0].onmousewheel = undefined;
|
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
|
|
|
|
$(window).off('keydown');
|
|
|
|
$(window).off('keyup');
|
2017-01-10 18:51:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 23:15:04 +00:00
|
|
|
/**
|
|
|
|
* Handler for mouse click events.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {string} type - The type of event ("mousedown"/"mouseup").
|
|
|
|
* @param {Event} event - The mouse event.
|
|
|
|
* @returns {void}
|
2016-12-09 23:15:04 +00:00
|
|
|
*/
|
2017-05-03 23:57:52 +00:00
|
|
|
_onMouseClickHandler(type: string, event: Object) {
|
2017-06-22 21:28:57 +00:00
|
|
|
this.sendRemoteControlEndpointMessage(this._controlledParticipant, {
|
2017-05-03 23:57:52 +00:00
|
|
|
type,
|
2016-12-09 23:15:04 +00:00
|
|
|
button: event.which
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-06 01:18:07 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the remote control session is started.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
2017-01-06 01:18:07 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isStarted() {
|
2017-05-03 23:57:52 +00:00
|
|
|
return this._controlledParticipant !== null;
|
2017-01-06 01:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-03 23:57:52 +00:00
|
|
|
* Returns the id of the requested participant.
|
|
|
|
*
|
|
|
|
* @returns {string} The id of the requested participant.
|
2017-01-23 22:06:51 +00:00
|
|
|
* NOTE: This id should be the result of JitsiParticipant.getId() call.
|
2017-01-06 01:18:07 +00:00
|
|
|
*/
|
|
|
|
getRequestedParticipant() {
|
2017-05-03 23:57:52 +00:00
|
|
|
return this._requestedParticipant;
|
2017-01-06 01:18:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 23:15:04 +00:00
|
|
|
/**
|
|
|
|
* Handler for key press events.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {string} type - The type of event ("keydown"/"keyup").
|
|
|
|
* @param {Event} event - The key event.
|
|
|
|
* @returns {void}
|
2016-12-09 23:15:04 +00:00
|
|
|
*/
|
2017-05-03 23:57:52 +00:00
|
|
|
_onKeyPessHandler(type: string, event: Object) {
|
2017-06-22 21:28:57 +00:00
|
|
|
this.sendRemoteControlEndpointMessage(this._controlledParticipant, {
|
2017-05-03 23:57:52 +00:00
|
|
|
type,
|
2016-12-09 23:15:04 +00:00
|
|
|
key: getKey(event),
|
2017-05-03 23:57:52 +00:00
|
|
|
modifiers: getModifiers(event)
|
2016-12-09 23:15:04 +00:00
|
|
|
});
|
|
|
|
}
|
2017-01-06 01:18:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls the stop method if the other side have left.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {string} id - The user id for the participant that have left.
|
|
|
|
* @returns {void}
|
2017-01-06 01:18:07 +00:00
|
|
|
*/
|
2017-05-03 23:57:52 +00:00
|
|
|
_onUserLeft(id: string) {
|
|
|
|
if (this._controlledParticipant === id) {
|
2017-01-06 01:18:07 +00:00
|
|
|
this._stop();
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 18:51:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles changes of the participant displayed on the large video.
|
2017-05-03 23:57:52 +00:00
|
|
|
*
|
|
|
|
* @param {string} id - The user id for the participant that is displayed.
|
|
|
|
* @returns {void}
|
2017-01-10 18:51:25 +00:00
|
|
|
*/
|
2017-05-03 23:57:52 +00:00
|
|
|
_onLargeVideoIdChanged(id: string) {
|
|
|
|
if (!this._controlledParticipant) {
|
2017-01-10 18:51:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-03 23:57:52 +00:00
|
|
|
if (this._controlledParticipant === id) {
|
2017-01-10 18:51:25 +00:00
|
|
|
this.resume();
|
|
|
|
} else {
|
|
|
|
this.pause();
|
|
|
|
}
|
|
|
|
}
|
2016-12-09 23:15:04 +00:00
|
|
|
}
|