瀏覽代碼

Notify for kick and mute (#915)

* Updates kicked event to inform local and remote kicks and who it affects

* Parses actor from MuteIQ and adds participant info to mute track event.

* Fixes emitting both events.

* Fixes comments.
dev1
Дамян Минков 6 年之前
父節點
當前提交
15e09476cd
沒有連結到貢獻者的電子郵件帳戶。
共有 5 個檔案被更改,包括 97 行新增17 行删除
  1. 40
    1
      JitsiConference.js
  2. 12
    10
      JitsiConferenceEventManager.js
  3. 10
    0
      JitsiConferenceEvents.js
  4. 26
    5
      modules/xmpp/ChatRoom.js
  5. 9
    1
      service/xmpp/XMPPEvents.js

+ 40
- 1
JitsiConference.js 查看文件

135
     };
135
     };
136
     this.isMutedByFocus = false;
136
     this.isMutedByFocus = false;
137
 
137
 
138
+    // when muted by focus we receive the jid of the initiator of the mute
139
+    this.mutedByFocusActor = null;
140
+
138
     // Flag indicates if the 'onCallEnded' method was ever called on this
141
     // Flag indicates if the 'onCallEnded' method was ever called on this
139
     // instance. Used to log extra analytics event for debugging purpose.
142
     // instance. Used to log extra analytics event for debugging purpose.
140
     // We need to know if the potential issue happened before or after
143
     // We need to know if the potential issue happened before or after
828
         // unmute local user on server
831
         // unmute local user on server
829
         this.room.muteParticipant(this.room.myroomjid, false);
832
         this.room.muteParticipant(this.room.myroomjid, false);
830
     }
833
     }
831
-    this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
834
+
835
+    let actorParticipant;
836
+
837
+    if (this.mutedByFocusActor) {
838
+        const actorId = Strophe.getResourceFromJid(this.mutedByFocusActor);
839
+
840
+        actorParticipant = this.participants[actorId];
841
+    }
842
+
843
+    this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track, actorParticipant);
832
 };
844
 };
833
 
845
 
834
 /**
846
 /**
1411
     this._maybeClearSITimeout();
1423
     this._maybeClearSITimeout();
1412
 };
1424
 };
1413
 
1425
 
1426
+/**
1427
+ * Designates an event indicating that we were kicked from the XMPP MUC.
1428
+ * @param {boolean} isSelfPresence - whether it is for local participant
1429
+ * or another participant.
1430
+ * @param {string} actorId - the id of the participant who was initiator
1431
+ * of the kick.
1432
+ * @param {string?} kickedParticipantId - when it is not a kick for local participant,
1433
+ * this is the id of the participant which was kicked.
1434
+ */
1435
+JitsiConference.prototype.onMemberKicked = function(isSelfPresence, actorId, kickedParticipantId) {
1436
+    const actorParticipant = this.participants[actorId];
1437
+
1438
+    if (isSelfPresence) {
1439
+        this.eventEmitter.emit(
1440
+            JitsiConferenceEvents.KICKED, actorParticipant);
1441
+
1442
+        this.leave();
1443
+
1444
+        return;
1445
+    }
1446
+
1447
+    const kickedParticipant = this.participants[kickedParticipantId];
1448
+
1449
+    this.eventEmitter.emit(
1450
+        JitsiConferenceEvents.PARTICIPANT_KICKED, actorParticipant, kickedParticipant);
1451
+};
1452
+
1414
 /**
1453
 /**
1415
  * Method called on local MUC role change.
1454
  * Method called on local MUC role change.
1416
  * @param {string} role the name of new user's role as defined by XMPP MUC.
1455
  * @param {string} role the name of new user's role as defined by XMPP MUC.

+ 12
- 10
JitsiConferenceEventManager.js 查看文件

87
 
87
 
88
 
88
 
89
     chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
89
     chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
90
-        () => {
90
+        actor => {
91
             // TODO: Add a way to differentiate between commands which caused
91
             // TODO: Add a way to differentiate between commands which caused
92
             // us to mute and those that did not change our state (i.e. we were
92
             // us to mute and those that did not change our state (i.e. we were
93
             // already muted).
93
             // already muted).
94
             Statistics.sendAnalytics(createRemotelyMutedEvent());
94
             Statistics.sendAnalytics(createRemotelyMutedEvent());
95
 
95
 
96
+            conference.mutedByFocusActor = actor;
97
+
96
             // set isMutedByFocus when setAudioMute Promise ends
98
             // set isMutedByFocus when setAudioMute Promise ends
97
             conference.rtc.setAudioMute(true).then(
99
             conference.rtc.setAudioMute(true).then(
98
                 () => {
100
                 () => {
99
                     conference.isMutedByFocus = true;
101
                     conference.isMutedByFocus = true;
100
-                },
101
-                () =>
102
-                    logger.warn(
103
-                        'Error while audio muting due to focus request'));
102
+                    conference.mutedByFocusActor = null;
103
+                })
104
+                .catch(
105
+                    error => {
106
+                        conference.mutedByFocusActor = null;
107
+                        logger.warn(
108
+                            'Error while audio muting due to focus request', error);
109
+                    });
104
         }
110
         }
105
     );
111
     );
106
 
112
 
255
             node.value);
261
             node.value);
256
     });
262
     });
257
 
263
 
258
-    this.chatRoomForwarder.forward(XMPPEvents.KICKED,
259
-        JitsiConferenceEvents.KICKED);
260
     chatRoom.addListener(XMPPEvents.KICKED,
264
     chatRoom.addListener(XMPPEvents.KICKED,
261
-        () => {
262
-            conference.leave();
263
-        });
265
+        conference.onMemberKicked.bind(conference));
264
     chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
266
     chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
265
         conference.onSuspendDetected.bind(conference));
267
         conference.onSuspendDetected.bind(conference));
266
 
268
 

+ 10
- 0
JitsiConferenceEvents.js 查看文件

104
 
104
 
105
 /**
105
 /**
106
  * You are kicked from the conference.
106
  * You are kicked from the conference.
107
+ * @param {JitsiParticipant} the participant that initiated the kick.
107
  */
