@reactoo/watchtogether-sdk-js 2.5.4 → 2.5.8

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.4",
3
+ "version": "2.5.8",
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') {
@@ -201,11 +201,11 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
201
201
  return false;
202
202
  }
203
203
  },
204
-
204
+
205
205
  attachPlayer: function (type, inputs) {
206
-
206
+
207
207
  this.detachPlayer();
208
-
208
+
209
209
  if (type === 'hlsjs') {
210
210
  this.syncModule = syncHlsJs({room, wt, roomSession: this, emitter});
211
211
  if (this.syncModule.__events) {
@@ -276,7 +276,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
276
276
  room._log('Synchronisation type not recognised');
277
277
  }
278
278
  },
279
-
279
+
280
280
  detachPlayer: function () {
281
281
  if (this.syncModule) {
282
282
  this.playerInterface = null;
@@ -287,24 +287,24 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
287
287
  this.syncModule = null;
288
288
  }
289
289
  },
290
-
290
+
291
291
  setRoomVars: (observerIds = [], emit = true) => {
292
292
  return wt.room.getRoomById(roomId, pinHash)
293
293
  .then(r => {
294
-
294
+
295
295
  if (emit) {
296
296
  // emiting "fake" playerSource event
297
297
  //TODO: somehow push into sync modules instead
298
298
  emitter.emit('changePlayerSource', r.data.wtChannelId, true);
299
299
  }
300
-
300
+
301
301
  // setting observers userId's so we can ignore them when creating participant
302
302
  room.setObserverIds(r.data.allowedObservers);
303
303
  room.setTalkbackIds(r.data.allowedTalkbacks);
304
304
  room.setInstructorId(r.data.classroom?.instructorUserId);
305
305
  });
306
306
  },
307
-
307
+
308
308
  publishLocal: function (stream = null, {
309
309
  keepAudio = false,
310
310
  keepVideo = false,
@@ -315,25 +315,25 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
315
315
  ? room.publishLocal(stream, {keepAudio, keepVideo})
316
316
  : wt.utils.getUserStream(askVideo).then(stream => room.publishLocal(stream)))
317
317
  },
318
-
318
+
319
319
  unpublishLocal: () => {
320
320
  return room.unpublishLocal();
321
321
  },
322
-
322
+
323
323
  toggleAudio: (value) => {
324
324
  return room.toggleAudio(value);
325
325
  },
326
-
326
+
327
327
  toggleVideo: () => {
328
328
  return room.toggleVideo();
329
329
  },
330
-
330
+
331
331
  setBitrateCap: (bitrate) => {
332
-
332
+
333
333
  if(isInstructor) {
334
334
  return;
335
335
  }
336
-
336
+
337
337
  return room.sendMessage(room.handleId, {
338
338
  "body": {
339
339
  "request": "configure",
@@ -341,7 +341,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
341
341
  }
342
342
  }).catch(() => null)
343
343
  },
344
-
344
+
345
345
  switchChannel: (channelId) => {
346
346
  return room.sendMessage(room.handleId, {
347
347
  body: {
@@ -354,7 +354,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
354
354
  }
355
355
  });
356
356
  },
357
-
357
+
358
358
  sendSystemMessage: (action, value = {}, to, set_master) => {
359
359
  return room.sendMessage(room.handleId, {
360
360
  body: {
@@ -368,7 +368,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
368
368
  }
369
369
  });
370
370
  },
371
-
371
+
372
372
  sendChatMessage: (text, to) => {
373
373
  return room.sendMessage(room.handleId, {
374
374
  body: {
@@ -381,26 +381,26 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
381
381
  }
382
382
  });
383
383
  },
384
-
384
+
385
385
  __requestMuteStatus: function () {
386
386
  this.sendSystemMessage('remote_muted_request');
387
387
  },
388
-
388
+
389
389
  __sendMuteStatus: function () {
390
390
  this.sendSystemMessage('remote_muted', {type: 'video', value: room.isVideoMuted});
391
391
  this.sendSystemMessage('remote_muted', {type: 'audio', value: room.isAudioMuted});
392
392
  },
393
-
393
+
394
394
  $on: (key, callback, that) => {
395
395
  emitter.on(key, callback, that || this);
396
396
  room.on(key, callback, that || this);
397
397
  },
398
-
398
+
399
399
  $off: (key, callback, that) => {
400
400
  emitter.on(key, callback, that || this);
401
401
  room.on(key, callback, that || this);
402
402
  },
403
-
403
+
404
404
  $clear: function () {
405
405
  room.clear();
406
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)