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

AVModeration.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { getLogger } from 'jitsi-meet-logger';
  2. import { $msg } from 'strophe.js';
  3. import * as MediaType from '../../service/RTC/MediaType';
  4. import XMPPEvents from '../../service/xmpp/XMPPEvents';
  5. const logger = getLogger(__filename);
  6. /**
  7. * The AVModeration logic.
  8. */
  9. export default class AVModeration {
  10. /**
  11. * Constructs AV moderation room.
  12. *
  13. * @param {ChatRoom} room the main room.
  14. */
  15. constructor(room) {
  16. this._xmpp = room.xmpp;
  17. this._mainRoom = room;
  18. this._momderationEnabledByType = {
  19. [MediaType.AUDIO]: false,
  20. [MediaType.VIDEO]: false
  21. };
  22. this._whitelistAudio = [];
  23. this._whitelistVideo = [];
  24. this._xmpp.addListener(XMPPEvents.AV_MODERATION_RECEIVED, this._onMessage.bind(this));
  25. }
  26. /**
  27. * Whether AV moderation is supported on backend.
  28. *
  29. * @returns {boolean} whether AV moderation is supported on backend.
  30. */
  31. isSupported() {
  32. return Boolean(this._xmpp.avModerationComponentAddress);
  33. }
  34. /**
  35. * Enables or disables AV Moderation by sending a msg with command to the component.
  36. */
  37. enable(state, mediaType) {
  38. if (!this.isSupported() || !this._mainRoom.isModerator()) {
  39. logger.error(`Cannot enable:${state} AV moderation supported:${this.isSupported()},
  40. moderator:${this._mainRoom.isModerator()}`);
  41. return;
  42. }
  43. if (state === this._momderationEnabledByType[mediaType]) {
  44. logger.warn(`Moderation already in state:${state} for mediaType:${mediaType}`);
  45. return;
  46. }
  47. // send the enable/disable message
  48. const msg = $msg({ to: this._xmpp.avModerationComponentAddress });
  49. msg.c('av_moderation', {
  50. enable: state,
  51. mediaType
  52. }).up();
  53. this._xmpp.connection.send(msg);
  54. }
  55. /**
  56. * Approves that a participant can unmute by sending a msg with its jid to the component.
  57. */
  58. approve(mediaType, jid) {
  59. if (!this.isSupported() || !this._mainRoom.isModerator()) {
  60. logger.error(`Cannot approve in AV moderation supported:${this.isSupported()},
  61. moderator:${this._mainRoom.isModerator()}`);
  62. return;
  63. }
  64. // send a message to whitelist the jid and approve it to unmute
  65. const msg = $msg({ to: this._xmpp.avModerationComponentAddress });
  66. msg.c('av_moderation', {
  67. mediaType,
  68. jidToWhitelist: jid }).up();
  69. this._xmpp.connection.send(msg);
  70. }
  71. /**
  72. * Receives av_moderation parsed messages as json.
  73. * @param obj the parsed json content of the message to process.
  74. * @private
  75. */
  76. _onMessage(obj) {
  77. const newWhitelists = obj.whitelists;
  78. if (newWhitelists) {
  79. const fireEventApprovedJids = (mediaType, oldList, newList) => {
  80. newList.filter(x => !oldList.includes(x))
  81. .forEach(jid => this._xmpp.eventEmitter
  82. .emit(XMPPEvents.AV_MODERATION_PARTICIPANT_APPROVED, mediaType, jid));
  83. };
  84. if (newWhitelists[MediaType.AUDIO]) {
  85. fireEventApprovedJids(MediaType.AUDIO, this._whitelistAudio, newWhitelists[MediaType.AUDIO]);
  86. }
  87. if (newWhitelists[MediaType.VIDEO]) {
  88. fireEventApprovedJids(MediaType.VIDEO, this._whitelistVideo, newWhitelists[MediaType.VIDEO]);
  89. }
  90. } else if (this._momderationEnabledByType[obj.mediaType] !== obj.enabled) {
  91. this._momderationEnabledByType[obj.mediaType] = obj.enabled;
  92. this._xmpp.eventEmitter.emit(XMPPEvents.AV_MODERATION_CHANGED, obj.enabled, obj.mediaType, obj.actor);
  93. } else if (obj.approved) {
  94. this._xmpp.eventEmitter.emit(XMPPEvents.AV_MODERATION_APPROVED, obj.mediaType);
  95. }
  96. }
  97. }