Parcourir la source

feat(ts) migrate RecordingManager to TS

dev0
Yash il y a 8 mois
Parent
révision
2a8647b16a
Aucun compte lié à l'adresse e-mail de l'auteur
1 fichiers modifiés avec 24 ajouts et 15 suppressions
  1. 24
    15
      modules/recording/RecordingManager.ts

modules/recording/RecordingManager.js → modules/recording/RecordingManager.ts Voir le fichier

1
 import { getLogger } from '@jitsi/logger';
1
 import { getLogger } from '@jitsi/logger';
2
 
2
 
3
 import { XMPPEvents } from '../../service/xmpp/XMPPEvents';
3
 import { XMPPEvents } from '../../service/xmpp/XMPPEvents';
4
+import ChatRoom from '../xmpp/ChatRoom';
4
 
5
 
5
 import JibriSession from './JibriSession';
6
 import JibriSession from './JibriSession';
6
 import recordingXMLUtils from './recordingXMLUtils';
7
 import recordingXMLUtils from './recordingXMLUtils';
7
 
8
 
8
 const logger = getLogger(__filename);
9
 const logger = getLogger(__filename);
9
 
10
 
11
+export interface IRecordingOptions {
12
+    appData?: string;
13
+    broadcastId?: string;
14
+    mode: string;
15
+    streamId?: string;
16
+}
17
+
10
 /**
18
 /**
11
  * A class responsible for starting and stopping recording sessions and emitting
19
  * A class responsible for starting and stopping recording sessions and emitting
12
  * state updates for them.
20
  * state updates for them.
13
  */
21
  */
