@reactoo/watchtogether-sdk-js 2.5.35 → 2.5.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import {wait} from "../modules/wt-utils";
3
+ import {decodeJanusDisplay, wait} from "../modules/wt-utils";
4
4
  import _emitter_ from "../modules/wt-emitter";
5
5
 
6
6
  // SYNCHRONISATION MODULES
@@ -17,7 +17,7 @@ import syncDisabled from "../modules/sync-modules/sync-disabled";
17
17
  import syncDaznDash from "../modules/sync-modules/sync-dazn-dash";
18
18
  import syncUniversal from "../modules/sync-modules/sync-universal";
19
19
 
20
- let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructor}, room, wt) {
20
+ let roomSession = function ({roomId, pinHash, role}, room, wt) {
21
21
 
22
22
  let primaryRoomId = roomId;
23
23
  let publicCustomEvents = ['changePlayerSource', 'chatMessage', 'userUpdate', 'reconnecting', 'connecting', 'remoteMuted', 'scaling'];
@@ -88,27 +88,33 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
88
88
  emitter.emit('connecting', true);
89
89
  clearTimeout(alpTimeoutId);
90
90
  abortController = new AbortController();
91
- return Promise.all([wt.room.__joinRoom({
91
+ return wt.room.__joinRoom({
92
92
  roomId: reactooRoomId || primaryRoomId,
93
93
  pinHash,
94
- isTalkback,
95
- isMonitor,
96
- isInstructor
97
- }, abortController?.signal), wt.user.getUserSelf()])
98
- .then(([roomData, userData]) => {
94
+ role
95
+ }, abortController?.signal)
96
+ .then(roomData => {
99
97
  // Happens when we reroute user to a different room
100
98
  if(roomData?.data?.reactooRoomId !== roomId) {
101
99
  roomId = roomData.data.reactooRoomId;
102
100
  emitter.emit('changeRoomId', roomId);
103
101
  }
104
- return Promise.all([roomData, userData])
102
+ room.setRoomType(roomData.data.roomType);
103
+ return room.connect(
104
+ roomData.data.roomId,
105
+ roomData.data.pin,
106
+ roomData.data.href,
107
+ roomData.data.iceServers,
108
+ roomData.data.accessToken,
109
+ roomData.data.display,
110
+ roomData.data.userId,
111
+ roomData.data.webrtcVersion,
112
+ (roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0),
113
+ roomData.data.recordingFilename)
105
114
  })
106
- .then(([roomData, userData]) => Promise.all([roomData, userData, this.setRoomVars()]))
107
- .then(([roomData, userData, _]) => Promise.all([roomData, userData, room.connect(roomData.data.roomId, roomData.data.pin, roomData.data.href, roomData.data.iceServers, roomData.data.accessToken, roomData.data.display, roomData.data.userId, roomData.data.webrtcVersion, (roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0), isMonitor, roomData.data.recordingFilename)]))
108
115
  .finally(() => {
109
116
  emitter.emit('connecting', false);
110
117
  })
111
-
112
118
  },
113
119
 
114
120
  disconnect: function (dontWaitForResponses) {
@@ -172,17 +178,13 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
172
178
  this.restart();
173
179
  } else if (msg.action === 'user_update_displayname' || msg.action === 'user_update_avatar' || msg.action === 'user_update_customattributes' || msg.action === 'user_update_privateattributes') {
174
180
  emitter.emit('userUpdate', msg.text);
175
- } else if (msg.action === 'observer_connecting' || msg.action === 'talkback_connecting' || msg.action === 'instructor_connecting') {
176
- this.setRoomVars().catch(e => {
177
- room._log('Setting observers failed, this will cause issues', e);
178
- });
179
181
  } else if (msg.action === 'bitrate_changed') {
180
182
  this.setBitrateCap(msg.text);
181
183
  } else if (msg.user_action === 'chat_message') {
182
184
  emitter.emit('chatMessage', msg);
183
185
  } else if (msg.user_action === 'remote_muted') {
184
186
  if (msg.from !== room.userId) {
185
- emitter.emit('remoteMuted', {userId: msg.from, ...(msg.text && JSON.parse(msg.text))})
187
+ emitter.emit('remoteMuted', {userId: decodeJanusDisplay(msg.from)?.userId, ...(msg.text && JSON.parse(msg.text))})
186
188
  }
187
189
  } else if (msg.user_action === 'remote_muted_request') {
188
190
  if (msg.from !== room.userId) {
@@ -289,16 +291,6 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
289
291
  }
290
292
  },
291
293
 
292
- setRoomVars: () => {
293
- return wt.room.getRoomById(roomId, pinHash, undefined, false, abortController?.signal)
294
- .then(r => {
295
- // setting observers userId's so we can ignore them when creating participant
296
- room.setObserverIds(r.data.allowedObservers);
297
- room.setTalkbackIds(r.data.allowedTalkbacks);
298
- room.setInstructorId(r.data.classroom?.instructorUserId);
299
- });
300
- },
301
-
302
294
  publishLocal: function (stream = null, {keepAudio = false, keepVideo = false} = {}) {
303
295
  return room.publishLocal(stream, {keepAudio, keepVideo})
304
296
  },
@@ -316,11 +308,9 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
316
308
  },
317
309
 
318
310
  setBitrateCap: (bitrate) => {
319
-
320
- if(isInstructor) {
311
+ if(role === 'host') {
321
312
  return;
322
313
  }
323
-
324
314
  return room.sendMessage(room.handleId, {
325
315
  "body": {
326
316
  "request": "configure",
@@ -329,19 +319,6 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
329
319
  }).catch(() => null)
330
320
  },
331
321
 
332
- switchChannel: (channelId) => {
333
- return room.sendMessage(room.handleId, {
334
- body: {
335
- request: "sync_source_set",
336
- room: room.roomId,
337
- timestamp: new Date().getTime(),
338
- wt_channel_id: channelId,
339
- fragment: "0",
340
- fragment_pos: 0
341
- }
342
- });
343
- },
344
-
345
322
  sendSystemMessage: (action, value = {}, to, set_master) => {
346
323
  return room.sendMessage(room.handleId, {
347
324
  body: {
@@ -205,15 +205,13 @@ let room = function () {
205
205
  }))
206
206
  },
207
207
 
208
- __joinRoom: ({roomId, pinHash, instanceType = this.__instanceType, isTalkback = undefined, isMonitor = undefined, isInstructor = undefined, customBearer = undefined} = {}, signal) => {
208
+ __joinRoom: ({roomId, pinHash, instanceType = this.__instanceType, role = 'participant', customBearer = undefined} = {}, signal) => {
209
209
  return this.__privates.auth.__client
210
210
  .then(client => client.apis.wt.join({
211
211
  roomId,
212
212
  pinHash,
213
213
  instanceType,
214
- isTalkback,
215
- isMonitor,
216
- isInstructor,
214
+ role,
217
215
  platform: this.browser === 'firefox' ? 'web-firefox' : 'web'
218
216
  }, {
219
217
  ...(signal ? {
@@ -246,10 +244,11 @@ let room = function () {
246
244
  .then(newSession => {
247
245
  let existingSessionIndex = roomSessions.findIndex(session => session.constructId === newSession.constructId);
248
246
  if(existingSessionIndex > -1) {
249
- return this.room.destroySession(newSession.constructId).then(() => {
250
- roomSessions.push(newSession);
251
- return newSession;
252
- });
247
+ return this.room.destroySession(newSession.constructId)
248
+ .then(() => {
249
+ roomSessions.push(newSession);
250
+ return newSession;
251
+ });
253
252
  } else {
254
253
  roomSessions.push(newSession);
255
254
  return newSession;
@@ -257,22 +256,21 @@ let room = function () {
257
256
  })
258
257
  },
259
258
 
260
- createSession: ({constructId, roomId, pinHash, isTalkback, isMonitor, isInstructor, options}) => {
259
+ createSession: ({constructId, roomId, pinHash, role, options}) => {
261
260
  return this.__privates.room.whenInitialized
262
261
  .then(lib => roomSession.call(this, {
263
262
  roomId,
264
263
  pinHash,
265
- isTalkback,
266
- isMonitor,
267
- isInstructor
264
+ role,
268
265
  }, lib.createSession(constructId, 'reactooroom', options), this))
269
266
  .then(newSession => {
270
267
  let existingSessionIndex = roomSessions.findIndex(session => session.constructId === newSession.constructId);
271
268
  if(existingSessionIndex > -1) {
272
- return this.room.destroySession(newSession.constructId).then(() => {
273
- roomSessions.push(newSession);
274
- return newSession;
275
- });
269
+ return this.room.destroySession(newSession.constructId)
270
+ .then(() => {
271
+ roomSessions.push(newSession);
272
+ return newSession;
273
+ });
276
274
  } else {
277
275
  roomSessions.push(newSession);
278
276
  return newSession;
@@ -1,6 +1,7 @@
1
1
 
2
2
  import {device} from 'aws-iot-device-sdk';
3
3
  import emitter from './wt-emitter';
4
+ import {decodeJanusDisplay} from "./wt-utils";
4
5
 
5
6
  class Iot {
6
7
 
@@ -68,14 +69,14 @@ class Iot {
68
69
  this.startCredentialsExpirationCheck(expiration);
69
70
 
70
71
  let __s = () => {
71
- this.device.off('connect', __s);
72
- this.device.off('error', __e);
72
+ this.device?.off('connect', __s);
73
+ this.device?.off('error', __e);
73
74
  resolve(this.device)
74
75
  };
75
76
 
76
77
  let __e = (e) => {
77
- this.device.off('connect', __s);
78
- this.device.off('error', __e);
78
+ this.device?.off('connect', __s);
79
+ this.device?.off('error', __e);
79
80
  reject(e);
80
81
  };
81
82
 
@@ -156,10 +157,16 @@ class Iot {
156
157
  }
157
158
 
158
159
  __messageCb(t, message, packet) {
159
-
160
160
  const topic = t.split('/');
161
- const payload = JSON.parse(this.decoder.decode(message));
162
-
161
+ let payload = JSON.parse(this.decoder.decode(message));
162
+
163
+ if(payload.display) {
164
+ const decodedDisplay = decodeJanusDisplay(payload.display);
165
+ if(decodedDisplay.userId) {
166
+ payload = {...payload, userId: decodedDisplay.userId}
167
+ }
168
+ }
169
+
163
170
  if(topic[0] === 'user') { // user
164
171
  const userId = topic[1].replace("_", ':');
165
172
  this.emit('message', {userId, ...payload, event: payload.event ? `user:${payload.event}` : 'user'});
@@ -2,7 +2,7 @@
2
2
 
3
3
  import adapter from 'webrtc-adapter';
4
4
  import emitter from './wt-emitter';
5
- import {generateUUID} from "./wt-utils";
5
+ import {decodeJanusDisplay, generateUUID} from "./wt-utils";
6
6
 
7
7
  class Room {
8
8
 
@@ -96,25 +96,42 @@ class RoomSession {
96
96
 
97
97
  static subscriptionRules = {
98
98
  participant: {
99
- watchTogether: ['participant', 'talkback'],
100
- videoWall: ['instructor', 'observer', 'talkback']
99
+ "watchparty": ['participant', 'talkback'],
100
+ "commentary": ['participant', 'talkback'],
101
+ "videowall": ['host', 'observer', 'talkback'],
102
+ "videowall-queue": ['host', 'observer', 'talkback'],
103
+ "videowall-queue-video": ['host', 'observer', 'talkback']
101
104
  },
102
105
  monitor: {
103
- watchTogether: ['participant'],
104
- videoWall: ['instructor', 'participant'],
106
+ "watchparty": ['participant'],
107
+ "commentary": ['participant'],
108
+ "videowall": ['host', 'participant'],
109
+ "videowall-queue": ['host', 'participant'],
110
+ "videowall-queue-video": ['host', 'participant'],
105
111
  },
106
112
  talkback: {
107
- watchTogether: ['participant'],
108
- videoWall: ['instructor', 'participant'],
113
+ "watchparty": ['participant'],
114
+ "commentary": ['participant'],
115
+ "videowall": ['host', 'participant'],
116
+ "videowall-queue": ['host', 'participant'],
117
+ "videowall-queue-video": ['host', 'participant'],
109
118
  },
110
119
  observer: {
111
- watchTogether: ['participant'],
112
- videoWall: ['participant'],
120
+ "watchparty": ['participant'],
121
+ "commentary": ['participant'],
122
+ "videowall": ['participant'],
123
+ "videowall-queue": ['participant'],
124
+ "videowall-queue-video": ['participant'],
113
125
  },
114
- instructor: {
115
- watchTogether: [],
116
- videoWall: [],
126
+ host: {
127
+ "watchparty": [],
128
+ "commentary": [],
129
+ "videowall": [],
130
+ "videowall-queue": [],
131
+ "videowall-queue-video": [],
117
132
  },
133
+ companionTV: {},
134
+ companionPhone: {},
118
135
  };
119
136
 
120
137
  constructor(constructId = null, type = 'reactooroom', options = {}) {
@@ -130,8 +147,6 @@ class RoomSession {
130
147
  this.userId = null;
131
148
  this.sessiontype = type;
132
149
  this.initialBitrate = 0;
133
- //TODO: remove this
134
- this.isMonitor = false; // currently used just for classroom context so monitor user only subscribes to participants and not trainer (for other monitor this flag is not necessary)
135
150
  this.recordingFilename = null;
136
151
  this.pluginName = RoomSession.sessionTypes[type];
137
152
  this.options = options;
@@ -155,9 +170,7 @@ class RoomSession {
155
170
  this._maxRetries = 3;
156
171
  this._keepAliveId = null;
157
172
  this._participants = [];
158
- this._observerIds = [];
159
- this._talkbackIds = [];
160
- this._instuctorId = null;
173
+ this._roomType = 'watchparty';
161
174
  this._isDataChannelOpen = false;
162
175
  this._abortController = null;
163
176
 
@@ -209,29 +222,11 @@ class RoomSession {
209
222
  }
210
223
 
211
224
  _participantShouldSubscribe(userId) {
212
- let allowedObservers = this._observerIds || [];
213
- let allowedTalkback = this._talkbackIds || [];
214
- let allowedInstructor = this._instuctorId || null;
215
- let localUserRole = 'participant';
216
- if(this.isMonitor) {
217
- localUserRole = 'monitor';
218
- } else if(allowedObservers.indexOf(this.userId) > -1) {
219
- localUserRole = 'observer';
220
- } else if(allowedTalkback.indexOf(this.userId) > -1) {
221
- localUserRole = 'talkback';
222
- } else if(this.userId === allowedInstructor) {
223
- localUserRole = 'instructor';
224
- }
225
- let remoteUserRole = 'participant';
226
- if(allowedObservers.indexOf(userId) > -1) {
227
- remoteUserRole = 'observer';
228
- } else if(allowedTalkback.indexOf(userId) > -1) {
229
- remoteUserRole = 'talkback';
230
- } else if(userId === allowedInstructor) {
231
- remoteUserRole = 'instructor';
232
- }
233
- let mode = allowedInstructor !== null ? 'videoWall' : 'watchTogether';
234
- return this.subscriptionRules[localUserRole][mode].indexOf(remoteUserRole) > -1;
225
+ const myUser = decodeJanusDisplay(this.display);
226
+ const remoteUser = decodeJanusDisplay(userId);
227
+ let localUserRole = myUser?.role || 'participant';
228
+ let remoteUserRole = remoteUser?.role || 'participant';
229
+ return this.subscriptionRules[localUserRole][(this._roomType || 'watchparty')].indexOf(remoteUserRole) > -1;
235
230
  }
236
231
 
237
232
  _getAddParticipantEventName(handleId) {
@@ -246,20 +241,25 @@ class RoomSession {
246
241
  });
247
242
  }
248
243
 
249
- let allowedTalkback = this._talkbackIds || [];
250
- let allowedObservers = this._observerIds || [];
251
- let allowedInstructor = this._instuctorId || null;
252
- let eventName = 'addRemoteParticipant';
253
- if(handle.userId === allowedInstructor) {
254
- eventName = 'addRemoteInstructor';
255
- }
256
- if (allowedTalkback.indexOf(handle.userId) > -1) {
257
- eventName = 'addRemoteTalkback';
244
+ const participantRole = decodeJanusDisplay(handle.userId)?.role;
245
+ switch (participantRole) {
246
+ case 'participant':
247
+ return 'addRemoteParticipant';
248
+ case 'talkback':
249
+ return 'addRemoteTalkback';
250
+ case 'monitor':
251
+ return 'addRemoteTalkback';
252
+ case 'observer':
253
+ return 'addRemoteObserver';
254
+ case 'host':
255
+ return 'addRemoteInstructor';
256
+ case 'companionTV':
257
+ return 'addRemoteCompanionTV';
258
+ case 'companionPhone':
259
+ return 'addRemoteCompanionPhone';
260
+ default:
261
+ return 'addRemoteParticipant';
258
262
  }
259
- if (allowedObservers.indexOf(handle.userId) > -1) {
260
- eventName = 'addRemoteObserver';
261
- }
262
- return eventName
263
263
  }
264
264
 
265
265
  _getRemoveParticipantEventName(handleId) {
@@ -274,20 +274,25 @@ class RoomSession {
274
274
  });
275
275
  }
276
276
 
277
- let allowedTalkback = this._talkbackIds || [];
278
- let allowedObservers = this._observerIds || [];
279
- let allowedInstructor = this._instuctorId || null;
280
- let eventName = 'removeRemoteParticipant';
281
- if(handle.userId === allowedInstructor) {
282
- eventName = 'removeRemoteInstructor';
283
- }
284
- if (allowedTalkback.indexOf(handle.userId) > -1) {
285
- eventName = 'removeRemoteTalkback';
277
+ const participantRole = decodeJanusDisplay(handle.userId)?.role;
278
+ switch (participantRole) {
279
+ case 'participant':
280
+ return 'removeRemoteParticipant';
281
+ case 'talkback':
282
+ return 'addRemoteTalkback';
283
+ case 'monitor':
284
+ return 'removeRemoteTalkback';
285
+ case 'observer':
286
+ return 'removeRemoteObserver';
287
+ case 'host':
288
+ return 'removeRemoteInstructor';
289
+ case 'companionTV':
290
+ return 'removeRemoteCompanionTV';
291
+ case 'companionPhone':
292
+ return 'removeRemoteCompanionPhone';
293
+ default:
294
+ return 'removeRemoteParticipant';
286
295
  }
287
- if (allowedObservers.indexOf(handle.userId) > -1) {
288
- eventName = 'removeRemoteObserver';
289
- }
290
- return eventName
291
296
  }
292
297
 
293
298
  sendMessage(handleId, message = {body: 'Example Body'}, dontWait = false, dontResolveOnAck = false) {
@@ -658,7 +663,7 @@ class RoomSession {
658
663
  this.emit(this._getAddParticipantEventName(handle.handleId), {
659
664
  tid: generateUUID(),
660
665
  id: handle.handleId,
661
- userId: handle.userId,
666
+ userId: decodeJanusDisplay(handle.userId)?.userId,
662
667
  stream: null,
663
668
  track: null,
664
669
  adding: false,
@@ -795,9 +800,9 @@ class RoomSession {
795
800
  this._isDataChannelOpen = false;
796
801
  this.isPublished = false;
797
802
  this.emit('published', {status: false, hasStream: false});
798
- this.emit('removeLocalParticipant', {id: handleId, userId: handle.userId});
803
+ this.emit('removeLocalParticipant', {id: handleId, userId: decodeJanusDisplay(handle.userId)?.userId});
799
804
  } else {
800
- this.emit(this._getRemoveParticipantEventName(handleId), {id: handleId, userId: handle.userId});
805
+ this.emit(this._getRemoveParticipantEventName(handleId), {id: handleId, userId: decodeJanusDisplay(handle.userId)?.userId});
801
806
  }
802
807
 
803
808
  if (removeHandle) {
@@ -928,7 +933,7 @@ class RoomSession {
928
933
  });
929
934
  }
930
935
 
931
- connect(roomId, pin, server, iceServers, token, display, userId, webrtcVersion = 0, initialBitrate = 0, isMonitor, recordingFilename) {
936
+ connect(roomId, pin, server, iceServers, token, display, userId, webrtcVersion = 0, initialBitrate = 0, recordingFilename) {
932
937
 
933
938
  if (this.isConnecting) {
934
939
  return Promise.reject({type: 'warning', id: 16, message: 'connection already in progress'});
@@ -949,7 +954,6 @@ class RoomSession {
949
954
  this.userId = userId;
950
955
  this.webrtcVersion = webrtcVersion;
951
956
  this.initialBitrate = initialBitrate;
952
- this.isMonitor = isMonitor;
953
957
  this.recordingFilename = recordingFilename;
954
958
  this.isConnecting = true;
955
959
  this.emit('joining', true);
@@ -1235,7 +1239,7 @@ class RoomSession {
1235
1239
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1236
1240
  tid: generateUUID(),
1237
1241
  id: handle.handleId,
1238
- userId: handle.userId,
1242
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1239
1243
  stream: config.stream,
1240
1244
  track: null,
1241
1245
  optional: true,
@@ -1256,7 +1260,7 @@ class RoomSession {
1256
1260
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1257
1261
  tid: generateUUID(),
1258
1262
  id: handle.handleId,
1259
- userId: handle.userId,
1263
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1260
1264
  stream: config.stream,
1261
1265
  track: null,
1262
1266
  optional: true,
@@ -1309,7 +1313,7 @@ class RoomSession {
1309
1313
  tid: generateUUID(),
1310
1314
  mid,
1311
1315
  id: handle.handleId,
1312
- userId: handle.userId,
1316
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1313
1317
  stream: config.stream,
1314
1318
  track: event.track,
1315
1319
  constructId: this.constructId,
@@ -1337,7 +1341,7 @@ class RoomSession {
1337
1341
  tid: generateUUID(),
1338
1342
  id: handle.handleId,
1339
1343
  mid,
1340
- userId: handle.userId,
1344
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1341
1345
  stream: config.stream,
1342
1346
  track: ev.target,
1343
1347
  constructId: this.constructId,
@@ -1363,7 +1367,7 @@ class RoomSession {
1363
1367
  this.emit('remoteTrackMuted', {
1364
1368
  id: handle.handleId,
1365
1369
  mid,
1366
- userId: handle.userId,
1370
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1367
1371
  stream: config.stream,
1368
1372
  kind: ev.target.kind,
1369
1373
  track: ev.target,
@@ -1384,7 +1388,7 @@ class RoomSession {
1384
1388
  this.emit('remoteTrackMuted', {
1385
1389
  id: handle.handleId,
1386
1390
  mid,
1387
- userId: handle.userId,
1391
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1388
1392
  stream: config.stream,
1389
1393
  kind: ev.target.kind,
1390
1394
  track: ev.target,
@@ -1988,7 +1992,7 @@ class RoomSession {
1988
1992
  this.emit('addLocalParticipant', {
1989
1993
  tid: generateUUID(),
1990
1994
  id: handle.handleId,
1991
- userId: handle.userId,
1995
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1992
1996
  track,
1993
1997
  stream: config.stream,
1994
1998
  adding: true,
@@ -2001,7 +2005,7 @@ class RoomSession {
2001
2005
  this.emit('addLocalParticipant', {
2002
2006
  tid:generateUUID(),
2003
2007
  id: handle.handleId,
2004
- userId: handle.userId,
2008
+ userId: decodeJanusDisplay(handle.userId)?.userId,
2005
2009
  track: ev.target,
2006
2010
  stream: config.stream,
2007
2011
  adding: false,
@@ -2018,7 +2022,7 @@ class RoomSession {
2018
2022
  this.emit('addLocalParticipant', {
2019
2023
  tid: generateUUID(),
2020
2024
  id: handle.handleId,
2021
- userId: handle.userId,
2025
+ userId: decodeJanusDisplay(handle.userId)?.userId,
2022
2026
  stream: null,
2023
2027
  adding: false,
2024
2028
  constructId: this.constructId,
@@ -2099,22 +2103,9 @@ class RoomSession {
2099
2103
  this.emit('localMuted', {type: 'video', value: this.isVideoMuted, mid});
2100
2104
  }
2101
2105
 
2102
- setInstructorId(instructorId = null) {
2103
- this._instuctorId = instructorId;
2104
- this.emit('instructorId', this._instuctorId);
2105
- return this._instuctorId;
2106
- }
2107
-
2108
- setObserverIds(observerIds = []) {
2109
- this._observerIds = observerIds;
2110
- this.emit('observerIds', this._observerIds);
2111
- return this._observerIds;
2112
- }
2113
-
2114
- setTalkbackIds(talkbackIds = []) {
2115
- this._talkbackIds = talkbackIds;
2116
- this.emit('talkbackIds', this._talkbackIds);
2117
- return this._talkbackIds;
2106
+ setRoomType(type = 'watchparty') {
2107
+ this._roomType = type;
2108
+ return this._roomType;
2118
2109
  }
2119
2110
 
2120
2111
  }
@@ -27,6 +27,26 @@ let generateUUID = function () {
27
27
  });
28
28
  };
29
29
 
30
+
31
+ const janusDisplayDelimiter = ',';
32
+ const decodeJanusDisplay = display => {
33
+ let output = { userId: null, role: "participant", start: Date.now(), displayName: "?" };
34
+ if(display && typeof display === "string") {
35
+ if(display.indexOf(janusDisplayDelimiter) >= 0) {
36
+ let values = display
37
+ .split( new RegExp(`\\${janusDisplayDelimiter}(?=(?:(?:[^"]*"){2})*[^"]*$)`, 'mi') )
38
+ .map(v => (v && v.startsWith('"') || v.endsWith('"')) ? v.substring(1, v.length-1) : ( /^\d+$/.test(v) ? parseInt(v) : v ));
39
+ Object.keys(output).forEach((key, i) => values[i] ? output[key] = values[i] : null);
40
+ } else {
41
+ output.userId = display;
42
+ }
43
+ return output;
44
+ } else if(display && typeof display === "object") {
45
+ return Object.assign({}, output, display);
46
+ }
47
+ return null;
48
+ }
49
+
30
50
  const setExactTimeout = function(callback, duration, resolution) {
31
51
  const start = (new Date()).getTime();
32
52
  const timeout = setInterval(function(){
@@ -43,4 +63,6 @@ const clearExactTimeout = function(timeout) {
43
63
  clearInterval(timeout);
44
64
  };
45
65
 
46
- export {wait, getBrowserFingerprint, generateUUID, setExactTimeout, clearExactTimeout}
66
+
67
+
68
+ export {wait, getBrowserFingerprint, generateUUID, decodeJanusDisplay, setExactTimeout, clearExactTimeout}