@reactoo/watchtogether-sdk-js 2.5.3 → 2.5.7

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.
@@ -70,10 +70,10 @@
70
70
  document.getElementById('join-room').setAttribute('disabled', true);
71
71
  document.getElementById('joined-participants-count').value = joinedParticipantsCount;
72
72
 
73
- // TODO - toto tu na konci nebude. Je to len preistotu, aby som znova nezhodil server
74
- if (participantsCount > 4) {
75
- participantsCount = 4;
76
- }
73
+ // // TODO - toto tu na konci nebude. Je to len preistotu, aby som znova nezhodil server
74
+ // if (participantsCount > 4) {
75
+ // participantsCount = 4;
76
+ // }
77
77
 
78
78
  participantsData = Array(participantsCount).fill(0).map((_, i) => {
79
79
  const canvas = document.createElement('canvas');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.5.3",
3
+ "version": "2.5.7",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -18,40 +18,40 @@ import syncDaznDash from "../modules/sync-modules/sync-dazn-dash";
18
18
  import syncUniversal from "../modules/sync-modules/sync-universal";
19
19
 
20
20
  let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructor}, room, wt) {
21
-
21
+
22
22
  let publicCustomEvents = ['changePlayerSource', 'chatMessage', 'userUpdate', 'reconnecting', 'connecting', 'remoteMuted', 'scaling'];
23
-
23
+
24
24
  const addEvents = (events) => {
25
25
  publicCustomEvents = [...publicCustomEvents, ...events];
26
26
  };
27
27
  const removeEvents = (events) => {
28
28
  publicCustomEvents = publicCustomEvents.filter(ev => events.indexOf(ev) === -1);
29
29
  };
30
-
30
+
31
31
  const emitter = _emitter_();
32
32
  let alpTimeoutId = null;
33
33
  let ___; // return object
34
-
34
+
35
35
  room.on('addLocalParticipant', () => {
36
-
36
+
37
37
  // TODO: this timeout is a hotfix and should be sorted differently
38
38
  // At some random case we don't get message back if we don't wait
39
-
39
+
40
40
  clearTimeout(alpTimeoutId);
41
41
  alpTimeoutId = setTimeout(() => {
42
42
  ___.__requestMuteStatus();
43
43
  }, 1000);
44
44
  });
45
-
45
+
46
46
  room.on('localMuted', ({type, value}) => {
47
47
  ___.sendSystemMessage('remote_muted', {type, value})
48
48
  });
49
49
  room.on('data', (data) => {
50
50
  ___.__parseDataEvents(data);
51
51
  });
52
-
52
+
53
53
  return (___ = {
54
-
54
+
55
55
  syncModule: null,
56
56
  playerInterface: null,
57
57
 
@@ -77,11 +77,11 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
77
77
  return true;
78
78
  });
79
79
  },
80
-
80
+
81
81
  iceRestart: function () {
82
82
  return room._iceRestart(room.handleId);
83
83
  },
84
-
84
+
85
85
  connect: function () {
86
86
  emitter.emit('connecting', true);
87
87
  clearTimeout(alpTimeoutId);
@@ -92,35 +92,42 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
92
92
  isMonitor,
93
93
  isInstructor
94
94
  }), wt.user.getUserSelf()])
95
+ .then(([roomData, userData]) => {
96
+ // Happens when we reroute user to a different room
97
+ if(roomData?.data?.reactooRoomId) {
98
+ roomId = roomData.data.reactooRoomId
99
+ }
100
+ return Promise.all([roomData, userData])
101
+ })
95
102
  .then(([roomData, userData]) => Promise.all([roomData, userData, this.setRoomVars()]))
96
103
  .then(([roomData, userData, _]) => Promise.all([roomData, userData, room.connect(roomData.data.roomId, roomData.data.pin, roomData.data.href, roomData.data.iceServers, roomData.data.accessToken, (isMonitor || isInstructor || isTalkback) ? roomData.data.userId : userData.data._id, roomData.data.webrtcVersion, (roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0), isMonitor, roomData.data.recordingFilename)]))
97
104
  .then(([roomData, userData, _]) => {
98
- return roomData
105
+ return roomData.data
99
106
  })
100
107
  .finally(() => {
101
108
  emitter.emit('connecting', false);
102
109
  })
103
-
110
+
104
111
  },
