@reactoo/watchtogether-sdk-js 2.5.5 → 2.5.9

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.5",
3
+ "version": "2.5.9",
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
-
37
- // TODO: this timeout is a hotfix and should be sorted differently
36
+
37
+ // TODO: this doesnt seem to be fixable until we switch to differen type of messaging
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
- }, 1000);
43
+ }, 2000);
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,42 +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]) => Promise.all([roomData, userData, this.setRoomVars()]))
96
- .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
- .then(([roomData, userData, _]) => {
98
-
95
+ .then(([roomData, userData]) => {
99
96
  // Happens when we reroute user to a different room
100
-
101
97
  if(roomData?.data?.reactooRoomId) {
102
98
  roomId = roomData.data.reactooRoomId
103
99
  }
104
-
100
+ return Promise.all([roomData, userData])
101
+ })
102
+ .then(([roomData, userData]) => Promise.all([roomData, userData, this.setRoomVars()]))
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)]))
104
+ .then(([roomData, userData, _]) => {
105
105
  return roomData.data
106
106
  })
107
107
  .finally(() => {
108
108
  emitter.emit('connecting', false);
109
109
  })
110
-
110
+
111
111
  },
112
-
112
+
113
113
  disconnect: function (dontWaitForResponses) {
114
114
  clearTimeout(alpTimeoutId);
115
115
  return room.disconnect(dontWaitForResponses);
116
116
  },
117
-
117
+
118
118
  //TODO: refactor restart method
119
119
  restart: function (isObserver = false) {
120
-
120
+
121
121
  emitter.emit('reconnecting', true);
122
122
  room.isRestarting = true;
123
-
123
+
124
124
  let wasPublished = room._isPublished;
125
125
  let handle = room._getHandle(room.handleId);
126
126
  let stream = null;
127
127
  if (handle?.webrtcStuff?.stream && wasPublished) {
128
128
  stream = handle.webrtcStuff.stream;
129
129
  }
130
-
130
+
131
131
  return this.disconnect()
132
132
  .then(() => wait(1000)) //TODO: remove 1000ms wait by waiting for proper events from janus
133
133
  .then(() => this.connect())
@@ -150,17 +150,17 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
150
150
  emitter.emit('error', {type: 'error', id: 26, message: 'reconnecting failed', data: error});
151
151
  return Promise.reject(0);
152
152
  });
153
-
153
+
154
154
  },
155
-
155
+
156
156
  getStats: function (type = null) {
157
157
  return room._getStats(type)
158
158
  },
159
-
159
+
160
160
  getRoomParticipants: function () {
161
161
  return room._participants;
162
162
  },
