瀏覽代碼

feat(av-moderation) Remove from moderation whitelist functionality (#1729)

* feat(av-moderation) Remove from moderation whitelist functionality

* Fix comment
dev1
robertpin 4 年之前
父節點
當前提交
0646bc3403
No account linked to committer's email address
共有 5 個文件被更改,包括 114 次插入17 次删除
  1. 25
    1
      JitsiConference.js
  2. 15
    0
      JitsiConferenceEventManager.js
  3. 17
    0
      JitsiConferenceEvents.js
  4. 47
    16
      modules/xmpp/AVModeration.js
  5. 10
    0
      service/xmpp/XMPPEvents.js

+ 25
- 1
JitsiConference.js 查看文件

3813
 
3813
 
3814
         this.room.getAVModeration().approve(mediaType, participant.getJid());
3814
         this.room.getAVModeration().approve(mediaType, participant.getJid());
3815
     } else {
3815
     } else {
3816
-        logger.warn(`AV moderation skipped , ${this.room ? '' : 'not in a room, '}${
3816
+        logger.warn(`AV moderation approve skipped , ${this.room ? '' : 'not in a room, '}${
3817
+            this.isModerator() ? '' : 'participant is not a moderator, '}${
3818
+            this.room && this.isModerator() ? 'wrong media type passed' : ''}`);
3819
+    }
3820
+};
3821
+
3822
+/**
3823
+ * Reject participant access to certain media, blocks unmuting audio or video.
3824
+ *
3825
+ * @param {MediaType} mediaType "audio" or "video"
3826
+ * @param id the id of the participant.
3827
+ */
3828
+JitsiConference.prototype.avModerationReject = function(mediaType, id) {
3829
+    if (this.room && this.isModerator()
3830
+        && (mediaType === MediaType.AUDIO || mediaType === MediaType.VIDEO)) {
3831
+
3832
+        const participant = this.getParticipantById(id);
3833
+
3834
+        if (!participant) {
3835
+            return;
3836
+        }
3837
+
3838
+        this.room.getAVModeration().reject(mediaType, participant.getJid());
3839
+    } else {
3840
+        logger.warn(`AV moderation reject skipped , ${this.room ? '' : 'not in a room, '}${
3817
             this.isModerator() ? '' : 'participant is not a moderator, '}${
3841
             this.isModerator() ? '' : 'participant is not a moderator, '}${
3818
             this.room && this.isModerator() ? 'wrong media type passed' : ''}`);
3842
             this.room && this.isModerator() ? 'wrong media type passed' : ''}`);
3819
     }
3843
     }

+ 15
- 0
JitsiConferenceEventManager.js 查看文件

720
                 });
720
                 });
721
             }
721
             }
722
         });
722
         });
723
+    this._addConferenceXMPPListener(XMPPEvents.AV_MODERATION_PARTICIPANT_REJECTED,
724
+        (mediaType, jid) => {
725
+            const participant = conference.getParticipantById(Strophe.getResourceFromJid(jid));
726
+
727
+            if (participant) {
728
+                conference.eventEmitter.emit(JitsiConferenceEvents.AV_MODERATION_PARTICIPANT_REJECTED, {
729
+                    participant,
730
+                    mediaType
731
+                });
732
+            }
733
+        });
723
     this._addConferenceXMPPListener(XMPPEvents.AV_MODERATION_APPROVED,
734
     this._addConferenceXMPPListener(XMPPEvents.AV_MODERATION_APPROVED,
724
         value => conference.eventEmitter.emit(JitsiConferenceEvents.AV_MODERATION_APPROVED, { mediaType: value }));
735
         value => conference.eventEmitter.emit(JitsiConferenceEvents.AV_MODERATION_APPROVED, { mediaType: value }));
736
+    this._addConferenceXMPPListener(XMPPEvents.AV_MODERATION_REJECTED,
737
+        value => {
738
+            conference.eventEmitter.emit(JitsiConferenceEvents.AV_MODERATION_REJECTED, { mediaType: value });
739
+        });
725
 };
740
 };
726
 
741
 
727
 /**
742
 /**

+ 17
- 0
JitsiConferenceEvents.js 查看文件

385
  */
385
  */
386
 export const AV_MODERATION_APPROVED = 'conference.av_moderation.approved';
