瀏覽代碼

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,6 +135,9 @@ export default function JitsiConference(options) {
135 135
     };
136 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 141
     // Flag indicates if the 'onCallEnded' method was ever called on this
139 142
     // instance. Used to log extra analytics event for debugging purpose.
140 143
     // We need to know if the potential issue happened before or after
@@ -828,7 +831,16 @@ JitsiConference.prototype._fireMuteChangeEvent = function(track) {
828 831
         // unmute local user on server
829 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,6 +1423,33 @@ JitsiConference.prototype.onMemberLeft = function(jid) {
1411 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 1454
  * Method called on local MUC role change.
1416 1455
  * @param {string} role the name of new user's role as defined by XMPP MUC.

+ 12
- 10
JitsiConferenceEventManager.js 查看文件

@@ -87,20 +87,26 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
87 87
 
88 88
 
89 89
     chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
90
-        () => {
90
+        actor => {
91 91
             // TODO: Add a way to differentiate between commands which caused
92 92
             // us to mute and those that did not change our state (i.e. we were
93 93
             // already muted).
94 94
             Statistics.sendAnalytics(createRemotelyMutedEvent());
95 95
 
96
+            conference.mutedByFocusActor = actor;
97
+
96 98
             // set isMutedByFocus when setAudioMute Promise ends
97 99
             conference.rtc.setAudioMute(true).then(
98 100
                 () => {
99 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,12 +261,8 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
255 261
             node.value);
256 262
     });
257 263
 
258
-    this.chatRoomForwarder.forward(XMPPEvents.KICKED,
259
-        JitsiConferenceEvents.KICKED);
260 264
     chatRoom.addListener(XMPPEvents.KICKED,
261
-        () => {
262
-            conference.leave();
263
-        });
265
+        conference.onMemberKicked.bind(conference));
264 266
     chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
265 267
         conference.onSuspendDetected.bind(conference));
266 268
 

+ 10
- 0
JitsiConferenceEvents.js 查看文件

@@ -104,9 +104,17 @@ export const JVB121_STATUS = 'conference.jvb121Status';
104 104
 
105 105
 /**
106 106
  * You are kicked from the conference.
107
+ * @param {JitsiParticipant} the participant that initiated the kick.
107 108
  */
108 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 119
  * The Last N set is changed.
112 120
  *
@@ -252,6 +260,8 @@ export const TRACK_AUDIO_LEVEL_CHANGED = 'conference.audioLevelsChanged';
252 260
 
253 261
 /**
254 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 266
 export const TRACK_MUTE_CHANGED = 'conference.trackMuteChanged';
257 267
 

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

@@ -804,6 +804,31 @@ export default class ChatRoom extends Listenable {
804 804
                 .length;
805 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 832
         if (!isSelfPresence) {
808 833
             delete this.members[from];
809 834
             this.onParticipantLeft(from, false);
@@ -825,10 +850,6 @@ export default class ChatRoom extends Listenable {
825 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,7 +1361,7 @@ export default class ChatRoom extends Listenable {
1340 1361
         const mute = $(iq).find('mute');
1341 1362
 
1342 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 1365
         } else {
1345 1366
             // XXX Why do we support anything but muting? Why do we encode the
1346 1367
             // value in the text of the element? Why do we use a separate XML

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

@@ -102,7 +102,15 @@ const XMPPEvents = {
102 102
     // Event fired when we have failed to set initial offer
103 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 114
     KICKED: 'xmpp.kicked',
107 115
 
108 116
     // Designates an event indicating that our role in the XMPP MUC has changed.

Loading…
取消
儲存