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