105
-
112
+
106
113
  disconnect: function (dontWaitForResponses) {
107
114
  clearTimeout(alpTimeoutId);
108
115
  return room.disconnect(dontWaitForResponses);
109
116
  },
110
-
117
+
111
118
  //TODO: refactor restart method
112
119
  restart: function (isObserver = false) {
113
-
120
+
114
121
  emitter.emit('reconnecting', true);
115
122
  room.isRestarting = true;
116
-
123
+
117
124
  let wasPublished = room._isPublished;
118
125
  let handle = room._getHandle(room.handleId);
119
126
  let stream = null;
120
127
  if (handle?.webrtcStuff?.stream && wasPublished) {
121
128
  stream = handle.webrtcStuff.stream;
122
129
  }
123
-
130
+
124
131
  return this.disconnect()
125
132
  .then(() => wait(1000)) //TODO: remove 1000ms wait by waiting for proper events from janus
126
133
  .then(() => this.connect())
@@ -143,17 +150,17 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
143
150
  emitter.emit('error', {type: 'error', id: 26, message: 'reconnecting failed', data: error});
144
151
  return Promise.reject(0);
145
152
  });
146
-
153
+
147
154
  },
148
-
155
+
149
156
  getStats: function (type = null) {
150
157
  return room._getStats(type)
151
158
  },
152
-
159
+
153
160
  getRoomParticipants: function () {
154
161
  return room._participants;
155
162
  },
