Browse Source

feat(JitsiConference) add ability to set the leave reason

Co-authored-by: Дамян Минков <damencho@jitsi.org>
dev1
Saúl Ibarra Corretgé 2 years ago
parent
commit
726e04f5f2
No account linked to committer's email address

+ 5
- 4
JitsiConference.js View File

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

+ 22
- 8
modules/xmpp/ChatRoom.js View File

259
      * Sends the presence unavailable, signaling the server
259
      * Sends the presence unavailable, signaling the server
260
      * we want to leave the room.
260
      * we want to leave the room.
261
      */
261
      */
262
-    doLeave() {
262
+    doLeave(reason) {
263
         logger.log('do leave', this.myroomjid);
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
         this.presMap.length = 0;
273
         this.presMap.length = 0;
268
 
274
 
937
      * @param jid the jid of the participant that leaves
943
      * @param jid the jid of the participant that leaves
938
      * @param skipEvents optional params to skip any events, including check
944
      * @param skipEvents optional params to skip any events, including check
939
      * whether this is the focus that left
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
         delete this.lastPresences[jid];
949
         delete this.lastPresences[jid];
943
 
950
 
944
         if (skipEvents) {
951
         if (skipEvents) {
945
             return;
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
         this.moderator.onMucMemberLeft(jid);
957
         this.moderator.onMucMemberLeft(jid);
951
     }
958
     }
1047
                 this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
1054
                 this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
1048
             }
1055
             }
1049
         } else {
1056
         } else {
1057
+            const reasonSelect = $(pres).find('>status');
1058
+            let reason;
1059
+
1060
+            if (reasonSelect.length) {
1061
+                reason = reasonSelect.text();
1062
+            }
1063
+
1050
             delete this.members[from];
1064
             delete this.members[from];
1051
-            this.onParticipantLeft(from, false);
1065
+            this.onParticipantLeft(from, false, reason);
1052
         }
1066
         }
1053
     }
1067
     }
1054
 
1068
 
1829
      * less than 5s after sending presence unavailable. Otherwise the promise is
1843
      * less than 5s after sending presence unavailable. Otherwise the promise is
1830
      * rejected.
1844
      * rejected.
1831
      */
1845
      */
1832
-    leave() {
1846
+    leave(reason) {
1833
         this.avModeration.dispose();
1847
         this.avModeration.dispose();
1834
         this.breakoutRooms.dispose();
1848
         this.breakoutRooms.dispose();
1835
 
1849
 
1856
 
1870
 
1857
             this.clean();
1871
             this.clean();
1858
             this.eventEmitter.on(XMPPEvents.MUC_LEFT, onMucLeft);
1872
             this.eventEmitter.on(XMPPEvents.MUC_LEFT, onMucLeft);
1859
-            this.doLeave();
1873
+            this.doLeave(reason);
1860
         }));
1874
         }));
1861
 
1875
 
1862
         return Promise.allSettled(promises);
1876
         return Promise.allSettled(promises);

+ 3
- 2
types/auto/JitsiConference.d.ts View File

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

+ 4
- 3
types/auto/modules/xmpp/ChatRoom.d.ts View File

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

Loading…
Cancel
Save