163
-
163
+
164
164
  __parseDataEvents: function (msg = {}) {
165
165
  if (msg.videoroom === 'message') {
166
166
  if (msg.action === 'pending_shutdown' || msg.action === 'shutting_down') {
@@ -171,7 +171,6 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
171
171
  } else if (msg.action === 'user_update_displayname' || msg.action === 'user_update_avatar' || msg.action === 'user_update_customattributes' || msg.action === 'user_update_privateattributes') {
172
172
  emitter.emit('userUpdate', msg.text);
173
173
  } else if (msg.action === 'observer_connecting' || msg.action === 'talkback_connecting' || msg.action === 'instructor_connecting') {
174
-
175
174
  this.setRoomVars(null, msg.action === 'observer_connecting').catch(e => {
176
175
  room._log('Setting observers failed, this will cause issues', e);
177
176
  });
@@ -201,11 +200,11 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
201
200
  return false;
202
201
  }
203
202
  },
204
-
203
+
205
204
  attachPlayer: function (type, inputs) {
206
-
205
+
207
206
  this.detachPlayer();
208
-
207
+
209
208
  if (type === 'hlsjs') {
210
209
  this.syncModule = syncHlsJs({room, wt, roomSession: this, emitter});
211
210
  if (this.syncModule.__events) {
@@ -276,7 +275,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
276
275
  room._log('Synchronisation type not recognised');
277
276
  }
278
277
  },
279
-
278
+
280
279
  detachPlayer: function () {
281
280
  if (this.syncModule) {
282
281
  this.playerInterface = null;
@@ -287,24 +286,23 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
287
286
  this.syncModule = null;
288
287
  }
289
288
  },
290
-
289
+
291
290
  setRoomVars: (observerIds = [], emit = true) => {
292
291
  return wt.room.getRoomById(roomId, pinHash)
293
292
  .then(r => {
294
-
295
293
  if (emit) {
296
294
  // emiting "fake" playerSource event
297
295
  //TODO: somehow push into sync modules instead
298
296
  emitter.emit('changePlayerSource', r.data.wtChannelId, true);
299
297
  }
300
-
298
+
301
299
  // setting observers userId's so we can ignore them when creating participant
302
300
  room.setObserverIds(r.data.allowedObservers);
303
301
  room.setTalkbackIds(r.data.allowedTalkbacks);
304
302
  room.setInstructorId(r.data.classroom?.instructorUserId);
305
303
  });
306
304
  },
307
-
305
+
308
306
  publishLocal: function (stream = null, {
309
307
  keepAudio = false,
310
308
  keepVideo = false,
@@ -315,25 +313,25 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
315
313
  ? room.publishLocal(stream, {keepAudio, keepVideo})
316
314
  : wt.utils.getUserStream(askVideo).then(stream => room.publishLocal(stream)))
317
315
  },
318
-
316
+
319
317
  unpublishLocal: () => {
320
318
  return room.unpublishLocal();
321
319
  },
322
-
320
+
323
321
  toggleAudio: (value) => {
324
322
  return room.toggleAudio(value);
325
323
  },
326
-
324
+
327
325
  toggleVideo: () => {
328
326
  return room.toggleVideo();
329
327
  },
330
-
328
+
331
329
  setBitrateCap: (bitrate) => {
332
-
330
+
333
331
  if(isInstructor) {
334
332
  return;
335
333
  }
336
-
334
+
337
335
  return room.sendMessage(room.handleId, {
338
336
  "body": {
339
337
  "request": "configure",
@@ -341,7 +339,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
341
339
  }
342
340
  }).catch(() => null)
343
341
  },
344
-
342
+
345
343
  switchChannel: (channelId) => {
346
344
  return room.sendMessage(room.handleId, {
347
345
  body: {
@@ -354,7 +352,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
354
352
  }
355
353
  });
356
354
  },
357
-
355
+
358
356
  sendSystemMessage: (action, value = {}, to, set_master) => {
359
357
  return room.sendMessage(room.handleId, {
360
358
  body: {
@@ -368,7 +366,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
368
366
  }
369
367
  });
370
368
  },
371
-
369
+
372
370
  sendChatMessage: (text, to) => {
373
371
  return room.sendMessage(room.handleId, {
374
372
  body: {
@@ -381,26 +379,26 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
381
379
  }
382
380
  });
383
381
  },
384
-
382
+
385
383
  __requestMuteStatus: function () {
386
384
  this.sendSystemMessage('remote_muted_request');
387
385
  },
388
-
386
+
389
387
  __sendMuteStatus: function () {
390
388
  this.sendSystemMessage('remote_muted', {type: 'video', value: room.isVideoMuted});
391
389
  this.sendSystemMessage('remote_muted', {type: 'audio', value: room.isAudioMuted});
392
390
  },
393
-
391
+
394
392
  $on: (key, callback, that) => {
395
393
  emitter.on(key, callback, that || this);
396
394
  room.on(key, callback, that || this);
397
395
  },
398
-
396
+
399
397
  $off: (key, callback, that) => {
400
398
  emitter.on(key, callback, that || this);
401
399
  room.on(key, callback, that || this);
402
400
  },
403
-
401
+
404
402
  $clear: function () {
405
403
  room.clear();
406
404
  emitter.clear();
@@ -12,10 +12,8 @@ class Room {
12
12
  this.safariVp8 = false;
13
13
  this.browser = adapter.browserDetails.browser;
14
14
  this.browserDetails = adapter.browserDetails;
15
-
16
- this.isWebrtcSupported = Room.isWebrtcSupported();
15
+ this.webrtcSupported = Room.isWebrtcSupported();
17
16
  this.safariVp8TestPromise = Room.testSafariVp8();
18
-
19
17
  this.safariVp8 = null;
20
18
  this.safariVp8TestPromise.then(safariVp8 => {
21
19
  this.safariVp8 = safariVp8;
@@ -103,6 +101,9 @@ class RoomSession {
103
101
  };
104
102
 
105
103
  constructor(constructId = null, type = 'reactooroom', debug, options = {}) {
104
+
105
+ Object.assign(this, emitter());
106
+
106
107
  this.server = null;
107
108
  this.iceServers = null;
108
109
  this.token = null;
@@ -124,18 +125,15 @@ class RoomSession {
124
125
  },
125
126
  options
126
127
  };
127
-
128
- Object.assign(this, emitter());
129
-
130
128
  this.id = null;
131
129
  this.privateId = null;
132
-
133
130
  this.constructId = constructId || RoomSession.randomString(16);
134
131
  this.sessionId = null;
135
132
  this.handleId = null;
136
133
  this.ws = null;
137
134
  this.isRestarting = false;
138
-
135
+
136
+ //TODO: do it better
139
137
  // double click prevention
140
138
  this.connectingPromise = null;
141
139
  this.disconnectingPromise = null;
@@ -152,14 +150,11 @@ class RoomSession {
152
150
  this._isStreaming = false;
153
151
  this._isPublished = false;
154
152
  this._isDataChannelOpen = false;
155
-
156
153
  this.isAudioMuted = false;
157
154
  this.isVideoMuted = false;
158
155
  this.isVideoEnabled = false;
159
156
  this.isAudioEnabed = false;
160
-
161
157
  this.isUnifiedPlan = RoomSession.checkUnifiedPlan();
162
-
163
158
  this._log = RoomSession.noop;
164
159
  if (this.options.debug) {
165
160
  this._enableDebug();
@@ -682,6 +677,7 @@ class RoomSession {
682
677
  track: null,
683
678
  adding: false,
684
679
  constructId: this.constructId,
680
+ metaData: this.options.metaData,
685
681
  hasAudioTrack: false,
686
682
  hasVideoTrack: false
687
683
  });
@@ -1271,6 +1267,7 @@ class RoomSession {
1271
1267
  stream: config.stream,
1272
1268
  track: event.track,
1273
1269
  constructId: this.constructId,
1270
+ metaData: this.options.metaData,
1274
1271
  adding: true,
1275
1272
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1276
1273
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
@@ -1305,6 +1302,7 @@ class RoomSession {
1305
1302
  stream: config.stream,
1306
1303
  track: ev.target,
1307
1304
  constructId: this.constructId,
1305
+ metaData: this.options.metaData,
1308
1306
  adding: false,
1309
1307
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1310
1308
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)