Sfoglia il codice sorgente

fix: Always set recroding status=on when a jibri is present (#2132)

dev1
bgrozev 3 anni fa
parent
commit
3f0a4b7bdf
Nessun account collegato all'indirizzo email del committer
2 ha cambiato i file con 82 aggiunte e 3 eliminazioni
  1. 34
    1
      modules/recording/JibriSession.js
  2. 48
    2
      modules/recording/RecordingManager.js

+ 34
- 1
modules/recording/JibriSession.js Vedi File

@@ -14,6 +14,8 @@ export default class JibriSession {
14 14
     constructor(options = {}) {
15 15
         this._connection = options.connection;
16 16
         this._mode = options.mode;
17
+        this._jibriJid = null;
18
+        this._statusFromJicofo = '';
17 19
 
18 20
         this._setSessionID(options.sessionID);
19 21
         this.setStatus(options.status);
@@ -61,7 +63,19 @@ export default class JibriSession {
61 63
      * @returns {string|undefined}
62 64
      */
63 65
     getStatus() {
64
-        return this._status;
66
+        // If _status is not set fallback to the status reported by jicofo.
67
+        if (this._status) {
68
+            return this._status;
69
+        }
70
+
71
+        return this._statusFromJicofo;
72
+    }
73
+
74
+    /**
75
+     * @returns {string|undefined} the JID of jibri associated with this session.
76
+     */
77
+    getJibriJid() {
78
+        return this._jibriJid;
65 79
     }
66 80
 
67 81
     /**
@@ -114,6 +128,25 @@ export default class JibriSession {
114 128
         this._status = status;
115 129
     }
116 130
 
131
+    /**
132
+     * Set the session status reported by jicofo. If a jibri is present in the room,
133
+     * the status is always 'on'. Otherwise, we fallback to the status reported by jicofo.
134
+     *
135
+     * @param {string} status
136
+     */
137
+    setStatusFromJicofo(status) {
138
+        this._statusFromJicofo = status;
139
+    }
140
+
141
+    /**
142
+     * Set the JID of the jibri associated with this session.
143
+     *
144
+     * @param {*} jibriJid
145
+     */
146
+    setJibriJid(jibriJid) {
147
+        this._jibriJid = jibriJid;
148
+    }
149
+
117 150
     /**
118 151
      * Sets the participant that started the session.
119 152
      * @param {JitsiParticipant | string} participant - The participant or resource id

+ 48
- 2
modules/recording/RecordingManager.js Vedi File

@@ -29,8 +29,12 @@ class RecordingManager {
29 29
 
30 30
         this.onPresence = this.onPresence.bind(this);
31 31
 
32
+        this.onMemberLeft = this.onMemberLeft.bind(this);
33
+
32 34
         this._chatRoom.eventEmitter.addListener(
33 35
             XMPPEvents.PRESENCE_RECEIVED, this.onPresence);
36
+        this._chatRoom.eventEmitter.addListener(
37
+            XMPPEvents.MUC_MEMBER_LEFT, this.onMemberLeft);
34 38
     }
35 39
 
36 40
     /**
@@ -43,6 +47,24 @@ class RecordingManager {
43 47
         return this._sessions[sessionID];
44 48
     }
45 49
 
50
+    /**
51
+     * Find a session with a specific jibri JID.
52
+     *
53
+     * @param {string} jibriJid the JID to search for.
54
+     * @returns
55
+     */
56
+    getSessionByJibriJid(jibriJid) {
57
+        let s;
58
+
59
+        Object.values(this._sessions).forEach(session => {
60
+            if (session.getJibriJid() === jibriJid) {
61
+                s = session;
62
+            }
63
+        });
64
+
65
+        return s;
66
+    }
67
+
46 68
     /**
47 69
      * Callback to invoke to parse through a presence update to find recording
48 70
      * related updates (from Jibri participant doing the recording and the
@@ -63,6 +85,27 @@ class RecordingManager {
63 85
         }
64 86
     }
65 87
 
88
+    /**
89
+     * Handle a participant leaving the room.
90
+     * @param {string} jid the JID of the participant that left.
91
+     */
92
+    onMemberLeft(jid) {
93
+        const session = this.getSessionByJibriJid(jid);
94
+
95
+        if (session) {
96
+
97
+            const prevStatus = session.getStatus();
98
+
99
+            // Setting to ''
100
+            session.setStatus('');
101
+            session.setJibriJid(null);
102
+
103
+            if (session.getStatus() !== prevStatus) {
104
+                this._emitSessionUpdate(session);
105
+            }
106
+        }
107
+    }
108
+
66 109
     /**
67 110
      * Start a recording session.
68 111
      *
@@ -221,7 +264,7 @@ class RecordingManager {
221 264
             session = this._createSession(sessionID, status, recordingMode);
222 265
         }
223 266
 
224
-        session.setStatus(status);
267
+        session.setStatusFromJicofo(status);
225 268
 
226 269
         if (error) {
227 270
             session.setError(error);
@@ -251,9 +294,12 @@ class RecordingManager {
251 294
         let session = this.getSession(sessionID);
252 295
 
253 296
         if (!session) {
254
-            session = this._createSession(sessionID, '', mode);
297
+            session = this._createSession(sessionID, 'on', mode);
255 298
         }
256 299
 
300
+        // When a jibri is present the status is always 'on';
301
+        session.setStatus('on');
302
+        session.setJibriJid(presence.getAttribute('from'));
257 303
         session.setLiveStreamViewURL(liveStreamViewURL);
258 304
 
259 305
         this._emitSessionUpdate(session);

Loading…
Annulla
Salva