|
@@ -21,7 +21,7 @@ export default class AVModeration {
|
21
|
21
|
|
22
|
22
|
this._mainRoom = room;
|
23
|
23
|
|
24
|
|
- this._momderationEnabledByType = {
|
|
24
|
+ this._moderationEnabledByType = {
|
25
|
25
|
[MediaType.AUDIO]: false,
|
26
|
26
|
[MediaType.VIDEO]: false
|
27
|
27
|
};
|
|
@@ -52,7 +52,7 @@ export default class AVModeration {
|
52
|
52
|
return;
|
53
|
53
|
}
|
54
|
54
|
|
55
|
|
- if (state === this._momderationEnabledByType[mediaType]) {
|
|
55
|
+ if (state === this._moderationEnabledByType[mediaType]) {
|
56
|
56
|
logger.warn(`Moderation already in state:${state} for mediaType:${mediaType}`);
|
57
|
57
|
|
58
|
58
|
return;
|
|
@@ -90,34 +90,65 @@ export default class AVModeration {
|
90
|
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
|
116
|
* Receives av_moderation parsed messages as json.
|
95
|
117
|
* @param obj the parsed json content of the message to process.
|
96
|
118
|
* @private
|
97
|
119
|
*/
|
98
|
120
|
_onMessage(obj) {
|
99
|
|
- const newWhitelists = obj.whitelists;
|
|
121
|
+ const { removed, mediaType: media, enabled, approved, actor, whitelists: newWhitelists } = obj;
|
100
|
122
|
|
101
|
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
|
134
|
newList.filter(x => !oldList.includes(x))
|
104
|
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
|
}
|