您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RemoteControl.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* @flow */
  2. import EventEmitter from 'events';
  3. import { getLogger } from 'jitsi-meet-logger';
  4. import JitsiMeetJS from '../../react/features/base/lib-jitsi-meet';
  5. import { DISCO_REMOTE_CONTROL_FEATURE }
  6. from '../../service/remotecontrol/Constants';
  7. import * as RemoteControlEvents
  8. from '../../service/remotecontrol/RemoteControlEvents';
  9. import Controller from './Controller';
  10. import Receiver from './Receiver';
  11. const logger = getLogger(__filename);
  12. declare var APP: Object;
  13. declare var config: Object;
  14. /**
  15. * Implements the remote control functionality.
  16. */
  17. class RemoteControl extends EventEmitter {
  18. _active: boolean;
  19. _initialized: boolean;
  20. controller: Controller;
  21. receiver: Receiver;
  22. /**
  23. * Constructs new instance. Creates controller and receiver properties.
  24. */
  25. constructor() {
  26. super();
  27. this.controller = new Controller();
  28. this._active = false;
  29. this._initialized = false;
  30. this.controller.on(RemoteControlEvents.ACTIVE_CHANGED, active => {
  31. this.active = active;
  32. });
  33. }
  34. /**
  35. * Sets the remote control session active status.
  36. *
  37. * @param {boolean} isActive - True - if the controller or the receiver is
  38. * currently in remote control session and false otherwise.
  39. * @returns {void}
  40. */
  41. set active(isActive: boolean) {
  42. this._active = isActive;
  43. this.emit(RemoteControlEvents.ACTIVE_CHANGED, isActive);
  44. }
  45. /**
  46. * Returns the remote control session active status.
  47. *
  48. * @returns {boolean} - True - if the controller or the receiver is
  49. * currently in remote control session and false otherwise.
  50. */
  51. get active(): boolean {
  52. return this._active;
  53. }
  54. /**
  55. * Initializes the remote control - checks if the remote control should be
  56. * enabled or not.
  57. *
  58. * @returns {void}
  59. */
  60. init() {
  61. if (config.disableRemoteControl || this._initialized || !JitsiMeetJS.isDesktopSharingEnabled()) {
  62. return;
  63. }
  64. logger.log('Initializing remote control.');
  65. this._initialized = true;
  66. this.controller.enable(true);
  67. this.receiver = new Receiver();
  68. this.receiver.on(RemoteControlEvents.ACTIVE_CHANGED, active => {
  69. this.active = active;
  70. });
  71. }
  72. /**
  73. * Checks whether the passed user supports remote control or not.
  74. *
  75. * @param {JitsiParticipant} user - The user to be tested.
  76. * @returns {Promise<boolean>} The promise will be resolved with true if
  77. * the user supports remote control and with false if not.
  78. */
  79. checkUserRemoteControlSupport(user: Object) {
  80. return user.getFeatures()
  81. .then(features => features.has(DISCO_REMOTE_CONTROL_FEATURE));
  82. }
  83. }
  84. export default new RemoteControl();