選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

RemoteControlParticipant.js 1.8KB

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