@reactoo/watchtogether-sdk-js 2.6.44 → 2.6.46

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.
@@ -285,7 +285,7 @@
285
285
  });
286
286
 
287
287
  session.$on('error', (e) => {
288
- console.log(e);
288
+ console.error(e);
289
289
  if(e && e.type === 'error') {
290
290
  session.disconnect().catch(e => console.log(e));
291
291
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.6.44",
3
+ "version": "2.6.46",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -203,8 +203,8 @@ class RoomSession {
203
203
  this._maxRetries = 5;
204
204
  this._keepAliveId = null;
205
205
  this._participants = [];
206
- this._talkIntercomGroups = [];
207
- this._listenIntercomGroups = [];
206
+ this._talkIntercomGroups = ['all'];
207
+ this._listenIntercomGroups = ['all'];
208
208
  this._roomType = 'watchparty';
209
209
  this._isDataChannelOpen = false;
210
210
  this._abortController = null;
@@ -380,7 +380,7 @@ class RoomSession {
380
380
  messageTimeoutId = setTimeout(() => {
381
381
  this.ws.removeEventListener('message', parseResponse);
382
382
  this._abortController.signal.removeEventListener('abort', abortResponse);
383
- reject({type: 'error', id: 3, message: 'send timeout', data: requestData});
383
+ reject({type: 'warning', id: 3, message: 'send timeout', data: requestData});
384
384
  }, 10000);
385
385
 
386
386
  this._abortController.signal.addEventListener('abort', abortResponse);
@@ -556,6 +556,7 @@ class RoomSession {
556
556
  "room": this.roomId,
557
557
  "ptype": "subscriber",
558
558
  "private_id": this.privateId,
559
+ //TODO: check which groups we want to subscribe to
559
560
  streams: streams.filter(s => !s.disabled).map(stream => ({feed: stream.id, mid: stream.mid})),
560
561
  //"feed": id,
561
562
  ...(this.webrtcVersion > 1000 ? {id: this.userId} : {}),
@@ -590,15 +591,17 @@ class RoomSession {
590
591
  let handle = this._getHandle(null, id);
591
592
  if(handle) {
592
593
 
593
- //description: 'camera0'
594
+ //TODO: check which groups we want to subscribe to
594
595
  const _sfn = (stream) => {
595
596
  if(stream.type === 'data') {
596
597
  return true;
597
598
  }
599
+ // if stream.description is not set, we assume it's a data stream, and we shouldn't get here at all
600
+ const source = stream.description ? JSON.parse(stream.description)?.source : undefined;
598
601
  if(!this.options?.restrictSources?.length) {
599
602
  return true
600
603
  }
601
- else if(this.options?.restrictSources?.includes(stream.description)) {
604
+ else if(this.options?.restrictSources?.includes(source)) {
602
605
  return true;
603
606
  }
604
607
  return false;
@@ -627,6 +630,7 @@ class RoomSession {
627
630
  "room": this.roomId,
628
631
  "ptype": "subscriber",
629
632
  "private_id": this.privateId,
633
+ //TODO: check which groups we want to subscribe to
630
634
  streams: streams.filter(s => !s.disabled).map(stream => ({feed: stream.id, mid: stream.mid})),
631
635
  ...(this.webrtcVersion > 1000 ? {id: this.userId} : {}),
632
636
  pin: this.pin
@@ -941,7 +945,6 @@ class RoomSession {
941
945
  dtmfSender: null,
942
946
  trickle: true,
943
947
  iceDone: false,
944
- isIceRestarting: false
945
948
  }
946
949
  };
947
950
  this._participants.push(handle);
@@ -986,12 +989,15 @@ class RoomSession {
986
989
  if(tItem.active === false) {
987
990
  return;
988
991
  }
989
- if(!config.streamMap[tItem.feed_description]) {
990
- config.streamMap[tItem.feed_description] = [];
992
+
993
+ const source = JSON.parse(tItem.feed_description)?.source;
994
+
995
+ if(!config.streamMap[source]) {
996
+ config.streamMap[source] = [];
991
997
  }
992
998
  let trackId = config.pc.getTransceivers().find(t => t.mid === tItem.mid).receiver.track.id;
993
999
  if(trackId) {
994
- config.streamMap[tItem.feed_description].push(trackId);
1000
+ config.streamMap[source].push(trackId);
995
1001
  }
996
1002
  })
997
1003
  }
@@ -1397,9 +1403,9 @@ class RoomSession {
1397
1403
  };
1398
1404
 
1399
1405
  config.pc.onconnectionstatechange = () => {
1400
- //TODO: check if this isnt fired prematurely when we switch internet connection
1401
1406
  if (config.pc.connectionState === 'failed') {
1402
1407
  this._log('connectionState failed');
1408
+ this._iceRestart(handleId);
1403
1409
  }
1404
1410
  this.emit('connectionState', [handleId, handleId === this.handleId, config.pc.connectionState]);
1405
1411
  if(handleId !== this.handleId && config.pc.connectionState === 'connected') {
@@ -1694,14 +1700,8 @@ class RoomSession {
1694
1700
  }
1695
1701
  var config = handle.webrtcStuff;
1696
1702
 
1697
- // Already restarting;
1698
- if (config.isIceRestarting) {
1699
- return;
1700
- }
1701
-
1702
1703
  if (this.handleId === handleId) {
1703
1704
  this._log('Performing local ICE restart');
1704
- config.isIceRestarting = true;
1705
1705
  let hasAudio = !!(config.stream && config.stream.getAudioTracks().length > 0);
1706
1706
  let hasVideo = !!(config.stream && config.stream.getVideoTracks().length > 0);
1707
1707
  this._createAO('offer', handleId, true )
@@ -1715,23 +1715,17 @@ class RoomSession {
1715
1715
  });
1716
1716
  })
1717
1717
  .then(r => {
1718
- config.isIceRestarting = false;
1719
1718
  this._log('ICE restart success');
1720
1719
  })
1721
1720
  .catch((e) => {
1722
- config.isIceRestarting = false;
1723
1721
  this.emit('error', {type: 'warning', id: 28, message: 'iceRestart failed', data: e});
1724
1722
  });
1725
1723
  } else {
1726
1724
  this._log('Performing remote ICE restart', handleId);
1727
- config.isIceRestarting = true;
1728
1725
  return this.sendMessage(handleId, {
1729
1726
  body: {"request": "configure", "restart": true}
1730
1727
  }).then(() => {
1731
- config.isIceRestarting = false;
1732
- }).catch(() => {
1733
- config.isIceRestarting = false;
1734
- });
1728
+ }).catch(() => {});
1735
1729
  }
1736
1730
 
1737
1731
  }
@@ -2269,7 +2263,7 @@ class RoomSession {
2269
2263
  config.streamMap[source].forEach(trackId => {
2270
2264
  let t = transceivers.find(transceiver => transceiver.sender.track && transceiver.sender.track.id === trackId)
2271
2265
  if(t) {
2272
- descriptions.push({mid: t.mid, description: source});
2266
+ descriptions.push({mid: t.mid, description: JSON.stringify({source, intercomGroups: this._talkIntercomGroups})});
2273
2267
  }
2274
2268
  })
2275
2269
  });
@@ -2424,16 +2418,11 @@ class RoomSession {
2424
2418
  }
2425
2419
 
2426
2420
 
2427
- setTalkIntercomGroups(groups = []) {
2421
+ setTalkIntercomGroups(groups = ['all']) {
2428
2422
  this._talkIntercomGroups = structuredClone(groups);
2429
2423
  let handle = this._getHandle(this.handleId);
2430
2424
  if (!handle) {
2431
- return Promise.reject({
2432
- type: 'warning',
2433
- id: 21,
2434
- message: 'no local id, connect before publishing',
2435
- data: null
2436
- })
2425
+ return Promise.resolve();
2437
2426
  }
2438
2427
  let config = handle.webrtcStuff;
2439
2428
  let transceivers = config.pc.getTransceivers();
@@ -2446,8 +2435,6 @@ class RoomSession {
2446
2435
  }
2447
2436
  })
2448
2437
  });
2449
- //TODO: under development
2450
- return Promise.resolve();
2451
2438
  return this.sendMessage(this.handleId, {
2452
2439
  body: {
2453
2440
  "request": "configure",
@@ -2456,7 +2443,7 @@ class RoomSession {
2456
2443
  })
2457
2444
  }
2458
2445
 
2459
- setListenIntercomGroups(groups = []) {
2446
+ setListenIntercomGroups(groups = ['all']) {
2460
2447
  this._listenIntercomGroups = groups;
2461
2448
  }
2462
2449