14
 class RecordingManager {
22
 class RecordingManager {
23
+    private _sessions: { [key: string]: JibriSession; } = {};
24
+    private _chatRoom: any;
25
+
15
     /**
26
     /**
16
      * Initialize {@code RecordingManager} with other objects that are necessary
27
      * Initialize {@code RecordingManager} with other objects that are necessary
17
      * for starting a recording.
28
      * for starting a recording.
19
      * @param {ChatRoom} chatRoom - The chat room to handle.
30
      * @param {ChatRoom} chatRoom - The chat room to handle.
20
      * @returns {void}
31
      * @returns {void}
21
      */
32
      */
22
-    constructor(chatRoom) {
33
+    constructor(chatRoom: ChatRoom) {
23
         /**
34
         /**
24
          * All known recording sessions from the current conference.
35
          * All known recording sessions from the current conference.
25
          */
36
          */
26
-        this._sessions = {};
27
-
28
         this._chatRoom = chatRoom;
37
         this._chatRoom = chatRoom;
29
 
38
 
30
         this.onPresence = this.onPresence.bind(this);
39
         this.onPresence = this.onPresence.bind(this);
43
      * @param {string} sessionID - The session ID associated with the recording.
52
      * @param {string} sessionID - The session ID associated with the recording.
44
      * @returns {JibriSession|undefined}
53
      * @returns {JibriSession|undefined}
45
      */
54
      */
46
-    getSession(sessionID) {
55
+    getSession(sessionID: string): JibriSession | undefined {
47
         return this._sessions[sessionID];
56
         return this._sessions[sessionID];
48
     }
57
     }
49
 
58
 
53
      * @param {string} jibriJid the JID to search for.
62
      * @param {string} jibriJid the JID to search for.
54
      * @returns
63
      * @returns
55
      */
64
      */
56
-    getSessionByJibriJid(jibriJid) {
57
-        let s;
65
+    getSessionByJibriJid(jibriJid: string): JibriSession | undefined {
66
+        let s: JibriSession | undefined;
58
 
67
 
59
         Object.values(this._sessions).forEach(session => {
68
         Object.values(this._sessions).forEach(session => {
60
             if (session.getJibriJid() === jibriJid) {
69
             if (session.getJibriJid() === jibriJid) {
77
      * with the Jibri recorder participant.
86
      * with the Jibri recorder participant.
78
      * @returns {void}
87
      * @returns {void}
79
      */
88
      */
80
-    onPresence({ fromHiddenDomain, presence }) {
89
+    onPresence({ fromHiddenDomain, presence }: { fromHiddenDomain: boolean; presence: Node; }): void {
81
         if (recordingXMLUtils.isFromFocus(presence)) {
90
         if (recordingXMLUtils.isFromFocus(presence)) {
82
             this._handleFocusPresence(presence);
91
             this._handleFocusPresence(presence);
83
         } else if (fromHiddenDomain) {
92
         } else if (fromHiddenDomain) {
89
      * Handle a participant leaving the room.
98
      * Handle a participant leaving the room.
90
      * @param {string} jid the JID of the participant that left.
99
      * @param {string} jid the JID of the participant that left.
91
      */
100
      */
92
-    onMemberLeft(jid) {
101
+    onMemberLeft(jid: string): void {
93
         const session = this.getSessionByJibriJid(jid);
102
         const session = this.getSessionByJibriJid(jid);
94
 
103
 
95
         if (session) {
104
         if (session) {
122
      * back the session on success. The promise resolves after receiving an
131
      * back the session on success. The promise resolves after receiving an
123
      * acknowledgment of the start request success or fail.
132
      * acknowledgment of the start request success or fail.
124
      */
133
      */
125
-    startRecording(options) {
134
+    startRecording(options: IRecordingOptions): Promise<JibriSession> {
126
         const session = new JibriSession({
135
         const session = new JibriSession({
127
             ...options,
136
             ...options,
128
             connection: this._chatRoom.connection
137
             connection: this._chatRoom.connection
161
      * @returns {Promise} The promise resolves after receiving an
170
      * @returns {Promise} The promise resolves after receiving an
162
      * acknowledgment of the stop request success or fail.
171
      * acknowledgment of the stop request success or fail.
163
      */
172
      */
164
-    stopRecording(sessionID) {
173
+    stopRecording(sessionID: string): Promise<any> {
165
         const session = this.getSession(sessionID);
174
         const session = this.getSession(sessionID);
166
 
175
 
167
         if (session) {
176
         if (session) {
177
      * @param {string} session - The JibriSession instance to store.
186
      * @param {string} session - The JibriSession instance to store.
178
      * @returns {void}
187
      * @returns {void}
179
      */
188
      */
180
-    _addSession(session) {
189
+    _addSession(session: JibriSession): void {
181
         this._sessions[session.getID()] = session;
190
         this._sessions[session.getID()] = session;
182
     }
191
     }
183
 
192
 
190
      * @param {string} mode - The recording mode of the session.
199
      * @param {string} mode - The recording mode of the session.
191
      * @returns {JibriSession}
200
      * @returns {JibriSession}
192
      */
201
      */
193
-    _createSession(sessionID, status, mode) {
202
+    _createSession(sessionID: string, status: string, mode: string): JibriSession {
194
         const session = new JibriSession({
203
         const session = new JibriSession({
195
             connection: this._chatRoom.connection,
204
             connection: this._chatRoom.connection,
196
             focusMucJid: this._chatRoom.focusMucJid,
205
             focusMucJid: this._chatRoom.focusMucJid,
210
      * @param {JibriSession} session - The session that has been updated.
219
      * @param {JibriSession} session - The session that has been updated.
211
      * @param {string|undefined} initiator - The jid of the initiator of the update.
220
      * @param {string|undefined} initiator - The jid of the initiator of the update.
212
      */
221
      */
213
-    _emitSessionUpdate(session, initiator) {
222
+    _emitSessionUpdate(session: JibriSession, initiator?: string): void {
214
         this._chatRoom.eventEmitter.emit(
223
         this._chatRoom.eventEmitter.emit(
215
             XMPPEvents.RECORDER_STATE_CHANGED, session, initiator);
224
             XMPPEvents.RECORDER_STATE_CHANGED, session, initiator);
216
     }
225
     }
222
      * @param {Node} presence - An XMPP presence update.
231
      * @param {Node} presence - An XMPP presence update.
223
      * @returns {void}
232
      * @returns {void}
224
      */
233
      */
225
-    _handleFocusPresence(presence) {
234
+    _handleFocusPresence(presence: Node): void {
226
         const jibriStatus = recordingXMLUtils.getFocusRecordingUpdate(presence);
235
         const jibriStatus = recordingXMLUtils.getFocusRecordingUpdate(presence);
227
 
236
 
228
         if (!jibriStatus) {
237
         if (!jibriStatus) {
280
      * @param {Node} presence - An XMPP presence update.
289
      * @param {Node} presence - An XMPP presence update.
281
      * @returns {void}
290
      * @returns {void}
282
      */
291
      */
283
-    _handleJibriPresence(presence) {
292
+    _handleJibriPresence(presence: any): void {
284
         const { liveStreamViewURL, mode, sessionID }
293
         const { liveStreamViewURL, mode, sessionID }
285
             = recordingXMLUtils.getHiddenDomainUpdate(presence);
294
             = recordingXMLUtils.getHiddenDomainUpdate(presence);
286
 
295
 

Chargement…
Annuler
Enregistrer