You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // @flow
  2. import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
  3. import JitsiMeetJS from '../base/lib-jitsi-meet';
  4. import { enableReceiver, stopReceiver } from './actions';
  5. import { REMOTE_CONTROL_MESSAGE_NAME, EVENTS } from './constants';
  6. import { keyboardEventToKey } from './keycodes';
  7. import logger from './logger';
  8. /**
  9. * Checks if the remote contrrol is enabled.
  10. *
  11. * @param {*} state - The redux state.
  12. * @returns {boolean} - True if the remote control is enabled and false otherwise.
  13. */
  14. export function isRemoteControlEnabled(state: Object) {
  15. return !state['features/base/config'].disableRemoteControl && JitsiMeetJS.isDesktopSharingEnabled();
  16. }
  17. /**
  18. * Sends remote control message to other participant through data channel.
  19. *
  20. * @param {JitsiConference} conference - The JitsiConference object.
  21. * @param {string} to - The participant who will receive the event.
  22. * @param {RemoteControlEvent} event - The remote control event.
  23. * @returns {boolean} - True if the message was sent successfully and false otherwise.
  24. */
  25. export function sendRemoteControlEndpointMessage(
  26. conference: Object,
  27. to: ?string,
  28. event: Object) {
  29. if (!to) {
  30. logger.warn('Remote control: Skip sending remote control event. Params:', to);
  31. return false;
  32. }
  33. try {
  34. conference.sendEndpointMessage(to, {
  35. name: REMOTE_CONTROL_MESSAGE_NAME,
  36. ...event
  37. });
  38. return true;
  39. } catch (error) {
  40. logger.error('Failed to send EndpointMessage via the datachannels', error);
  41. return false;
  42. }
  43. }
  44. /**
  45. * Handles remote control events from the external app. Currently only
  46. * events with type EVENTS.supported and EVENTS.stop are
  47. * supported.
  48. *
  49. * @param {RemoteControlEvent} event - The remote control event.
  50. * @param {Store} store - The redux store.
  51. * @returns {void}
  52. */
  53. export function onRemoteControlAPIEvent(event: Object, { getState, dispatch }: Object) {
  54. switch (event.type) {
  55. case EVENTS.supported:
  56. logger.log('Remote Control supported.');
  57. if (isRemoteControlEnabled(getState())) {
  58. dispatch(enableReceiver());
  59. } else {
  60. logger.log('Remote Control disabled.');
  61. }
  62. break;
  63. case EVENTS.stop: {
  64. dispatch(stopReceiver());
  65. break;
  66. }
  67. }
  68. }
  69. /**
  70. * Returns the area used for capturing mouse and key events.
  71. *
  72. * @returns {JQuery} - A JQuery selector.
  73. */
  74. export function getRemoteConrolEventCaptureArea() {
  75. return VideoLayout.getLargeVideoWrapper();
  76. }
  77. /**
  78. * Extract the keyboard key from the keyboard event.
  79. *
  80. * @param {KeyboardEvent} event - The event.
  81. * @returns {KEYS} The key that is pressed or undefined.
  82. */
  83. export function getKey(event: Object) {
  84. return keyboardEventToKey(event);
  85. }
  86. /**
  87. * Extract the modifiers from the keyboard event.
  88. *
  89. * @param {KeyboardEvent} event - The event.
  90. * @returns {Array} With possible values: "shift", "control", "alt", "command".
  91. */
  92. export function getModifiers(event: Object) {
  93. const modifiers = [];
  94. if (event.shiftKey) {
  95. modifiers.push('shift');
  96. }
  97. if (event.ctrlKey) {
  98. modifiers.push('control');
  99. }
  100. if (event.altKey) {
  101. modifiers.push('alt');
  102. }
  103. if (event.metaKey) {
  104. modifiers.push('command');
  105. }
  106. return modifiers;
  107. }