156
-
163
+
157
164
  __parseDataEvents: function (msg = {}) {
158
165
  if (msg.videoroom === 'message') {
159
166
  if (msg.action === 'pending_shutdown' || msg.action === 'shutting_down') {
@@ -194,11 +201,11 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
194
201
  return false;
195
202
  }
196
203
  },
197
-
204
+
198
205
  attachPlayer: function (type, inputs) {
199
-
206
+
200
207
  this.detachPlayer();
201
-
208
+
202
209
  if (type === 'hlsjs') {
203
210
  this.syncModule = syncHlsJs({room, wt, roomSession: this, emitter});
204
211
  if (this.syncModule.__events) {
@@ -269,7 +276,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
269
276
  room._log('Synchronisation type not recognised');
270
277
  }
271
278
  },
272
-
279
+
273
280
  detachPlayer: function () {
274
281
  if (this.syncModule) {
275
282
  this.playerInterface = null;
@@ -280,24 +287,24 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
280
287
  this.syncModule = null;
281
288
  }
282
289
  },
283
-
290
+
284
291
  setRoomVars: (observerIds = [], emit = true) => {
285
292
  return wt.room.getRoomById(roomId, pinHash)
286
293
  .then(r => {
287
-
294
+
288
295
  if (emit) {
289
296
  // emiting "fake" playerSource event
290
297
  //TODO: somehow push into sync modules instead
291
298
  emitter.emit('changePlayerSource', r.data.wtChannelId, true);
292
299
  }
293
-
300
+
294
301
  // setting observers userId's so we can ignore them when creating participant
295
302
  room.setObserverIds(r.data.allowedObservers);
296
303
  room.setTalkbackIds(r.data.allowedTalkbacks);
297
304
  room.setInstructorId(r.data.classroom?.instructorUserId);
298
305
  });
299
306
  },
300
-
307
+
301
308
  publishLocal: function (stream = null, {
302
309
  keepAudio = false,
303
310
  keepVideo = false,
@@ -308,25 +315,25 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
308
315
  ? room.publishLocal(stream, {keepAudio, keepVideo})
309
316
  : wt.utils.getUserStream(askVideo).then(stream => room.publishLocal(stream)))
310
317
  },
311
-
318
+
312
319
  unpublishLocal: () => {
313
320
  return room.unpublishLocal();
314
321
  },
315
-
322
+
316
323
  toggleAudio: (value) => {
317
324
  return room.toggleAudio(value);
318
325
  },
319
-
326
+
320
327
  toggleVideo: () => {
321
328
  return room.toggleVideo();
322
329
  },
323
-
330
+
324
331
  setBitrateCap: (bitrate) => {
325
-
332
+
326
333
  if(isInstructor) {
327
334
  return;
328
335
  }
329
-
336
+
330
337
  return room.sendMessage(room.handleId, {
331
338
  "body": {
332
339
  "request": "configure",
@@ -334,7 +341,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
334
341
  }
335
342
  }).catch(() => null)
336
343
  },
337
-
344
+
338
345
  switchChannel: (channelId) => {
339
346
  return room.sendMessage(room.handleId, {
340
347
  body: {
@@ -347,7 +354,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
347
354
  }
348
355
  });
349
356
  },
350
-
357
+
351
358
  sendSystemMessage: (action, value = {}, to, set_master) => {
352
359
  return room.sendMessage(room.handleId, {
353
360
  body: {
@@ -361,7 +368,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
361
368
  }
362
369
  });
363
370
  },
364
-
371
+
365
372
  sendChatMessage: (text, to) => {
366
373
  return room.sendMessage(room.handleId, {
367
374
  body: {
@@ -374,26 +381,26 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
374
381
  }
375
382
  });
376
383
  },
377
-
384
+
378
385
  __requestMuteStatus: function () {
379
386
  this.sendSystemMessage('remote_muted_request');
380
387
  },
381
-
388
+
382
389
  __sendMuteStatus: function () {
383
390
  this.sendSystemMessage('remote_muted', {type: 'video', value: room.isVideoMuted});
384
391
  this.sendSystemMessage('remote_muted', {type: 'audio', value: room.isAudioMuted});
385
392
  },
386
-
393
+
387
394
  $on: (key, callback, that) => {
388
395
  emitter.on(key, callback, that || this);
389
396
  room.on(key, callback, that || this);
390
397
  },
391
-
398
+
392
399
  $off: (key, callback, that) => {
393
400
  emitter.on(key, callback, that || this);
394
401
  room.on(key, callback, that || this);
395
402
  },
396
-
403
+
397
404
  $clear: function () {
398
405
  room.clear();
399
406
  emitter.clear();
@@ -103,6 +103,9 @@ class RoomSession {
103
103
  };
104
104
 
105
105
  constructor(constructId = null, type = 'reactooroom', debug, options = {}) {
106
+
107
+ Object.assign(this, emitter());
108
+
106
109
  this.server = null;
107
110
  this.iceServers = null;
108
111
  this.token = null;
@@ -124,18 +127,15 @@ class RoomSession {
124
127
  },
125
128
  options
126
129
  };
127
-
128
- Object.assign(this, emitter());
129
-
130
130
  this.id = null;
131
131
  this.privateId = null;
132
-
133
132
  this.constructId = constructId || RoomSession.randomString(16);
134
133
  this.sessionId = null;
135
134
  this.handleId = null;
136
135
  this.ws = null;
137
136
  this.isRestarting = false;
138
-
137
+
138
+ //TODO: do it better
139
139
  // double click prevention
140
140
  this.connectingPromise = null;
141
141
  this.disconnectingPromise = null;
@@ -152,14 +152,11 @@ class RoomSession {
152
152
  this._isStreaming = false;
153
153
  this._isPublished = false;
154
154
  this._isDataChannelOpen = false;
155
-
156
155
  this.isAudioMuted = false;
157
156
  this.isVideoMuted = false;
158
157
  this.isVideoEnabled = false;
159
158
  this.isAudioEnabed = false;
160
-
161
159
  this.isUnifiedPlan = RoomSession.checkUnifiedPlan();
162
-
163
160
  this._log = RoomSession.noop;
164
161
  if (this.options.debug) {
165
162
  this._enableDebug();
@@ -682,6 +679,7 @@ class RoomSession {
682
679
  track: null,
683
680
  adding: false,
684
681
  constructId: this.constructId,
682
+ metaData: this.options.metaData,
685
683
  hasAudioTrack: false,
686
684
  hasVideoTrack: false
687
685
  });
@@ -1271,6 +1269,7 @@ class RoomSession {
1271
1269
  stream: config.stream,
1272
1270
  track: event.track,
1273
1271
  constructId: this.constructId,
1272
+ metaData: this.options.metaData,
1274
1273
  adding: true,
1275
1274
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1276
1275
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
@@ -1305,6 +1304,7 @@ class RoomSession {
1305
1304
  stream: config.stream,
1306
1305
  track: ev.target,
1307
1306
  constructId: this.constructId,
1307
+ metaData: this.options.metaData,
1308
1308
  adding: false,
1309
1309
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1310
1310
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)