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.

RemoteControl.js 2.8KB

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