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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* global APP, config */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import Controller from "./Controller";
  4. import Receiver from "./Receiver";
  5. import {EVENT_TYPES, DISCO_REMOTE_CONTROL_FEATURE}
  6. from "../../service/remotecontrol/Constants";
  7. /**
  8. * Implements the remote control functionality.
  9. */
  10. class RemoteControl {
  11. /**
  12. * Constructs new instance. Creates controller and receiver properties.
  13. * @constructor
  14. */
  15. constructor() {
  16. this.controller = new Controller();
  17. this.receiver = new Receiver();
  18. this.enabled = false;
  19. this.initialized = false;
  20. }
  21. /**
  22. * Initializes the remote control - checks if the remote control should be
  23. * enabled or not, initializes the API module.
  24. */
  25. init() {
  26. if(config.disableRemoteControl || this.initialized
  27. || !APP.conference.isDesktopSharingEnabled) {
  28. return;
  29. }
  30. logger.log("Initializing remote control.");
  31. this.initialized = true;
  32. APP.API.init({
  33. forceEnable: true,
  34. });
  35. this.controller.enable(true);
  36. if(this.enabled) { // supported message came before init.
  37. this._onRemoteControlSupported();
  38. }
  39. }
  40. /**
  41. * Handles remote control events from the API module. Currently only events
  42. * with type = EVENT_TYPES.supported or EVENT_TYPES.permissions
  43. * @param {RemoteControlEvent} event the remote control event.
  44. */
  45. onRemoteControlAPIEvent(event) {
  46. switch(event.type) {
  47. case EVENT_TYPES.supported:
  48. this._onRemoteControlSupported();
  49. break;
  50. case EVENT_TYPES.permissions:
  51. this.receiver._onRemoteControlPermissionsEvent(
  52. event.userId, event.action);
  53. break;
  54. }
  55. }
  56. /**
  57. * Handles API event for support for executing remote control events into
  58. * the wrapper application.
  59. */
  60. _onRemoteControlSupported() {
  61. logger.log("Remote Control supported.");
  62. if(!config.disableRemoteControl) {
  63. this.enabled = true;
  64. if(this.initialized) {
  65. this.receiver.enable(true);
  66. }
  67. } else {
  68. logger.log("Remote Control disabled.");
  69. }
  70. }
  71. /**
  72. * Checks whether the passed user supports remote control or not
  73. * @param {JitsiParticipant} user the user to be tested
  74. * @returns {Promise<boolean>} the promise will be resolved with true if
  75. * the user supports remote control and with false if not.
  76. */
  77. checkUserRemoteControlSupport(user) {
  78. return user.getFeatures().then(features =>
  79. features.has(DISCO_REMOTE_CONTROL_FEATURE), () => false
  80. );
  81. }
  82. }
  83. export default new RemoteControl();