Parcourir la source

feat(JitsiConference) add ability to set the leave reason

Co-authored-by: Дамян Минков <damencho@jitsi.org>
dev1
Saúl Ibarra Corretgé il y a 2 ans
Parent
révision
726e04f5f2
Aucun compte lié à l'adresse e-mail de l'auteur

+ 5
- 4
JitsiConference.js Voir le fichier

@@ -627,9 +627,10 @@ JitsiConference.prototype.isP2PTestModeEnabled = function() {
627 627
 
628 628
 /**
629 629
  * Leaves the conference.
630
+ * @param reason {string|undefined} The reason for leaving the conference.
630 631
  * @returns {Promise}
631 632
  */
632
-JitsiConference.prototype.leave = async function() {
633
+JitsiConference.prototype.leave = async function(reason) {
633 634
     if (this.participantConnectionStatus) {
634 635
         this.participantConnectionStatus.dispose();
635 636
         this.participantConnectionStatus = null;
@@ -710,7 +711,7 @@ JitsiConference.prototype.leave = async function() {
710 711
     let leaveError;
711 712
 
712 713
     try {
713
-        await room.leave();
714
+        await room.leave(reason);
714 715
     } catch (err) {
715 716
         leaveError = err;
716 717
 
@@ -1946,7 +1947,7 @@ JitsiConference.prototype._onMemberBotTypeChanged = function(jid, botType) {
1946 1947
     }
1947 1948
 };
1948 1949
 
1949
-JitsiConference.prototype.onMemberLeft = function(jid) {
1950
+JitsiConference.prototype.onMemberLeft = function(jid, reason) {
1950 1951
     const id = Strophe.getResourceFromJid(jid);
1951 1952
 
1952 1953
     if (id === 'focus' || this.myUserId() === id) {
@@ -1973,7 +1974,7 @@ JitsiConference.prototype.onMemberLeft = function(jid) {
1973 1974
 
1974 1975
     if (participant) {
1975 1976
         delete this.participants[id];
1976
-        this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
1977
+        this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant, reason);
1977 1978
     }
1978 1979
 
1979 1980
     if (this.room !== null) { // Skip if we have left the room already.

+ 22
- 8
modules/xmpp/ChatRoom.js Voir le fichier

@@ -259,10 +259,16 @@ export default class ChatRoom extends Listenable {
259 259
      * Sends the presence unavailable, signaling the server
260 260
      * we want to leave the room.
261 261
      */
262
-    doLeave() {
262
+    doLeave(reason) {
263 263
         logger.log('do leave', this.myroomjid);
264
-        const pres = $pres({ to: this.myroomjid,
265
-            type: 'unavailable' });
264
+        const pres = $pres({
265
+            to: this.myroomjid,
266
+            type: 'unavailable'
267
+        });
268
+
269
+        if (reason) {
270
+            pres.c('status').t(reason).up();
271
+        }
266 272
 
267 273
         this.presMap.length = 0;
268 274
 
@@ -937,15 +943,16 @@ export default class ChatRoom extends Listenable {
937 943
      * @param jid the jid of the participant that leaves
938 944
      * @param skipEvents optional params to skip any events, including check
939 945
      * whether this is the focus that left
946
+     * @param reason the reason for leaving (optional).
940 947
      */
941
-    onParticipantLeft(jid, skipEvents) {
948
+    onParticipantLeft(jid, skipEvents, reason) {
942 949
         delete this.lastPresences[jid];
943 950
 
944 951
         if (skipEvents) {
945 952
             return;
946 953
         }
947 954
 
948
-        this.eventEmitter.emit(XMPPEvents.MUC_MEMBER_LEFT, jid);
955
+        this.eventEmitter.emit(XMPPEvents.MUC_MEMBER_LEFT, jid, reason);
949 956
 
950 957
         this.moderator.onMucMemberLeft(jid);
951 958
     }
@@ -1047,8 +1054,15 @@ export default class ChatRoom extends Listenable {
1047 1054
                 this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
1048 1055
             }
1049 1056
         } else {
1057
+            const reasonSelect = $(pres).find('>status');
1058
+            let reason;
1059
+
1060
+            if (reasonSelect.length) {
1061
+                reason = reasonSelect.text();
1062
+            }
1063
+
1050 1064
             delete this.members[from];
1051
-            this.onParticipantLeft(from, false);
1065
+            this.onParticipantLeft(from, false, reason);
1052 1066
         }
1053 1067
     }
1054 1068
 
@@ -1829,7 +1843,7 @@ export default class ChatRoom extends Listenable {
1829 1843
      * less than 5s after sending presence unavailable. Otherwise the promise is
1830 1844
      * rejected.
1831 1845
      */
1832
-    leave() {
1846
+    leave(reason) {
1833 1847
         this.avModeration.dispose();
1834 1848
         this.breakoutRooms.dispose();
1835 1849
 
@@ -1856,7 +1870,7 @@ export default class ChatRoom extends Listenable {
1856 1870
 
1857 1871
             this.clean();
1858 1872
             this.eventEmitter.on(XMPPEvents.MUC_LEFT, onMucLeft);
1859
-            this.doLeave();
1873
+            this.doLeave(reason);
1860 1874
         }));
1861 1875
 
1862 1876
         return Promise.allSettled(promises);

+ 3
- 2
types/auto/JitsiConference.d.ts Voir le fichier

@@ -252,9 +252,10 @@ declare class JitsiConference {
252 252
     isP2PTestModeEnabled(): boolean;
253 253
     /**
254 254
      * Leaves the conference.
255
+     * @param reason {string|undefined} The reason for leaving the conference.
255 256
      * @returns {Promise}
256 257
      */
257
-    leave(): Promise<any>;
258
+    leave(reason: string | undefined): Promise<any>;
258 259
     /**
259 260
      * Returns the currently active media session if any.
260 261
      *
@@ -622,7 +623,7 @@ declare class JitsiConference {
622 623
     private _onMucJoined;
623 624
     private _updateFeatures;
624 625
     private _onMemberBotTypeChanged;
625
-    onMemberLeft(jid: any): void;
626
+    onMemberLeft(jid: any, reason: any): void;
626 627
     /**
627 628
      * Designates an event indicating that we were kicked from the XMPP MUC.
628 629
      * @param {boolean} isSelfPresence - whether it is for local participant

+ 4
- 3
types/auto/modules/xmpp/ChatRoom.d.ts Voir le fichier

@@ -80,7 +80,7 @@ export default class ChatRoom extends Listenable {
80 80
      * Sends the presence unavailable, signaling the server
81 81
      * we want to leave the room.
82 82
      */
83
-    doLeave(): void;
83
+    doLeave(reason: any): void;
84 84
     /**
85 85
      *
86 86
      */
@@ -163,8 +163,9 @@ export default class ChatRoom extends Listenable {
163 163
      * @param jid the jid of the participant that leaves
164 164
      * @param skipEvents optional params to skip any events, including check
165 165
      * whether this is the focus that left
166
+     * @param reason the reason for leaving (optional).
166 167
      */
167
-    onParticipantLeft(jid: any, skipEvents: any): void;
168
+    onParticipantLeft(jid: any, skipEvents: any, reason: any): void;
168 169
     /**
169 170
      *
170 171
      * @param pres
@@ -367,7 +368,7 @@ export default class ChatRoom extends Listenable {
367 368
      * less than 5s after sending presence unavailable. Otherwise the promise is
368 369
      * rejected.
369 370
      */
370
-    leave(): Promise<any>;
371
+    leave(reason: any): Promise<any>;
371 372
 }
372 373
 import Listenable from "../util/Listenable";
373 374
 import XmppConnection from "./XmppConnection";

Chargement…
Annuler
Enregistrer