浏览代码

feat(ts) migrate JitsiParticipant to TS

dev0
Naman Jain 8 个月前
父节点
当前提交
0fce9d6bb3
没有帐户链接到提交者的电子邮件
共有 3 个文件被更改,包括 95 次插入44 次删除
  1. 80
    44
      JitsiParticipant.ts
  2. 14
    0
      package-lock.json
  3. 1
    0
      package.json

JitsiParticipant.js → JitsiParticipant.ts 查看文件

1
-
2
 import { Strophe } from 'strophe.js';
1
 import { Strophe } from 'strophe.js';
3
 
2
 
4
-
3
+import JitsiConference from './JitsiConference';
5
 import * as JitsiConferenceEvents from './JitsiConferenceEvents';
4
 import * as JitsiConferenceEvents from './JitsiConferenceEvents';
5
+import JitsiTrack from './modules/RTC/JitsiTrack';
6
 import { MediaType } from './service/RTC/MediaType';
6
 import { MediaType } from './service/RTC/MediaType';
7
 
7
 
8
+export interface ISourceInfo {
9
+    muted: boolean;
10
+    videoType: string;
11
+}
12
+
8
 /**
13
 /**
9
  * Represents a participant in (i.e. a member of) a conference.
14
  * Represents a participant in (i.e. a member of) a conference.
10
  */
15
  */
