Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

actions.ts 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. // @ts-expect-error
  2. import $ from 'jquery';
  3. import React from 'react';
  4. import { IStore } from '../app/types';
  5. import { openDialog } from '../base/dialog/actions';
  6. import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
  7. import { pinParticipant } from '../base/participants/actions';
  8. import {
  9. getParticipantDisplayName,
  10. getPinnedParticipant,
  11. getVirtualScreenshareParticipantByOwnerId
  12. } from '../base/participants/functions';
  13. import { toggleScreensharing } from '../base/tracks/actions';
  14. import { getLocalDesktopTrack } from '../base/tracks/functions';
  15. import { showNotification } from '../notifications/actions';
  16. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  17. import { isScreenVideoShared } from '../screen-share/functions';
  18. import {
  19. CAPTURE_EVENTS,
  20. REMOTE_CONTROL_ACTIVE,
  21. SET_CONTROLLED_PARTICIPANT,
  22. SET_CONTROLLER,
  23. SET_RECEIVER_ENABLED,
  24. SET_RECEIVER_TRANSPORT,
  25. SET_REQUESTED_PARTICIPANT
  26. } from './actionTypes';
  27. import RemoteControlAuthorizationDialog from './components/RemoteControlAuthorizationDialog';
  28. import {
  29. DISCO_REMOTE_CONTROL_FEATURE,
  30. EVENTS,
  31. PERMISSIONS_ACTIONS,
  32. REMOTE_CONTROL_MESSAGE_NAME,
  33. REQUESTS
  34. } from './constants';
  35. import {
  36. getKey,
  37. getModifiers,
  38. getRemoteConrolEventCaptureArea,
  39. isRemoteControlEnabled,
  40. sendRemoteControlEndpointMessage
  41. } from './functions';
  42. import logger from './logger';
  43. /**
  44. * Listeners.
  45. */
  46. let permissionsReplyListener: Function | undefined,
  47. receiverEndpointMessageListener: Function, stopListener: Function | undefined;
  48. /**
  49. * Signals that the remote control authorization dialog should be displayed.
  50. *
  51. * @param {string} participantId - The id of the participant who is requesting
  52. * the authorization.
  53. * @returns {{
  54. * type: OPEN_DIALOG,
  55. * component: {RemoteControlAuthorizationDialog},
  56. * componentProps: {
  57. * participantId: {string}
  58. * }
  59. * }}
  60. * @public
  61. */
  62. export function openRemoteControlAuthorizationDialog(participantId: string) {
  63. return openDialog(RemoteControlAuthorizationDialog, { participantId });
  64. }
  65. /**
  66. * Sets the remote control active property.
  67. *
  68. * @param {boolean} active - The new value for the active property.
  69. * @returns {Function}
  70. */
  71. export function setRemoteControlActive(active: boolean) {
  72. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  73. const state = getState();
  74. const { active: oldActive } = state['features/remote-control'];
  75. const { conference } = state['features/base/conference'];
  76. if (active !== oldActive) {
  77. dispatch({
  78. type: REMOTE_CONTROL_ACTIVE,
  79. active
  80. });
  81. conference?.setLocalParticipantProperty('remoteControlSessionStatus', active);
  82. }
  83. };
  84. }
  85. /**
  86. * Requests permissions from the remote control receiver side.
  87. *
  88. * @param {string} userId - The user id of the participant that will be
  89. * requested.
  90. * @returns {Function}
  91. */
  92. export function requestRemoteControl(userId: string) {
  93. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  94. const state = getState();
  95. const enabled = isRemoteControlEnabled(state);
  96. if (!enabled) {
  97. return Promise.reject(new Error('Remote control is disabled!'));
  98. }
  99. dispatch(setRemoteControlActive(true));
  100. logger.log(`Requesting remote control permissions from: ${userId}`);
  101. const { conference } = state['features/base/conference'];
  102. permissionsReplyListener = (participant: any, event: any) => {
  103. dispatch(processPermissionRequestReply(participant.getId(), event));
  104. };
  105. conference?.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, permissionsReplyListener);
  106. dispatch({
  107. type: SET_REQUESTED_PARTICIPANT,
  108. requestedParticipant: userId
  109. });
  110. if (!sendRemoteControlEndpointMessage(
  111. conference,
  112. userId,
  113. {
  114. type: EVENTS.permissions,
  115. action: PERMISSIONS_ACTIONS.request
  116. })) {
  117. dispatch(clearRequest());
  118. }
  119. };
  120. }
  121. /**
  122. * Handles permission request replies on the controller side.
  123. *
  124. * @param {string} participantId - The participant that sent the request.
  125. * @param {EndpointMessage} event - The permission request event.
  126. * @returns {Function}
  127. */
  128. export function processPermissionRequestReply(participantId: string, event: any) {
  129. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  130. const state = getState();
  131. const { action, name, type } = event;
  132. const { requestedParticipant } = state['features/remote-control'].controller;
  133. if (isRemoteControlEnabled(state) && name === REMOTE_CONTROL_MESSAGE_NAME && type === EVENTS.permissions
  134. && participantId === requestedParticipant) {
  135. let descriptionKey, permissionGranted = false;
  136. switch (action) {
  137. case PERMISSIONS_ACTIONS.grant: {
  138. dispatch({
  139. type: SET_CONTROLLED_PARTICIPANT,
  140. controlled: participantId
  141. });
  142. logger.log('Remote control permissions granted!', participantId);
  143. logger.log('Starting remote control controller.');
  144. const { conference } = state['features/base/conference'];
  145. stopListener = (participant: any, stopEvent: { name: string; type: string; }) => {
  146. dispatch(handleRemoteControlStoppedEvent(participant.getId(), stopEvent));
  147. };
  148. conference?.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, stopListener);
  149. dispatch(resume());
  150. permissionGranted = true;
  151. descriptionKey = 'dialog.remoteControlAllowedMessage';
  152. break;
  153. }
  154. case PERMISSIONS_ACTIONS.deny:
  155. logger.log('Remote control permissions denied!', participantId);
  156. descriptionKey = 'dialog.remoteControlDeniedMessage';
  157. break;
  158. case PERMISSIONS_ACTIONS.error:
  159. logger.error('Error occurred on receiver side');
  160. descriptionKey = 'dialog.remoteControlErrorMessage';
  161. break;
  162. default:
  163. logger.error('Unknown reply received!');
  164. descriptionKey = 'dialog.remoteControlErrorMessage';
  165. }
  166. dispatch(clearRequest());
  167. if (!permissionGranted) {
  168. dispatch(setRemoteControlActive(false));
  169. }
  170. dispatch(showNotification({
  171. descriptionArguments: { user: getParticipantDisplayName(state, participantId) },
  172. descriptionKey,
  173. titleKey: 'dialog.remoteControlTitle'
  174. }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
  175. if (permissionGranted) {
  176. // the remote control permissions has been granted
  177. // pin the controlled participant
  178. const pinnedParticipant = getPinnedParticipant(state);
  179. const virtualScreenshareParticipant = getVirtualScreenshareParticipantByOwnerId(state, participantId);
  180. const pinnedId = pinnedParticipant?.id;
  181. if (virtualScreenshareParticipant?.id && pinnedId !== virtualScreenshareParticipant?.id) {
  182. dispatch(pinParticipant(virtualScreenshareParticipant?.id));
  183. } else if (!virtualScreenshareParticipant?.id && pinnedId !== participantId) {
  184. dispatch(pinParticipant(participantId));
  185. }
  186. }
  187. } else {
  188. // different message type or another user -> ignoring the message
  189. }
  190. };
  191. }
  192. /**
  193. * Handles remote control stopped.
  194. *
  195. * @param {string} participantId - The ID of the participant that has sent the event.
  196. * @param {EndpointMessage} event - EndpointMessage event from the data channels.
  197. * @property {string} type - The function process only events with name REMOTE_CONTROL_MESSAGE_NAME.
  198. * @returns {void}
  199. */
  200. export function handleRemoteControlStoppedEvent(participantId: Object, event: { name: string; type: string; }) {
  201. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  202. const state = getState();
  203. const { name, type } = event;
  204. const { controlled } = state['features/remote-control'].controller;
  205. if (isRemoteControlEnabled(state) && name === REMOTE_CONTROL_MESSAGE_NAME && type === EVENTS.stop
  206. && participantId === controlled) {
  207. dispatch(stopController());
  208. }
  209. };
  210. }
  211. /**
  212. * Stops processing the mouse and keyboard events. Removes added listeners.
  213. * Enables the keyboard shortcuts. Displays dialog to notify the user that remote control session has ended.
  214. *
  215. * @param {boolean} notifyRemoteParty - If true a endpoint message to the controlled participant will be sent.
  216. * @returns {void}
  217. */
  218. export function stopController(notifyRemoteParty = false) {
  219. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  220. const state = getState();
  221. const { controlled } = state['features/remote-control'].controller;
  222. if (!controlled) {
  223. return;
  224. }
  225. const { conference } = state['features/base/conference'];
  226. if (notifyRemoteParty) {
  227. sendRemoteControlEndpointMessage(conference, controlled, {
  228. type: EVENTS.stop
  229. });
  230. }
  231. logger.log('Stopping remote control controller.');
  232. conference?.off(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, stopListener);
  233. stopListener = undefined;
  234. dispatch(pause());
  235. dispatch({
  236. type: SET_CONTROLLED_PARTICIPANT,
  237. controlled: undefined
  238. });
  239. dispatch(setRemoteControlActive(false));
  240. dispatch(showNotification({
  241. descriptionKey: 'dialog.remoteControlStopMessage',
  242. titleKey: 'dialog.remoteControlTitle'
  243. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  244. };
  245. }
  246. /**
  247. * Clears a pending permission request.
  248. *
  249. * @returns {Function}
  250. */
  251. export function clearRequest() {
  252. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  253. const { conference } = getState()['features/base/conference'];
  254. dispatch({
  255. type: SET_REQUESTED_PARTICIPANT,
  256. requestedParticipant: undefined
  257. });
  258. conference?.off(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, permissionsReplyListener);
  259. permissionsReplyListener = undefined;
  260. };
  261. }
  262. /**
  263. * Sets that transport object that is used by the receiver to communicate with the native part of the remote control
  264. * implementation.
  265. *
  266. * @param {Transport} transport - The transport to be set.
  267. * @returns {{
  268. * type: SET_RECEIVER_TRANSPORT,
  269. * transport: Transport
  270. * }}
  271. */
  272. export function setReceiverTransport(transport?: Object) {
  273. return {
  274. type: SET_RECEIVER_TRANSPORT,
  275. transport
  276. };
  277. }
  278. /**
  279. * Enables the receiver functionality.
  280. *
  281. * @returns {Function}
  282. */
  283. export function enableReceiver() {
  284. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  285. const state = getState();
  286. const { enabled } = state['features/remote-control'].receiver;
  287. if (enabled) {
  288. return;
  289. }
  290. const { connection } = state['features/base/connection'];
  291. const { conference } = state['features/base/conference'];
  292. if (!connection || !conference) {
  293. logger.error('Couldn\'t enable the remote receiver! The connection or conference instance is undefined!');
  294. return;
  295. }
  296. dispatch({
  297. type: SET_RECEIVER_ENABLED,
  298. enabled: true
  299. });
  300. connection.addFeature(DISCO_REMOTE_CONTROL_FEATURE, true);
  301. receiverEndpointMessageListener = (participant: any, message: {
  302. action: string; name: string; type: string; }) => {
  303. dispatch(endpointMessageReceived(participant.getId(), message));
  304. };
  305. conference.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, receiverEndpointMessageListener);
  306. };
  307. }
  308. /**
  309. * Disables the receiver functionality.
  310. *
  311. * @returns {Function}
  312. */
  313. export function disableReceiver() {
  314. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  315. const state = getState();
  316. const { enabled } = state['features/remote-control'].receiver;
  317. if (!enabled) {
  318. return;
  319. }
  320. const { connection } = state['features/base/connection'];
  321. const { conference } = state['features/base/conference'];
  322. if (!connection || !conference) {
  323. logger.error('Couldn\'t enable the remote receiver! The connection or conference instance is undefined!');
  324. return;
  325. }
  326. logger.log('Remote control receiver disabled.');
  327. dispatch({
  328. type: SET_RECEIVER_ENABLED,
  329. enabled: false
  330. });
  331. dispatch(stopReceiver(true));
  332. connection.removeFeature(DISCO_REMOTE_CONTROL_FEATURE);
  333. conference.off(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, receiverEndpointMessageListener);
  334. };
  335. }
  336. /**
  337. * Stops a remote control session on the receiver side.
  338. *
  339. * @param {boolean} [dontNotifyLocalParty] - If true - a notification about stopping
  340. * the remote control won't be displayed.
  341. * @param {boolean} [dontNotifyRemoteParty] - If true a endpoint message to the controller participant will be sent.
  342. * @returns {Function}
  343. */
  344. export function stopReceiver(dontNotifyLocalParty = false, dontNotifyRemoteParty = false) {
  345. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  346. const state = getState();
  347. const { receiver } = state['features/remote-control'];
  348. const { controller, transport } = receiver;
  349. if (!controller) {
  350. return;
  351. }
  352. const { conference } = state['features/base/conference'];
  353. if (!dontNotifyRemoteParty) {
  354. sendRemoteControlEndpointMessage(conference, controller, {
  355. type: EVENTS.stop
  356. });
  357. }
  358. dispatch({
  359. type: SET_CONTROLLER,
  360. controller: undefined
  361. });
  362. transport?.sendEvent({
  363. name: REMOTE_CONTROL_MESSAGE_NAME,
  364. type: EVENTS.stop
  365. });
  366. dispatch(setRemoteControlActive(false));
  367. if (!dontNotifyLocalParty) {
  368. dispatch(showNotification({
  369. descriptionKey: 'dialog.remoteControlStopMessage',
  370. titleKey: 'dialog.remoteControlTitle'
  371. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  372. }
  373. };
  374. }
  375. /**
  376. * Handles only remote control endpoint messages.
  377. *
  378. * @param {string} participantId - The controller participant ID.
  379. * @param {Object} message - EndpointMessage from the data channels.
  380. * @param {string} message.name - The function processes only messages with
  381. * name REMOTE_CONTROL_MESSAGE_NAME.
  382. * @returns {Function}
  383. */
  384. export function endpointMessageReceived(participantId: string, message: {
  385. action: string; name: string; type: string; }) {
  386. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  387. const { action, name, type } = message;
  388. if (name !== REMOTE_CONTROL_MESSAGE_NAME) {
  389. return;
  390. }
  391. const state = getState();
  392. const { receiver } = state['features/remote-control'];
  393. const { enabled, transport } = receiver;
  394. if (enabled) {
  395. const { controller } = receiver;
  396. if (!controller && type === EVENTS.permissions && action === PERMISSIONS_ACTIONS.request) {
  397. dispatch(setRemoteControlActive(true));
  398. dispatch(openRemoteControlAuthorizationDialog(participantId));
  399. } else if (controller === participantId) {
  400. if (type === EVENTS.stop) {
  401. dispatch(stopReceiver(false, true));
  402. } else { // forward the message
  403. try {
  404. transport?.sendEvent(message);
  405. } catch (error) {
  406. logger.error('Error while trying to execute remote control message', error);
  407. }
  408. }
  409. } // else ignore
  410. } else {
  411. logger.log('Remote control message is ignored because remote control is disabled', message);
  412. }
  413. };
  414. }
  415. /**
  416. * Denies remote control access for user associated with the passed user id.
  417. *
  418. * @param {string} participantId - The id associated with the user who sent the
  419. * request for remote control authorization.
  420. * @returns {Function}
  421. */
  422. export function deny(participantId: string) {
  423. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  424. const state = getState();
  425. const { conference } = state['features/base/conference'];
  426. dispatch(setRemoteControlActive(false));
  427. sendRemoteControlEndpointMessage(conference, participantId, {
  428. type: EVENTS.permissions,
  429. action: PERMISSIONS_ACTIONS.deny
  430. });
  431. };
  432. }
  433. /**
  434. * Sends start remote control request to the native implementation.
  435. *
  436. * @returns {Function}
  437. */
  438. export function sendStartRequest() {
  439. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  440. const state = getState();
  441. const tracks = state['features/base/tracks'];
  442. const track = getLocalDesktopTrack(tracks);
  443. const { sourceId } = track?.jitsiTrack || {};
  444. const { transport } = state['features/remote-control'].receiver;
  445. if (typeof sourceId === 'undefined') {
  446. return Promise.reject(new Error('Cannot identify screen for the remote control session'));
  447. }
  448. return transport?.sendRequest({
  449. name: REMOTE_CONTROL_MESSAGE_NAME,
  450. type: REQUESTS.start,
  451. sourceId
  452. });
  453. };
  454. }
  455. /**
  456. * Grants remote control access to user associated with the passed user id.
  457. *
  458. * @param {string} participantId - The id associated with the user who sent the
  459. * request for remote control authorization.
  460. * @returns {Function}
  461. */
  462. export function grant(participantId: string) {
  463. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  464. dispatch({
  465. type: SET_CONTROLLER,
  466. controller: participantId
  467. });
  468. logger.log(`Remote control permissions granted to: ${participantId}`);
  469. let promise;
  470. const state = getState();
  471. const tracks = state['features/base/tracks'];
  472. const track = getLocalDesktopTrack(tracks);
  473. const isScreenSharing = isScreenVideoShared(state);
  474. const { sourceType } = track?.jitsiTrack || {};
  475. if (isScreenSharing && sourceType === 'screen') {
  476. promise = dispatch(sendStartRequest());
  477. } else {
  478. promise = dispatch(toggleScreensharing(
  479. true,
  480. false,
  481. { desktopSharingSources: [ 'screen' ] }
  482. ))
  483. .then(() => dispatch(sendStartRequest()));
  484. }
  485. const { conference } = state['features/base/conference'];
  486. promise
  487. .then(() => sendRemoteControlEndpointMessage(conference, participantId, {
  488. type: EVENTS.permissions,
  489. action: PERMISSIONS_ACTIONS.grant
  490. }))
  491. .catch((error: any) => {
  492. logger.error(error);
  493. sendRemoteControlEndpointMessage(conference, participantId, {
  494. type: EVENTS.permissions,
  495. action: PERMISSIONS_ACTIONS.error
  496. });
  497. dispatch(showNotification({
  498. descriptionKey: 'dialog.startRemoteControlErrorMessage',
  499. titleKey: 'dialog.remoteControlTitle'
  500. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  501. dispatch(stopReceiver(true));
  502. });
  503. };
  504. }
  505. /**
  506. * Handler for mouse click events on the controller side.
  507. *
  508. * @param {string} type - The type of event ("mousedown"/"mouseup").
  509. * @param {Event} event - The mouse event.
  510. * @returns {Function}
  511. */
  512. export function mouseClicked(type: string, event: React.MouseEvent) {
  513. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  514. const state = getState();
  515. const { conference } = state['features/base/conference'];
  516. const { controller } = state['features/remote-control'];
  517. sendRemoteControlEndpointMessage(conference, controller.controlled, {
  518. type,
  519. // @ts-ignore
  520. button: event.which
  521. });
  522. };
  523. }
  524. /**
  525. * Handles mouse moved events on the controller side.
  526. *
  527. * @param {Event} event - The mouse event.
  528. * @returns {Function}
  529. */
  530. export function mouseMoved(event: React.MouseEvent) {
  531. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  532. const area = getRemoteConrolEventCaptureArea();
  533. if (!area) {
  534. return;
  535. }
  536. const position = area.position();
  537. const state = getState();
  538. const { conference } = state['features/base/conference'];
  539. const { controller } = state['features/remote-control'];
  540. sendRemoteControlEndpointMessage(conference, controller.controlled, {
  541. type: EVENTS.mousemove,
  542. x: (event.pageX - position.left) / area.width(),
  543. y: (event.pageY - position.top) / area.height()
  544. });
  545. };
  546. }
  547. /**
  548. * Handles mouse scroll events on the controller side.
  549. *
  550. * @param {Event} event - The mouse event.
  551. * @returns {Function}
  552. */
  553. export function mouseScrolled(event: { deltaX: number; deltaY: number; }) {
  554. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  555. const state = getState();
  556. const { conference } = state['features/base/conference'];
  557. const { controller } = state['features/remote-control'];
  558. sendRemoteControlEndpointMessage(conference, controller.controlled, {
  559. type: EVENTS.mousescroll,
  560. x: event.deltaX,
  561. y: event.deltaY
  562. });
  563. };
  564. }
  565. /**
  566. * Handles key press events on the controller side..
  567. *
  568. * @param {string} type - The type of event ("keydown"/"keyup").
  569. * @param {Event} event - The key event.
  570. * @returns {Function}
  571. */
  572. export function keyPressed(type: string, event: React.KeyboardEvent) {
  573. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  574. const state = getState();
  575. const { conference } = state['features/base/conference'];
  576. const { controller } = state['features/remote-control'];
  577. sendRemoteControlEndpointMessage(conference, controller.controlled, {
  578. type,
  579. key: getKey(event),
  580. modifiers: getModifiers(event)
  581. });
  582. };
  583. }
  584. /**
  585. * Disables the keyboatd shortcuts. Starts collecting remote control
  586. * events. It can be used to resume an active remote control session which
  587. * was paused with the pause action.
  588. *
  589. * @returns {Function}
  590. */
  591. export function resume() {
  592. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  593. const area = getRemoteConrolEventCaptureArea();
  594. const state = getState();
  595. const { controller } = state['features/remote-control'];
  596. const { controlled, isCapturingEvents } = controller;
  597. if (!isRemoteControlEnabled(state) || !area || !controlled || isCapturingEvents) {
  598. return;
  599. }
  600. logger.log('Resuming remote control controller.');
  601. area.mousemove((event: React.MouseEvent) => {
  602. dispatch(mouseMoved(event));
  603. });
  604. area.mousedown((event: React.MouseEvent) => dispatch(mouseClicked(EVENTS.mousedown, event)));
  605. area.mouseup((event: React.MouseEvent) => dispatch(mouseClicked(EVENTS.mouseup, event)));
  606. area.dblclick((event: React.MouseEvent) => dispatch(mouseClicked(EVENTS.mousedblclick, event)));
  607. area.contextmenu(() => false);
  608. area[0].onwheel = (event: any) => {
  609. event.preventDefault();
  610. event.stopPropagation();
  611. dispatch(mouseScrolled(event));
  612. return false;
  613. };
  614. $(window).keydown((event: React.KeyboardEvent) => dispatch(keyPressed(EVENTS.keydown, event)));
  615. $(window).keyup((event: React.KeyboardEvent) => dispatch(keyPressed(EVENTS.keyup, event)));
  616. dispatch({
  617. type: CAPTURE_EVENTS,
  618. isCapturingEvents: true
  619. });
  620. };
  621. }
  622. /**
  623. * Pauses the collecting of events and enables the keyboard shortcus. But
  624. * it doesn't removes any other listeners. Basically the remote control
  625. * session will be still active after the pause action, but no events from the
  626. * controller side will be captured and sent. You can resume the collecting
  627. * of the events with the resume action.
  628. *
  629. * @returns {Function}
  630. */
  631. export function pause() {
  632. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  633. const state = getState();
  634. const { controller } = state['features/remote-control'];
  635. const { controlled, isCapturingEvents } = controller;
  636. if (!isRemoteControlEnabled(state) || !controlled || !isCapturingEvents) {
  637. return;
  638. }
  639. logger.log('Pausing remote control controller.');
  640. const area = getRemoteConrolEventCaptureArea();
  641. if (area) {
  642. area.off('contextmenu');
  643. area.off('dblclick');
  644. area.off('mousedown');
  645. area.off('mousemove');
  646. area.off('mouseup');
  647. area[0].onwheel = undefined;
  648. }
  649. $(window).off('keydown');
  650. $(window).off('keyup');
  651. dispatch({
  652. type: CAPTURE_EVENTS,
  653. isCapturingEvents: false
  654. });
  655. };
  656. }