386
 export const AV_MODERATION_APPROVED = 'conference.av_moderation.approved';
387
 
387
 
388
+/**
389
+ * The local participant was blocked to be able to unmute.
390
+ * @param {options} event - {
391
+ *     {MediaType} mediaType
392
+ * }.
393
+ */
394
+export const AV_MODERATION_REJECTED = 'conference.av_moderation.rejected';
395
+
388
 /**
396
 /**
389
  * AV Moderation was enabled/disabled. The actor is the participant that is currently in the meeting,
397
  * AV Moderation was enabled/disabled. The actor is the participant that is currently in the meeting,
390
  * or undefined if that participant has left the meeting.
398
  * or undefined if that participant has left the meeting.
405
  * }.
413
  * }.
406
  */
414
  */
407
 export const AV_MODERATION_PARTICIPANT_APPROVED = 'conference.av_moderation.participant.approved';
415
 export const AV_MODERATION_PARTICIPANT_APPROVED = 'conference.av_moderation.participant.approved';
416
+
417
+/**
418
+ * AV Moderation, report for user being blocked to unmute.
419
+ * @param {options} event - {
420
+ *     {JitsiParticipant} participant,
421
+ *     {MediaType} mediaType
422
+ * }.
423
+ */
424
+export const AV_MODERATION_PARTICIPANT_REJECTED = 'conference.av_moderation.participant.rejected';

+ 47
- 16
modules/xmpp/AVModeration.js 查看文件

21
 
21
 
22
         this._mainRoom = room;
22
         this._mainRoom = room;
23
 
23
 
24
-        this._momderationEnabledByType = {
24
+        this._moderationEnabledByType = {
25
             [MediaType.AUDIO]: false,
25
             [MediaType.AUDIO]: false,
26
             [MediaType.VIDEO]: false
26
             [MediaType.VIDEO]: false
27
         };
27
         };
52
             return;
52
             return;
53
         }
53
         }
54
 
54
 
55
-        if (state === this._momderationEnabledByType[mediaType]) {
55
+        if (state === this._moderationEnabledByType[mediaType]) {
56
             logger.warn(`Moderation already in state:${state} for mediaType:${mediaType}`);
56
             logger.warn(`Moderation already in state:${state} for mediaType:${mediaType}`);
57
 
57
 
58
             return;
58
             return;
90
         this._xmpp.connection.send(msg);
90
         this._xmpp.connection.send(msg);
91
     }
91
     }
92
 
92
 
93
+    /**
94
+     * Rejects that a participant can unmute by sending a msg with its jid to the component.
95
+     */
96
+    reject(mediaType, jid) {
97
+        if (!this.isSupported() || !this._mainRoom.isModerator()) {
98
+            logger.error(`Cannot reject in AV moderation supported:${this.isSupported()},
99
+                moderator:${this._mainRoom.isModerator()}`);
100
+
101
+            return;
102
+        }
103
+
104
+        // send a message to remove from whitelist the jid and reject it to unmute
105
+        const msg = $msg({ to: this._xmpp.avModerationComponentAddress });
106
+
107
+        msg.c('av_moderation', {
108
+            mediaType,
109
+            jidToBlacklist: jid
110
+        }).up();
111
+
112
+        this._xmpp.connection.send(msg);
113
+    }
114
+
93
     /**
115
     /**
94
      * Receives av_moderation parsed messages as json.
116
      * Receives av_moderation parsed messages as json.
95
      * @param obj the parsed json content of the message to process.
117
      * @param obj the parsed json content of the message to process.
96
      * @private
118
      * @private
97
      */
119
      */