11
 export default class JitsiParticipant {
16
 export default class JitsiParticipant {
12
 
17
 
18
+    private _jid: string;
19
+    private _id: string;
20
+    private _conference: JitsiConference;
21
+    private _displayName: string;
22
+    private _supportsDTMF: boolean;
23
+    private _tracks: JitsiTrack[];
24
+    private _role: string;
25
+    private _status?: string;
26
+    private _hidden: boolean;
27
+    private _statsID?: string;
28
+    private _properties: Map<string, any>;
29
+    private _identity?: object;
30
+    private _isReplacing?: boolean;
31
+    private _isReplaced?: boolean;
32
+    private _isSilent?: boolean;
33
+    private _features: Set<string>;
34
+    private _sources: Map<MediaType, Map<string, ISourceInfo>>;
35
+    private _botType?: string;
36
+    private _connectionJid?: string;
37
+
13
     /* eslint-disable max-params */
38
     /* eslint-disable max-params */
14
 
39
 
15
     /**
40
     /**
28
      * @param {boolean?} isReplaced - whether this is a participant to be kicked and replaced into the meeting.
53
      * @param {boolean?} isReplaced - whether this is a participant to be kicked and replaced into the meeting.
29
      * @param {boolean?} isSilent - whether participant has joined without audio
54
      * @param {boolean?} isSilent - whether participant has joined without audio
30
      */
55
      */
31
-    constructor(jid, conference, displayName, hidden, statsID, status, identity, isReplacing, isReplaced, isSilent) {
56
+    constructor(
57
+            jid: string,
58
+            conference: JitsiConference,
59
+            displayName: string,
60
+            hidden: boolean,
61
+            statsID?: string,
62
+            status?: string,
63
+            identity?: object,
64
+            isReplacing?: boolean,
65
+            isReplaced?: boolean,
66
+            isSilent?: boolean
67
+    ) {
32
         this._jid = jid;
68
         this._jid = jid;
33
         this._id = Strophe.getResourceFromJid(jid);
69
         this._id = Strophe.getResourceFromJid(jid);
34
         this._conference = conference;
70
         this._conference = conference;
48
 
84
 
49
         /**
85
         /**
50
          * Remote sources associated with the participant in the following format.
86
          * Remote sources associated with the participant in the following format.
51
-         * Map<mediaType, Map<sourceName, sourceInfo>>
87
+         * Map<mediaType, Map<sourceName, ISourceInfo>>
52
          *
88
          *
53
          * mediaType - 'audio' or 'video'.
89
          * mediaType - 'audio' or 'video'.
54
          * sourceName - name of the remote source.
90
          * sourceName - name of the remote source.
55
-         * sourceInfo: {
91
+         * ISourceInfo: {
56
          *   muted: boolean;
92
          *   muted: boolean;
57
          *   videoType: string;
93
          *   videoType: string;
58
          * }
94
          * }
69
      * @returns {Boolean} True if all JitsiTracks which are of the specified mediaType and which belong to this
105
      * @returns {Boolean} True if all JitsiTracks which are of the specified mediaType and which belong to this
70
      * JitsiParticipant are muted; otherwise, false.
106
      * JitsiParticipant are muted; otherwise, false.
71
      */
107
      */
72
-    _isMediaTypeMuted(mediaType) {
108
+    _isMediaTypeMuted(mediaType: MediaType): boolean {
73
         return this.getTracks().reduce(
109
         return this.getTracks().reduce(
74
             (muted, track) =>
110
             (muted, track) =>
75
-                muted && (track.getType() !== mediaType || track.isMuted()),
111
+                muted && (track.getType() !== mediaType || (track as any).isMuted()),
76
             true);
112
             true);
77
     }
113
     }
78
 
114
 
84
      * @param {string} videoType The video type of the source.
120
      * @param {string} videoType The video type of the source.
85
      * @returns {void}
121
      * @returns {void}
86
      */
122
      */
87
-    _setSources(mediaType, muted, sourceName, videoType) {
123
+    _setSources(mediaType: MediaType, muted: boolean, sourceName: string, videoType: string): void {
88
         let sourceByMediaType = this._sources.get(mediaType);
124
         let sourceByMediaType = this._sources.get(mediaType);
89
-        const sourceInfo = {
125
+        const sourceInfo: ISourceInfo = {
90
             muted,
126
             muted,
91
             videoType
127
             videoType
92
         };
128
         };
107
      *
143
      *
108
      * @returns {string|undefined} - The bot type of the participant.
144
      * @returns {string|undefined} - The bot type of the participant.
109
      */
145
      */
110
-    getBotType() {
146
+    getBotType(): string | undefined {
111
         return this._botType;
147
         return this._botType;
112
     }
148
     }
113
 
149
 
115
      * @returns {JitsiConference} The conference that this participant belongs
151
      * @returns {JitsiConference} The conference that this participant belongs
116
      * to.
152
      * to.
117
      */
153
      */
118
-    getConference() {
154
+    getConference(): JitsiConference {
119
         return this._conference;
155
         return this._conference;
120
     }
156
     }
121
 
157
 
124
      *
160
      *
125
      * @returns {string|undefined} - The connection jid of the participant.
161
      * @returns {string|undefined} - The connection jid of the participant.
126
      */
162
      */
127
-    getConnectionJid() {
163
+    getConnectionJid(): string | undefined {
128
         return this._connectionJid;
164
         return this._connectionJid;
129
     }
165
     }
130
 
166
 
131
     /**
167
     /**
132
      * @returns {String} The human-readable display name of this participant.
168
      * @returns {String} The human-readable display name of this participant.
133
      */
169
      */
134
-    getDisplayName() {
170
+    getDisplayName(): string {
135
         return this._displayName;
171
         return this._displayName;
136
     }
172
     }
137
 
173
 
139
      * Returns a set with the features for the participant.
175
      * Returns a set with the features for the participant.
140
      * @returns {Promise<Set<String>>}
176
      * @returns {Promise<Set<String>>}
141
      */
177
      */
142
-    getFeatures() {
178
+    getFeatures(): Promise<Set<string>> {
143
         return Promise.resolve(this._features);
179
         return Promise.resolve(this._features);
144
     }
180
     }
145
 
181
 
146
     /**
182
     /**
147
      * @returns {String} The ID of this participant.
183
      * @returns {String} The ID of this participant.
148
      */
184
      */
149
-    getId() {
185
+    getId(): string {
150
         return this._id;
186
         return this._id;
151
     }
187
     }
152
 
188
 
156
      *
192
      *
157
      * @returns {object|undefined} - XMPP user identity.
193
      * @returns {object|undefined} - XMPP user identity.
158
      */
194
      */
159
-    getIdentity() {
195
+    getIdentity(): object | undefined {
160
         return this._identity;
196
         return this._identity;
161
     }
197
     }
162
 
198
 
163
     /**
199
     /**
164
      * @returns {String} The JID of this participant.
200
      * @returns {String} The JID of this participant.
165
      */
201
      */
166
-    getJid() {
202
+    getJid(): string {
167
         return this._jid;
203
         return this._jid;
168
     }
204
     }
169
 
205
 
170
     /**
206
     /**
171
      * Gets the value of a property of this participant.
207
      * Gets the value of a property of this participant.
172
      */
208
      */
173
-    getProperty(name) {
209
+    getProperty(name: string): any {
174
         return this._properties.get(name);
210
         return this._properties.get(name);
175
     }
211
     }
176
 
212
 
177
     /**
213
     /**
178
      * @returns {String} The role of this participant.
214
      * @returns {String} The role of this participant.
179
      */
215
      */
180
-    getRole() {
216
+    getRole(): string {
181
         return this._role;
217
         return this._role;
182
     }
218
     }
183
 
219
 
185
      * Returns the sources associated with this participant.
221
      * Returns the sources associated with this participant.
186
      * @returns Map<string, Map<string, Object>>
222
      * @returns Map<string, Map<string, Object>>
187
      */
223
      */
188
-    getSources() {
224
+    getSources(): Map<MediaType, Map<string, ISourceInfo>> {
189
         return this._sources;
225
         return this._sources;
190
     }
226
     }
191
 
227
 
192
     /**
228
     /**
193
      * @returns {String} The stats ID of this participant.
229
      * @returns {String} The stats ID of this participant.
194
      */
230
      */
195
-    getStatsID() {
231
+    getStatsID(): string {
196
         return this._statsID;
232
         return this._statsID;
197
     }
233
     }
198
 
234
 
199
     /**
235
     /**
200
      * @returns {String} The status of the participant.
236
      * @returns {String} The status of the participant.
201
      */
237
      */
202
-    getStatus() {
238
+    getStatus(): string {
203
         return this._status;
239
         return this._status;
204
     }
240
     }
205
 
241
 
207
      * @returns {Array.<JitsiTrack>} The list of media tracks for this
243
      * @returns {Array.<JitsiTrack>} The list of media tracks for this
208
      * participant.
244
      * participant.
209
      */
245
      */
210
-    getTracks() {
246
+    getTracks(): JitsiTrack[] {
211
         return this._tracks.slice();
247
         return this._tracks.slice();
212
     }
248
     }
213
 
249
 
216
      * @returns {Array.<JitsiTrack>} an array of media tracks for this
252
      * @returns {Array.<JitsiTrack>} an array of media tracks for this
217
      * participant, for given media type.
253
      * participant, for given media type.
218
      */
254
      */
219
-    getTracksByMediaType(mediaType) {
255
+    getTracksByMediaType(mediaType: MediaType): JitsiTrack[] {
220
         return this.getTracks().filter(track => track.getType() === mediaType);
256
         return this.getTracks().filter(track => track.getType() === mediaType);
221
     }
257
     }
222
 
258
 
226
      * @return {boolean} <tt>true</tt> if this <tt>participant</tt> contains the
262
      * @return {boolean} <tt>true</tt> if this <tt>participant</tt> contains the
227
      * <tt>feature</tt>.
263
      * <tt>feature</tt>.
228
      */
264
      */
229
-    hasFeature(feature) {
265
+    hasFeature(feature: string): boolean {
230
         return this._features.has(feature);
266
         return this._features.has(feature);
231
     }
267
     }
232
 
268
 
233
     /**
269
     /**
234
      * @returns {Boolean} Whether this participant has muted their audio.
270
      * @returns {Boolean} Whether this participant has muted their audio.
235
      */
271
      */
236
-    isAudioMuted() {
272
+    isAudioMuted(): boolean {
237
         return this._isMediaTypeMuted(MediaType.AUDIO);
273
         return this._isMediaTypeMuted(MediaType.AUDIO);
238
     }
274
     }
239
 
275
 
242
      * special system participants may want to join hidden (like for example the
278
      * special system participants may want to join hidden (like for example the
243
      * recorder).
279
      * recorder).
244
      */
280
      */
245
-    isHidden() {
281
+    isHidden(): boolean {
246
         return this._hidden;
282
         return this._hidden;
247
     }
283
     }
248
 
284
 
251
      * special system participants may want to join hidden (like for example the
287
      * special system participants may want to join hidden (like for example the
252
      * recorder).
288
      * recorder).
253
      */
289
      */
254
-    isHiddenFromRecorder() {
255
-        return this._identity?.user?.['hidden-from-recorder'] === 'true';
290
+    isHiddenFromRecorder(): boolean {
291
+        return (this._identity as any)?.user?.['hidden-from-recorder'] === 'true';
256
     }
292
     }
257
 
293
 
258
     /**
294
     /**
259
      * @returns {Boolean} Whether this participant is a moderator or not.
295
      * @returns {Boolean} Whether this participant is a moderator or not.
260
      */
296
      */
261
-    isModerator() {
297
+    isModerator(): boolean {
262
         return this._role === 'moderator';
298
         return this._role === 'moderator';
263
     }
299
     }
264
 
300
 
266
      * @returns {Boolean} Wheter this participants will be replaced by another
302
      * @returns {Boolean} Wheter this participants will be replaced by another
267
      * participant in the meeting.
303
      * participant in the meeting.
268
      */
304
      */
269
-    isReplaced() {
305
+    isReplaced(): boolean {
270
         return this._isReplaced;
306
         return this._isReplaced;
271
     }
307
     }
272
 
308
 
274
      * @returns {Boolean} Whether this participant replaces another participant
310
      * @returns {Boolean} Whether this participant replaces another participant
275
      * from the meeting.
311
      * from the meeting.
276
      */
312
      */
277
-    isReplacing() {
313
+    isReplacing(): boolean {
278
         return this._isReplacing;
314
         return this._isReplacing;
279
     }
315
     }
280
 
316
 
281
     /**
317
     /**
282
      * @returns {Boolean} Whether this participant has joined without audio.
318
      * @returns {Boolean} Whether this participant has joined without audio.
283
      */
319
      */
284
-    isSilent() {
320
+    isSilent(): boolean {
285
         return this._isSilent;
321
         return this._isSilent;
286
     }
322
     }
287
 
323
 
288
     /**
324
     /**
289
      * @returns {Boolean} Whether this participant has muted their video.
325
      * @returns {Boolean} Whether this participant has muted their video.
290
      */
326
      */
291
-    isVideoMuted() {
327
+    isVideoMuted(): boolean {
292
         return this._isMediaTypeMuted(MediaType.VIDEO);
328
         return this._isMediaTypeMuted(MediaType.VIDEO);
293
     }
329
     }
294
 
330
 
296
      * Sets the bot type for the participant.
332
      * Sets the bot type for the participant.
297
      * @param {String} newBotType - The new bot type to set.
333
      * @param {String} newBotType - The new bot type to set.
298
      */
334
      */
299
-    setBotType(newBotType) {
335
+    setBotType(newBotType: string): void {
300
         this._botType = newBotType;
336
         this._botType = newBotType;
301
     }
337
     }
302
 
338
 
304
      * Sets the connection jid for the participant.
340
      * Sets the connection jid for the participant.
305
      * @param {String} newJid - The connection jid to set.
341
      * @param {String} newJid - The connection jid to set.
306
      */
342
      */
307
-    setConnectionJid(newJid) {
343
+    setConnectionJid(newJid: string): void {
308
         this._connectionJid = newJid;
344
         this._connectionJid = newJid;
309
     }
345
     }
310
 
346
 
312
      * Set new features.
348
      * Set new features.
313
      * @param {Set<String>|undefined} newFeatures - Sets new features.
349
      * @param {Set<String>|undefined} newFeatures - Sets new features.
314
      */
350
      */
315
-    setFeatures(newFeatures) {
351
+    setFeatures(newFeatures?: Set<string>): void {
316
         this._features = newFeatures || new Set();
352
         this._features = newFeatures || new Set();
317
     }
353
     }
318
 
354
 
320
      * Sets whether participant is being replaced by another based on jwt.
356
      * Sets whether participant is being replaced by another based on jwt.
321
      * @param {boolean} newIsReplaced - whether is being replaced.
357
      * @param {boolean} newIsReplaced - whether is being replaced.
322
      */
358
      */
323
-    setIsReplaced(newIsReplaced) {
359
+    setIsReplaced(newIsReplaced: boolean): void {
324
         this._isReplaced = newIsReplaced;
360
         this._isReplaced = newIsReplaced;
325
     }
361
     }
326
 
362
 
327
     /**
363
     /**
328
      * Sets whether participant is replacing another based on jwt.
364
      * Sets whether participant is replacing another based on jwt.
329
-     * @param {String} newIsReplacing - whether is replacing.
365
+     * @param {boolean} newIsReplacing - whether is replacing.
330
      */
366
      */
331
-    setIsReplacing(newIsReplacing) {
367
+    setIsReplacing(newIsReplacing: boolean): void {
332
         this._isReplacing = newIsReplacing;
368
         this._isReplacing = newIsReplacing;
333
     }
369
     }
334
 
370
 
336
      * Sets whether participant has joined without audio.
372
      * Sets whether participant has joined without audio.
337
      * @param {boolean} newIsSilent - whether is silent.
373
      * @param {boolean} newIsSilent - whether is silent.
338
      */
374
      */
339
-    setIsSilent(newIsSilent) {
375
+    setIsSilent(newIsSilent: boolean): void {
340
         this._isSilent = newIsSilent;
376
         this._isSilent = newIsSilent;
341
     }
377
     }
342
 
378
 
346
      * @name the name of the property.
382
      * @name the name of the property.
347
      * @value the value to set.
383
      * @value the value to set.
348
      */
384
      */
349
-    setProperty(name, value) {
385
+    setProperty(name: string, value: any): void {
350
         const oldValue = this._properties.get(name);
386
         const oldValue = this._properties.get(name);
351
 
387
 
352
         if (value !== oldValue) {
388
         if (value !== oldValue) {
364
      * Sets a new participant role.
400
      * Sets a new participant role.
365
      * @param {String} newRole - the new role.
401
      * @param {String} newRole - the new role.
366
      */
402
      */
367
-    setRole(newRole) {
403
+    setRole(newRole: string): void {
368
         this._role = newRole;
404
         this._role = newRole;
369
     }
405
     }
370
 
406
 
371
     /**
407
     /**
372
      *
408
      *
373
      */
409
      */
374
-    supportsDTMF() {
410
+    supportsDTMF(): boolean {
375
         return this._supportsDTMF;
411
         return this._supportsDTMF;
376
     }
412
     }
377
 }
413
 }

+ 14
- 0
package-lock.json 查看文件

33
         "@types/jasmine": "4.0.3",
33
         "@types/jasmine": "4.0.3",
34
         "@types/lodash-es": "4.17.12",
34
         "@types/lodash-es": "4.17.12",
35
         "@types/sdp-transform": "2.4.5",
35
         "@types/sdp-transform": "2.4.5",
36
+        "@types/strophe": "1.2.37",
36
         "babel-loader": "8.2.3",
37
         "babel-loader": "8.2.3",
37
         "core-js": "3.19.1",
38
         "core-js": "3.19.1",
38
         "eslint": "8.57.0",
39
         "eslint": "8.57.0",
2200
       "dev": true,
2201
       "dev": true,
2201
       "license": "MIT"
2202
       "license": "MIT"
2202
     },
2203
     },
2204
+    "node_modules/@types/strophe": {
2205
+      "version": "1.2.37",
2206
+      "resolved": "https://registry.npmjs.org/@types/strophe/-/strophe-1.2.37.tgz",
2207
+      "integrity": "sha512-qKYKbMuBmyfK9oMBuD4UZHF0GhHA62xiMj8+jPr8tfeVprdG+hkxxrp5Mf6y7rCqcC+om37p+TVlotNHdFYPug==",
2208
+      "dev": true,
2209
+      "license": "MIT"
2210
+    },
2203
     "node_modules/@typescript-eslint/eslint-plugin": {
2211
     "node_modules/@typescript-eslint/eslint-plugin": {
2204
       "version": "8.19.1",
2212
       "version": "8.19.1",
2205
       "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.19.1.tgz",
2213
       "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.19.1.tgz",
10462
       "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==",
10470
       "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==",
10463
       "dev": true
10471
       "dev": true
10464
     },
10472
     },
10473
+    "@types/strophe": {
10474
+      "version": "1.2.37",
10475
+      "resolved": "https://registry.npmjs.org/@types/strophe/-/strophe-1.2.37.tgz",
10476
+      "integrity": "sha512-qKYKbMuBmyfK9oMBuD4UZHF0GhHA62xiMj8+jPr8tfeVprdG+hkxxrp5Mf6y7rCqcC+om37p+TVlotNHdFYPug==",
10477
+      "dev": true
10478
+    },
10465
     "@typescript-eslint/eslint-plugin": {
10479
     "@typescript-eslint/eslint-plugin": {
10466
       "version": "8.19.1",
10480
       "version": "8.19.1",
10467
       "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.19.1.tgz",
10481
       "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.19.1.tgz",

+ 1
- 0
package.json 查看文件

40
     "@types/jasmine": "4.0.3",
40
     "@types/jasmine": "4.0.3",
41
     "@types/lodash-es": "4.17.12",
41
     "@types/lodash-es": "4.17.12",
42
     "@types/sdp-transform": "2.4.5",
42
     "@types/sdp-transform": "2.4.5",
43
+    "@types/strophe": "1.2.37",
43
     "babel-loader": "8.2.3",
44
     "babel-loader": "8.2.3",
44
     "core-js": "3.19.1",
45
     "core-js": "3.19.1",
45
     "eslint": "8.57.0",
46
     "eslint": "8.57.0",

正在加载...
取消
保存