Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.js 24KB

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