|
@@ -1,24 +1,64 @@
|
1
|
1
|
import { $iq } from 'strophe.js';
|
2
|
2
|
|
3
|
3
|
import recordingXMLUtils from './recordingXMLUtils';
|
|
4
|
+import JitsiParticipant from '../../JitsiParticipant';
|
|
5
|
+
|
|
6
|
+export interface IJibriSessionOptions {
|
|
7
|
+ connection?: any;
|
|
8
|
+ focusMucJid?: string;
|
|
9
|
+ mode?: string;
|
|
10
|
+ sessionID?: string;
|
|
11
|
+ status?: string;
|
|
12
|
+}
|
|
13
|
+
|
|
14
|
+export interface IStartOptions {
|
|
15
|
+ appData?: string;
|
|
16
|
+ broadcastId?: string;
|
|
17
|
+ focusMucJid: string;
|
|
18
|
+ streamId?: string;
|
|
19
|
+}
|
|
20
|
+
|
|
21
|
+export interface IStopOptions {
|
|
22
|
+ focusMucJid: string;
|
|
23
|
+}
|
|
24
|
+
|
|
25
|
+export interface IQOptions {
|
|
26
|
+ action?: 'start' | 'stop';
|
|
27
|
+ appData?: string;
|
|
28
|
+ broadcastId?: string;
|
|
29
|
+ focusMucJid: string;
|
|
30
|
+ streamId?: string;
|
|
31
|
+}
|
4
|
32
|
|
5
|
33
|
/**
|
6
|
34
|
* Represents a recording session.
|
7
|
35
|
*/
|
8
|
36
|
export default class JibriSession {
|
|
37
|
+ private _connection?: any;
|
|
38
|
+ private _mode?: string;
|
|
39
|
+ private _jibriJid: string | null = null;
|
|
40
|
+ private _statusFromJicofo: string = '';
|
|
41
|
+ private _sessionID?: string;
|
|
42
|
+ private _status?: string;
|
|
43
|
+ private _error?: string;
|
|
44
|
+ private _liveStreamViewURL?: string;
|
|
45
|
+ private _initiator?: JitsiParticipant | string;
|
|
46
|
+ private _terminator?: JitsiParticipant | string;
|
|
47
|
+ private _focusMucJid?: string;
|
|
48
|
+
|
9
|
49
|
/**
|
10
|
50
|
* Initializes a new JibriSession instance.
|
11
|
51
|
*
|
12
|
52
|
* @constructor
|
13
|
53
|
*/
|
14
|
|
- constructor(options = {}) {
|
|
54
|
+ constructor(options: IJibriSessionOptions = {}) {
|
15
|
55
|
this._connection = options.connection;
|
16
|
56
|
this._mode = options.mode;
|
17
|
57
|
this._jibriJid = null;
|
18
|
58
|
this._statusFromJicofo = '';
|
19
|
|
-
|
20
|
59
|
this._setSessionID(options.sessionID);
|
21
|
60
|
this.setStatus(options.status);
|
|
61
|
+ this._focusMucJid = options.focusMucJid;
|
22
|
62
|
}
|
23
|
63
|
|
24
|
64
|
/**
|
|
@@ -26,7 +66,7 @@ export default class JibriSession {
|
26
|
66
|
*
|
27
|
67
|
* @returns {string|undefined}
|
28
|
68
|
*/
|
29
|
|
- getError() {
|
|
69
|
+ getError(): string | undefined {
|
30
|
70
|
return this._error;
|
31
|
71
|
}
|
32
|
72
|
|
|
@@ -35,7 +75,7 @@ export default class JibriSession {
|
35
|
75
|
*
|
36
|
76
|
* @returns {string|undefined}
|
37
|
77
|
*/
|
38
|
|
- getID() {
|
|
78
|
+ getID(): string | undefined {
|
39
|
79
|
return this._sessionID;
|
40
|
80
|
}
|
41
|
81
|
|
|
@@ -44,7 +84,7 @@ export default class JibriSession {
|
44
|
84
|
*
|
45
|
85
|
* @returns {JitsiParticipant|string} The participant that started the session.
|
46
|
86
|
*/
|
47
|
|
- getInitiator() {
|
|
87
|
+ getInitiator(): JitsiParticipant | string {
|
48
|
88
|
return this._initiator;
|
49
|
89
|
}
|
50
|
90
|
|
|
@@ -53,7 +93,7 @@ export default class JibriSession {
|
53
|
93
|
*
|
54
|
94
|
* @returns {string|undefined}
|
55
|
95
|
*/
|
56
|
|
- getLiveStreamViewURL() {
|
|
96
|
+ getLiveStreamViewURL(): string | undefined {
|
57
|
97
|
return this._liveStreamViewURL;
|
58
|
98
|
}
|
59
|
99
|
|
|
@@ -62,7 +102,7 @@ export default class JibriSession {
|
62
|
102
|
*
|
63
|
103
|
* @returns {string|undefined}
|
64
|
104
|
*/
|
65
|
|
- getStatus() {
|
|
105
|
+ getStatus(): string | undefined {
|
66
|
106
|
// If _status is not set fallback to the status reported by jicofo.
|
67
|
107
|
if (this._status) {
|
68
|
108
|
return this._status;
|
|
@@ -74,7 +114,7 @@ export default class JibriSession {
|
74
|
114
|
/**
|
75
|
115
|
* @returns {string|undefined} the JID of jibri associated with this session.
|
76
|
116
|
*/
|
77
|
|
- getJibriJid() {
|
|
117
|
+ getJibriJid(): string | undefined {
|
78
|
118
|
return this._jibriJid;
|
79
|
119
|
}
|
80
|
120
|
|
|
@@ -83,7 +123,7 @@ export default class JibriSession {
|
83
|
123
|
*
|
84
|
124
|
* @returns {JitsiParticipant|string} The participant that stopped the session.
|
85
|
125
|
*/
|
86
|
|
- getTerminator() {
|
|
126
|
+ getTerminator(): JitsiParticipant | string {
|
87
|
127
|
return this._terminator;
|
88
|
128
|
}
|
89
|
129
|
|
|
@@ -92,7 +132,7 @@ export default class JibriSession {
|
92
|
132
|
*
|
93
|
133
|
* @returns {string}
|
94
|
134
|
*/
|
95
|
|
- getMode() {
|
|
135
|
+ getMode(): string {
|
96
|
136
|
return this._mode;
|
97
|
137
|
}
|
98
|
138
|
|
|
@@ -103,7 +143,7 @@ export default class JibriSession {
|
103
|
143
|
* entered an error state.
|
104
|
144
|
* @returns {void}
|
105
|
145
|
*/
|
106
|
|
- setError(error) {
|
|
146
|
+ setError(error: string): void {
|
107
|
147
|
this._error = error;
|
108
|
148
|
}
|
109
|
149
|
|
|
@@ -114,7 +154,7 @@ export default class JibriSession {
|
114
|
154
|
* @param {string} url - The live stream URL associated with the session.
|
115
|
155
|
* @returns {void}
|
116
|
156
|
*/
|
117
|
|
- setLiveStreamViewURL(url) {
|
|
157
|
+ setLiveStreamViewURL(url: string): void {
|
118
|
158
|
this._liveStreamViewURL = url;
|
119
|
159
|
}
|
120
|
160
|
|
|
@@ -124,7 +164,7 @@ export default class JibriSession {
|
124
|
164
|
* @param {string} status - The new status to set.
|
125
|
165
|
* @returns {void}
|
126
|
166
|
*/
|
127
|
|
- setStatus(status) {
|
|
167
|
+ setStatus(status?: string): void {
|
128
|
168
|
this._status = status;
|
129
|
169
|
}
|
130
|
170
|
|
|
@@ -134,7 +174,7 @@ export default class JibriSession {
|
134
|
174
|
*
|
135
|
175
|
* @param {string} status
|
136
|
176
|
*/
|
137
|
|
- setStatusFromJicofo(status) {
|
|
177
|
+ setStatusFromJicofo(status: string): void {
|
138
|
178
|
this._statusFromJicofo = status;
|
139
|
179
|
}
|
140
|
180
|
|
|
@@ -143,7 +183,7 @@ export default class JibriSession {
|
143
|
183
|
*
|
144
|
184
|
* @param {*} jibriJid
|
145
|
185
|
*/
|
146
|
|
- setJibriJid(jibriJid) {
|
|
186
|
+ setJibriJid(jibriJid: string | null): void {
|
147
|
187
|
this._jibriJid = jibriJid;
|
148
|
188
|
}
|
149
|
189
|
|
|
@@ -152,7 +192,7 @@ export default class JibriSession {
|
152
|
192
|
* @param {JitsiParticipant | string} participant - The participant or resource id
|
153
|
193
|
* if local participant.
|
154
|
194
|
*/
|
155
|
|
- setInitiator(participant) {
|
|
195
|
+ setInitiator(participant: JitsiParticipant | string): void {
|
156
|
196
|
this._initiator = participant;
|
157
|
197
|
}
|
158
|
198
|
|
|
@@ -161,7 +201,7 @@ export default class JibriSession {
|
161
|
201
|
* @param {JitsiParticipant | string} participant - The participant or the resource id
|
162
|
202
|
* if local participant.
|
163
|
203
|
*/
|
164
|
|
- setTerminator(participant) {
|
|
204
|
+ setTerminator(participant: JitsiParticipant | string): void {
|
165
|
205
|
this._terminator = participant;
|
166
|
206
|
}
|
167
|
207
|
|
|
@@ -182,9 +222,9 @@ export default class JibriSession {
|
182
|
222
|
* streaming service provider.
|
183
|
223
|
* @returns Promise
|
184
|
224
|
*/
|
185
|
|
- start({ appData, broadcastId, focusMucJid, streamId }) {
|
|
225
|
+ start({ appData, broadcastId, focusMucJid, streamId }: IStartOptions): Promise<void> {
|
186
|
226
|
return new Promise((resolve, reject) => {
|
187
|
|
- this._connection.sendIQ(
|
|
227
|
+ this._connection?.sendIQ(
|
188
|
228
|
this._createIQ({
|
189
|
229
|
action: 'start',
|
190
|
230
|
appData,
|
|
@@ -192,22 +232,20 @@ export default class JibriSession {
|
192
|
232
|
broadcastId,
|
193
|
233
|
streamId
|
194
|
234
|
}),
|
195
|
|
- result => {
|
196
|
|
- // All users will eventually receive the 'pending' status
|
197
|
|
- // from the backend, but for the user initiating the session
|
198
|
|
- // it's better to give some instant feedback that recording
|
199
|
|
- // is starting so fire 'pending' here manually.
|
|
235
|
+ (result: any) => {
|
200
|
236
|
this.setStatus('pending');
|
201
|
237
|
this._setSessionID(
|
202
|
|
- recordingXMLUtils.getSessionIdFromIq(result));
|
|
238
|
+ recordingXMLUtils.getSessionIdFromIq(result)
|
|
239
|
+ );
|
203
|
240
|
|
204
|
241
|
resolve();
|
205
|
242
|
},
|
206
|
|
- error => {
|
|
243
|
+ (error: any) => {
|
207
|
244
|
this._setErrorFromIq(error);
|
208
|
245
|
|
209
|
246
|
reject(error);
|
210
|
|
- });
|
|
247
|
+ }
|
|
248
|
+ );
|
211
|
249
|
});
|
212
|
250
|
}
|
213
|
251
|
|
|
@@ -220,15 +258,16 @@ export default class JibriSession {
|
220
|
258
|
* that controls recording.
|
221
|
259
|
* @returns Promise
|
222
|
260
|
*/
|
223
|
|
- stop({ focusMucJid }) {
|
|
261
|
+ stop({ focusMucJid }: IStopOptions): Promise<any> {
|
224
|
262
|
return new Promise((resolve, reject) => {
|
225
|
|
- this._connection.sendIQ(
|
|
263
|
+ this._connection?.sendIQ(
|
226
|
264
|
this._createIQ({
|
227
|
265
|
action: 'stop',
|
228
|
266
|
focusMucJid
|
229
|
267
|
}),
|
230
|
268
|
resolve,
|
231
|
|
- reject);
|
|
269
|
+ reject
|
|
270
|
+ );
|
232
|
271
|
});
|
233
|
272
|
}
|
234
|
273
|
|
|
@@ -248,7 +287,7 @@ export default class JibriSession {
|
248
|
287
|
* streaming service provider.
|
249
|
288
|
* @returns Object - The XMPP IQ message.
|
250
|
289
|
*/
|
251
|
|
- _createIQ({ action, appData, broadcastId, focusMucJid, streamId }) {
|
|
290
|
+ _createIQ({ action, appData, broadcastId, focusMucJid, streamId }: IQOptions) {
|
252
|
291
|
return $iq({
|
253
|
292
|
to: focusMucJid,
|
254
|
293
|
type: 'set'
|
|
@@ -271,7 +310,7 @@ export default class JibriSession {
|
271
|
310
|
* @private
|
272
|
311
|
* @returns {void}
|
273
|
312
|
*/
|
274
|
|
- _setErrorFromIq(errorIq) {
|
|
313
|
+ _setErrorFromIq(errorIq: any): void {
|
275
|
314
|
const error = errorIq.getElementsByTagName('error')[0];
|
276
|
315
|
|
277
|
316
|
this.setError(error.children[0].tagName);
|
|
@@ -284,7 +323,7 @@ export default class JibriSession {
|
284
|
323
|
* @private
|
285
|
324
|
* @returns {void}
|
286
|
325
|
*/
|
287
|
|
- _setSessionID(sessionID) {
|
|
326
|
+ _setSessionID(sessionID?: string): void {
|
288
|
327
|
this._sessionID = sessionID;
|
289
|
328
|
}
|
290
|
329
|
}
|