Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RemoteControl.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.
  40. * @param {object} event the remote control event
  41. */
  42. onRemoteControlAPIEvent(event) {
  43. switch(event.type) {
  44. case EVENT_TYPES.supported:
  45. this._onRemoteControlSupported();
  46. break;
  47. case EVENT_TYPES.permissions:
  48. this.receiver._onRemoteControlPermissionsEvent(
  49. event.userId, event.action);
  50. break;
  51. }
  52. }
  53. /**
  54. * Handles API event for support for executing remote control events into
  55. * the wrapper application.
  56. */
  57. _onRemoteControlSupported() {
  58. if(!config.disableRemoteControl) {
  59. this.enabled = true;
  60. if(this.initialized) {
  61. this.receiver.enable(true);
  62. }
  63. }
  64. }
  65. /**
  66. * Checks whether the passed user supports remote control or not
  67. * @param {JitsiParticipant} user the user to be tested
  68. * @returns {Promise<boolean>} the promise will be resolved with true if
  69. * the user supports remote control and with false if not.
  70. */
  71. checkUserRemoteControlSupport(user) {
  72. return user.getFeatures().then(features =>
  73. features.has(DISCO_REMOTE_CONTROL_FEATURE), () => false
  74. );
  75. }
  76. }
  77. export default new RemoteControl();