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

RemoteControl.js 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* global APP, config */
  2. import Controller from "./Controller";
  3. import Receiver from "./Receiver";
  4. import {EVENT_TYPES, DISCO_REMOTE_CONTROL_FEATURE}
  5. from "../../service/remotecontrol/Constants";
  6. /**
  7. * Implements the remote control functionality.
  8. */
  9. class RemoteControl {
  10. /**
  11. * Constructs new instance. Creates controller and receiver properties.
  12. * @constructor
  13. */
  14. constructor() {
  15. this.controller = new Controller();
  16. this.receiver = new Receiver();
  17. this.enabled = false;
  18. this.initialized = false;
  19. }
  20. /**
  21. * Initializes the remote control - checks if the remote control should be
  22. * enabled or not, initializes the API module.
  23. */
  24. init() {
  25. if(config.disableRemoteControl || this.initialized
  26. || !APP.conference.isDesktopSharingEnabled) {
  27. return;
  28. }
  29. this.initialized = true;
  30. APP.API.init({
  31. forceEnable: true,
  32. });
  33. this.controller.enable(true);
  34. if(this.enabled) { // supported message came before init.
  35. this._onRemoteControlSupported();
  36. }
  37. }
  38. /**
  39. * Handles remote control events from the API module. Currently only events
  40. * with type = EVENT_TYPES.supported or EVENT_TYPES.permissions
  41. * @param {object} event the remote control event. The remote control event
  42. * has one mandatory property - type which is string from EVENT_TYPES enum
  43. * defined in /service/remotecontrol/constants. If the event type is
  44. * "supported" it won't have any other properties. If the event type is
  45. * "permissions" the method will expect also the following properties:
  46. * {string} userId - the user id of the participant that made the request
  47. * for permissions
  48. * {PERMISSIONS_ACTIONS} action the action related to the event.
  49. */
  50. onRemoteControlAPIEvent(event) {
  51. switch(event.type) {
  52. case EVENT_TYPES.supported:
  53. this._onRemoteControlSupported();
  54. break;
  55. case EVENT_TYPES.permissions:
  56. this.receiver._onRemoteControlPermissionsEvent(
  57. event.userId, event.action);
  58. break;
  59. }
  60. }
  61. /**
  62. * Handles API event for support for executing remote control events into
  63. * the wrapper application.
  64. */
  65. _onRemoteControlSupported() {
  66. if(!config.disableRemoteControl) {
  67. this.enabled = true;
  68. if(this.initialized) {
  69. this.receiver.enable(true);
  70. }
  71. }
  72. }
  73. /**
  74. * Checks whether the passed user supports remote control or not
  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) {
  80. return user.getFeatures().then(features =>
  81. features.has(DISCO_REMOTE_CONTROL_FEATURE), () => false
  82. );
  83. }
  84. }
  85. export default new RemoteControl();