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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 {object} event the remote control event. The remote control event
  44. * has one mandatory property - type which is string from EVENT_TYPES enum
  45. * defined in /service/remotecontrol/constants. If the event type is
  46. * "supported" it won't have any other properties. If the event type is
  47. * "permissions" the method will expect also the following properties:
  48. * {string} userId - the user id of the participant that made the request
  49. * for permissions
  50. * {PERMISSIONS_ACTIONS} action the action related to the event.
  51. */
  52. onRemoteControlAPIEvent(event) {
  53. switch(event.type) {
  54. case EVENT_TYPES.supported:
  55. this._onRemoteControlSupported();
  56. break;
  57. case EVENT_TYPES.permissions:
  58. this.receiver._onRemoteControlPermissionsEvent(
  59. event.userId, event.action);
  60. break;
  61. }
  62. }
  63. /**
  64. * Handles API event for support for executing remote control events into
  65. * the wrapper application.
  66. */
  67. _onRemoteControlSupported() {
  68. logger.log("Remote Control supported.");
  69. if(!config.disableRemoteControl) {
  70. this.enabled = true;
  71. if(this.initialized) {
  72. this.receiver.enable(true);
  73. }
  74. } else {
  75. logger.log("Remote Control disabled.");
  76. }
  77. }
  78. /**
  79. * Checks whether the passed user supports remote control or not
  80. * @param {JitsiParticipant} user the user to be tested
  81. * @returns {Promise<boolean>} the promise will be resolved with true if
  82. * the user supports remote control and with false if not.
  83. */
  84. checkUserRemoteControlSupport(user) {
  85. return user.getFeatures().then(features =>
  86. features.has(DISCO_REMOTE_CONTROL_FEATURE), () => false
  87. );
  88. }
  89. }
  90. export default new RemoteControl();