98
     _onMessage(obj) {
120
     _onMessage(obj) {
99
-        const newWhitelists = obj.whitelists;
121
+        const { removed, mediaType: media, enabled, approved, actor, whitelists: newWhitelists } = obj;
100
 
122
 
101
         if (newWhitelists) {
123
         if (newWhitelists) {
102
-            const fireEventApprovedJids = (mediaType, oldList, newList) => {
124
+            const oldList = media === MediaType.AUDIO
125
+                ? this._whitelistAudio
126
+                : this._whitelistVideo;
127
+            const newList = Array.isArray(newWhitelists[media]) ? newWhitelists[media] : [];
128
+
129
+            if (removed) {
130
+                oldList.filter(x => !newList.includes(x))
131
+                    .forEach(jid => this._xmpp.eventEmitter
132
+                        .emit(XMPPEvents.AV_MODERATION_PARTICIPANT_REJECTED, media, jid));
133
+            } else {
103
                 newList.filter(x => !oldList.includes(x))
134
                 newList.filter(x => !oldList.includes(x))
104
                     .forEach(jid => this._xmpp.eventEmitter
135
                     .forEach(jid => this._xmpp.eventEmitter
105
-                        .emit(XMPPEvents.AV_MODERATION_PARTICIPANT_APPROVED, mediaType, jid));
106
-            };
107
-
108
-            if (Array.isArray(newWhitelists[MediaType.AUDIO])) {
109
-                fireEventApprovedJids(MediaType.AUDIO, this._whitelistAudio, newWhitelists[MediaType.AUDIO]);
136
+                        .emit(XMPPEvents.AV_MODERATION_PARTICIPANT_APPROVED, media, jid));
110
             }
137
             }
111
 
138
 
112
-            if (Array.isArray(newWhitelists[MediaType.VIDEO])) {
113
-                fireEventApprovedJids(MediaType.VIDEO, this._whitelistVideo, newWhitelists[MediaType.VIDEO]);
139
+            if (media === MediaType.AUDIO) {
140
+                this._whitelistAudio = newList;
141
+            } else {
142
+                this._whitelistVideo = newList;
114
             }
143
             }
115
-        } else if (obj.enabled !== undefined && this._momderationEnabledByType[obj.mediaType] !== obj.enabled) {
116
-            this._momderationEnabledByType[obj.mediaType] = obj.enabled;
144
+        } else if (enabled !== undefined && this._moderationEnabledByType[media] !== enabled) {
145
+            this._moderationEnabledByType[media] = enabled;
146
+
147
+            this._xmpp.eventEmitter.emit(XMPPEvents.AV_MODERATION_CHANGED, enabled, media, actor);
148
+        } else if (approved) {
149
+            const event = removed ? XMPPEvents.AV_MODERATION_REJECTED : XMPPEvents.AV_MODERATION_APPROVED;
117
 
150
 
118
-            this._xmpp.eventEmitter.emit(XMPPEvents.AV_MODERATION_CHANGED, obj.enabled, obj.mediaType, obj.actor);
119
-        } else if (obj.approved) {
120
-            this._xmpp.eventEmitter.emit(XMPPEvents.AV_MODERATION_APPROVED, obj.mediaType);
151
+            this._xmpp.eventEmitter.emit(event, media);
121
         }
152
         }
122
     }
153
     }
123
 }
154
 }

+ 10
- 0
service/xmpp/XMPPEvents.js 查看文件

253
      */
253
      */
254
     AV_MODERATION_APPROVED: 'xmpp.av_moderation.approved',
254
     AV_MODERATION_APPROVED: 'xmpp.av_moderation.approved',
255
 
255
 
256
+    /**
257
+    * Event fired when we receive a message for AV moderation rejected for the local participant.
258
+    */
259
+    AV_MODERATION_REJECTED: 'xmpp.av_moderation.rejected',
260
+
256
     /**
261
     /**
257
      * Event fired when we receive a message for AV moderation.
262
      * Event fired when we receive a message for AV moderation.
258
      */
263
      */
268
      */
273
      */
269
     AV_MODERATION_PARTICIPANT_APPROVED: 'xmpp.av_moderation.participant.approved',
274
     AV_MODERATION_PARTICIPANT_APPROVED: 'xmpp.av_moderation.participant.approved',
270
 
275
 
276
+    /**
277
+     * Event fired when we receive message that a new jid was approved.
278
+     */
279
+    AV_MODERATION_PARTICIPANT_REJECTED: 'xmpp.av_moderation.participant.rejected',
280
+
271
     // Designates an event indicating that we should join the conference with
281
     // Designates an event indicating that we should join the conference with
272
     // audio and/or video muted.
282
     // audio and/or video muted.
273
     START_MUTED_FROM_FOCUS: 'xmpp.start_muted_from_focus',
283
     START_MUTED_FROM_FOCUS: 'xmpp.start_muted_from_focus',

Loading…
取消
儲存