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

RemoteControlParticipant.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* @flow */
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import {
  4. REMOTE_CONTROL_EVENT_NAME
  5. } from '../../service/remotecontrol/Constants';
  6. const logger = getLogger(__filename);
  7. declare var APP: Object;
  8. /**
  9. * Implements common logic for Receiver class and Controller class.
  10. */
  11. export default class RemoteControlParticipant {
  12. _enabled: boolean;
  13. /**
  14. * Creates new instance.
  15. */
  16. constructor() {
  17. this._enabled = false;
  18. }
  19. /**
  20. * Enables / Disables the remote control.
  21. *
  22. * @param {boolean} enabled - The new state.
  23. * @returns {void}
  24. */
  25. enable(enabled: boolean) {
  26. this._enabled = enabled;
  27. }
  28. /**
  29. * Sends remote control event to other participant trough data channel.
  30. *
  31. * @param {string} to - The participant who will receive the event.
  32. * @param {RemoteControlEvent} event - The remote control event.
  33. * @param {Function} onDataChannelFail - Handler for data channel failure.
  34. * @returns {void}
  35. */
  36. sendRemoteControlEvent(
  37. to: ?string,
  38. event: Object,
  39. onDataChannelFail: ?Function) {
  40. if (!this._enabled || !to) {
  41. logger.warn(
  42. 'Remote control: Skip sending remote control event. Params:',
  43. this.enable,
  44. to);
  45. return;
  46. }
  47. try {
  48. APP.conference.sendEndpointMessage(to, {
  49. name: REMOTE_CONTROL_EVENT_NAME,
  50. ...event
  51. });
  52. } catch (e) {
  53. logger.error(
  54. 'Failed to send EndpointMessage via the datachannels',
  55. e);
  56. if (typeof onDataChannelFail === 'function') {
  57. onDataChannelFail(e);
  58. }
  59. }
  60. }
  61. }