2022-11-28 10:52:24 +00:00
|
|
|
import React from 'react';
|
2020-11-14 04:09:25 +00:00
|
|
|
|
2022-11-28 10:52:24 +00:00
|
|
|
// @ts-expect-error
|
2020-11-14 04:09:25 +00:00
|
|
|
import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
|
2022-11-28 10:52:24 +00:00
|
|
|
import { IReduxState, IStore } from '../app/types';
|
|
|
|
import { IJitsiConference } from '../base/conference/reducer';
|
2020-11-14 04:09:25 +00:00
|
|
|
import JitsiMeetJS from '../base/lib-jitsi-meet';
|
|
|
|
|
|
|
|
import { enableReceiver, stopReceiver } from './actions';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { EVENTS, REMOTE_CONTROL_MESSAGE_NAME } from './constants';
|
2020-11-14 04:09:25 +00:00
|
|
|
import { keyboardEventToKey } from './keycodes';
|
|
|
|
import logger from './logger';
|
|
|
|
|
|
|
|
/**
|
2022-07-14 07:10:08 +00:00
|
|
|
* Checks if the remote control is enabled.
|
2020-11-14 04:09:25 +00:00
|
|
|
*
|
|
|
|
* @param {*} state - The redux state.
|
|
|
|
* @returns {boolean} - True if the remote control is enabled and false otherwise.
|
|
|
|
*/
|
2022-11-28 10:52:24 +00:00
|
|
|
export function isRemoteControlEnabled(state: IReduxState) {
|
2020-11-14 04:09:25 +00:00
|
|
|
return !state['features/base/config'].disableRemoteControl && JitsiMeetJS.isDesktopSharingEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-16 15:59:33 +00:00
|
|
|
* Sends remote control message to other participant through data channel.
|
2020-11-14 04:09:25 +00:00
|
|
|
*
|
|
|
|
* @param {JitsiConference} conference - The JitsiConference object.
|
|
|
|
* @param {string} to - The participant who will receive the event.
|
|
|
|
* @param {RemoteControlEvent} event - The remote control event.
|
|
|
|
* @returns {boolean} - True if the message was sent successfully and false otherwise.
|
|
|
|
*/
|
|
|
|
export function sendRemoteControlEndpointMessage(
|
2022-11-28 10:52:24 +00:00
|
|
|
conference: IJitsiConference | undefined,
|
|
|
|
to: string | undefined,
|
2020-11-14 04:09:25 +00:00
|
|
|
event: Object) {
|
|
|
|
if (!to) {
|
|
|
|
logger.warn('Remote control: Skip sending remote control event. Params:', to);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-11-28 10:52:24 +00:00
|
|
|
conference?.sendEndpointMessage(to, {
|
2020-11-14 04:09:25 +00:00
|
|
|
name: REMOTE_CONTROL_MESSAGE_NAME,
|
|
|
|
...event
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
logger.error('Failed to send EndpointMessage via the datachannels', error);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles remote control events from the external app. Currently only
|
|
|
|
* events with type EVENTS.supported and EVENTS.stop are
|
|
|
|
* supported.
|
|
|
|
*
|
|
|
|
* @param {RemoteControlEvent} event - The remote control event.
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-11-28 10:52:24 +00:00
|
|
|
export function onRemoteControlAPIEvent(event: { type: string; }, { getState, dispatch }: IStore) {
|
2020-11-14 04:09:25 +00:00
|
|
|
switch (event.type) {
|
|
|
|
case EVENTS.supported:
|
|
|
|
logger.log('Remote Control supported.');
|
|
|
|
if (isRemoteControlEnabled(getState())) {
|
|
|
|
dispatch(enableReceiver());
|
|
|
|
} else {
|
|
|
|
logger.log('Remote Control disabled.');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EVENTS.stop: {
|
|
|
|
dispatch(stopReceiver());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the area used for capturing mouse and key events.
|
|
|
|
*
|
|
|
|
* @returns {JQuery} - A JQuery selector.
|
|
|
|
*/
|
|
|
|
export function getRemoteConrolEventCaptureArea() {
|
|
|
|
return VideoLayout.getLargeVideoWrapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the keyboard key from the keyboard event.
|
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} event - The event.
|
|
|
|
* @returns {KEYS} The key that is pressed or undefined.
|
|
|
|
*/
|
2022-11-28 10:52:24 +00:00
|
|
|
export function getKey(event: React.KeyboardEvent) {
|
2020-11-14 04:09:25 +00:00
|
|
|
return keyboardEventToKey(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the modifiers from the keyboard event.
|
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} event - The event.
|
|
|
|
* @returns {Array} With possible values: "shift", "control", "alt", "command".
|
|
|
|
*/
|
2022-11-28 10:52:24 +00:00
|
|
|
export function getModifiers(event: React.KeyboardEvent) {
|
2020-11-14 04:09:25 +00:00
|
|
|
const modifiers = [];
|
|
|
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
modifiers.push('shift');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.ctrlKey) {
|
|
|
|
modifiers.push('control');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (event.altKey) {
|
|
|
|
modifiers.push('alt');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.metaKey) {
|
|
|
|
modifiers.push('command');
|
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|