108
  */
108
 export const KICKED = 'conference.kicked';
109
 export const KICKED = 'conference.kicked';
109
 
110
 
111
+/**
112
+ * Participant was kicked from the conference.
113
+ * @param {JitsiParticipant} the participant that initiated the kick.
114
+ * @param {JitsiParticipant} the participant that was kicked.
115
+ */
116
+export const PARTICIPANT_KICKED = 'conference.participant_kicked';
117
+
110
 /**
118
 /**
111
  * The Last N set is changed.
119
  * The Last N set is changed.
112
  *
120
  *
252
 
260
 
253
 /**
261
 /**
254
  * A media track ( attached to the conference) mute status was changed.
262
  * A media track ( attached to the conference) mute status was changed.
263
+ * @param {JitsiParticipant|null} the participant that initiated the mute
264
+ * if it is a remote mute.
255
  */
265
  */
256
 export const TRACK_MUTE_CHANGED = 'conference.trackMuteChanged';
266
 export const TRACK_MUTE_CHANGED = 'conference.trackMuteChanged';
257
 
267
 

+ 26
- 5
modules/xmpp/ChatRoom.js 查看文件

804
                 .length;
804
                 .length;
805
         const membersKeys = Object.keys(this.members);
805
         const membersKeys = Object.keys(this.members);
806
 
806
 
807
+        if (isKick) {
808
+            const actorSelect
809
+                = $(pres)
810
+                .find('>x[xmlns="http://jabber.org/protocol/muc#user"]>item>actor');
811
+
812
+            let actorNick;
813
+
814
+            if (actorSelect.length) {
815
+                actorNick = actorSelect.attr('nick');
816
+            }
817
+
818
+            // if no member is found this is the case we had kicked someone
819
+            // and we are not in the list of members
820
+            if (membersKeys.find(jid => Strophe.getResourceFromJid(jid) === actorNick)) {
821
+                // we first fire the kicked so we can show the participant
822
+                // who kicked, before notifying that participant left
823
+                // we fire kicked for us and for any participant kicked
824
+                this.eventEmitter.emit(
825
+                    XMPPEvents.KICKED,
826
+                    isSelfPresence,
827
+                    actorNick,
828
+                    Strophe.getResourceFromJid(from));
829
+            }
830
+        }
831
+
807
         if (!isSelfPresence) {
832
         if (!isSelfPresence) {
808
             delete this.members[from];
833
             delete this.members[from];
809
             this.onParticipantLeft(from, false);
834
             this.onParticipantLeft(from, false);
825
                 this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
850
                 this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
826
             }
851
             }
827
         }
852
         }
828
-
829
-        if (isKick && this.myroomjid === from) {
830
-            this.eventEmitter.emit(XMPPEvents.KICKED);
831
-        }
832
     }
853
     }
833
 
854
 
834
     /**
855
     /**
1340
         const mute = $(iq).find('mute');
1361
         const mute = $(iq).find('mute');
1341
 
1362
 
1342
         if (mute.length && mute.text() === 'true') {
1363
         if (mute.length && mute.text() === 'true') {
1343
-            this.eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS);
1364
+            this.eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS, mute.attr('actor'));
1344
         } else {
1365
         } else {
1345
             // XXX Why do we support anything but muting? Why do we encode the
1366
             // XXX Why do we support anything but muting? Why do we encode the
1346
             // value in the text of the element? Why do we use a separate XML
1367
             // value in the text of the element? Why do we use a separate XML

+ 9
- 1
service/xmpp/XMPPEvents.js 查看文件

102
     // Event fired when we have failed to set initial offer
102
     // Event fired when we have failed to set initial offer
103
     JINGLE_FATAL_ERROR: 'xmpp.jingle_fatal_error',
103
     JINGLE_FATAL_ERROR: 'xmpp.jingle_fatal_error',
104
 
104
 
105
-    // Designates an event indicating that we were kicked from the XMPP MUC.
105
+    /**
106
+     * Designates an event indicating that we were kicked from the XMPP MUC.
107
+     * @param {boolean} isSelfPresence - whether it is for local participant
108
+     * or another participant.
109
+     * @param {string} actorJid - the jid of the participant who was initator
110
+     * of the kick.
111
+     * @param {?string} participantJid - when it is not a kick for local participant,
112
+     * this is the jid of the participant which was kicked.
113
+     */
106
     KICKED: 'xmpp.kicked',
114
     KICKED: 'xmpp.kicked',
107
 
115
 
108
     // Designates an event indicating that our role in the XMPP MUC has changed.
116
     // Designates an event indicating that our role in the XMPP MUC has changed.

Loading…
取消
儲存