@reactoo/watchtogether-sdk-js 2.6.60 → 2.6.62

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.
@@ -149,12 +149,12 @@
149
149
  Instance.room.getSessionByConstructId(constructId).toggleAudio()
150
150
  }
151
151
 
152
- function setListenIntercomGroups(groups) {
153
- Instance.room.getSessionByConstructId(constructId).setListenIntercomGroups(groups)
152
+ function setListenIntercomChannels(groups) {
153
+ Instance.room.getSessionByConstructId(constructId).setListenIntercomChannels(groups)
154
154
  }
155
155
 
156
- function setTalkIntercomGroups(groups) {
157
- Instance.room.getSessionByConstructId(constructId).setTalkIntercomGroups(groups)
156
+ function setTalkIntercomChannels(groups) {
157
+ Instance.room.getSessionByConstructId(constructId).setTalkIntercomChannels(groups)
158
158
  }
159
159
 
160
160
  let Instance = WatchTogetherSDK({debug:true, apiUrl: 'https://api.reactoo.com/stefan/swagger.json'})({instanceType:'reactooDemo'});
@@ -212,6 +212,9 @@
212
212
  }})) // pin hash is not needed if you're owner of the room
213
213
  .then(session => {
214
214
 
215
+ session.setTalkIntercomChannels([]);
216
+ session.setListenIntercomChannels([]);
217
+
215
218
  session.$on('connecting', (status) => {
216
219
  console.log('connecting', status);
217
220
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.6.60",
3
+ "version": "2.6.62",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -336,16 +336,16 @@ let roomSession = function ({roomId, pinHash, role}, room, wt) {
336
336
  return room.toggleVideo(value, source);
337
337
  },
338
338
 
339
- setTalkIntercomGroups: (groups) => {
340
- return room.setTalkIntercomGroups(groups);
339
+ setTalkIntercomChannels: (groups) => {
340
+ return room.setTalkIntercomChannels(groups);
341
341
  },
342
342
 
343
343
  getTalkIntercomGroups: () => {
344
344
  return room._talkIntercomGroups;
345
345
  },
346
346
 
347
- setListenIntercomGroups: (groups) => {
348
- return room.setListenIntercomGroups(groups);
347
+ setListenIntercomChannels: (groups) => {
348
+ return room.setListenIntercomChannels(groups);
349
349
  },
350
350
 
351
351
  getListenIntercomGroups: () => {
@@ -108,12 +108,12 @@ class RoomSession {
108
108
  "videowall-queue-video": ['host', 'participant'],
109
109
  },
110
110
  talkback: {
111
- "watchparty": ['participant', 'host'],
112
- "studio": ['participant', 'host', 'observer'],
113
- "commentary": ['host', 'participant'],
114
- "videowall": ['host', 'participant'],
115
- "videowall-queue": ['host', 'participant'],
116
- "videowall-queue-video": ['host', 'participant'],
111
+ "watchparty": ['participant', 'host', 'talkback'],
112
+ "studio": ['participant', 'host', 'observer', 'talkback'],
113
+ "commentary": ['host', 'participant', 'talkback'],
114
+ "videowall": ['host', 'participant', 'talkback'],
115
+ "videowall-queue": ['host', 'participant', 'talkback'],
116
+ "videowall-queue-video": ['host', 'participant', 'talkback'],
117
117
  },
118
118
  observer: {
119
119
  "watchparty": ['participant'],
@@ -202,8 +202,8 @@ class RoomSession {
202
202
  this._maxRetries = 5;
203
203
  this._keepAliveId = null;
204
204
  this._participants = [];
205
- this._talkIntercomGroups = ['participants'];
206
- this._listenIntercomGroups = ['participants'];
205
+ this._talkIntercomChannels = ['participants'];
206
+ this._listenIntercomChannels = ['participants'];
207
207
  this._roomType = 'watchparty';
208
208
  this._isDataChannelOpen = false;
209
209
  this._abortController = null;
@@ -232,7 +232,7 @@ class RoomSession {
232
232
  return true;
233
233
  }
234
234
  const intercomGroups = JSON.parse(stream.description || "[]")?.intercomGroups || [];
235
- return intercomGroups.some(g => this._listenIntercomGroups.indexOf(g) > -1);
235
+ return intercomGroups.some(g => this._listenIntercomChannels.indexOf(g) > -1);
236
236
  };
237
237
 
238
238
  _getAddParticipantEventName(handleId) {
@@ -746,12 +746,17 @@ class RoomSession {
746
746
 
747
747
  if (event === "updated") {
748
748
  this._log('Remote has updated tracks', msg);
749
- this._updateCurrentSubscriptions(handle.handleId, msg["streams"] || []);
749
+ if(msg["streams"]) {
750
+ this._updateCurrentSubscriptions(handle.handleId, msg["streams"]);
751
+ }
752
+
750
753
  }
751
754
 
752
755
  if (event === "attached") {
753
756
  this._log('Remote have successfully joined Room', msg);
754
- this._updateCurrentSubscriptions(handle.handleId, msg["streams"] || []);
757
+ if(msg["streams"]) {
758
+ this._updateCurrentSubscriptions(handle.handleId, msg["streams"] || []);
759
+ }
755
760
  this.emit(this._getAddParticipantEventName(handle.handleId), {
756
761
  tid: generateUUID(),
757
762
  id: handle.handleId,
@@ -855,18 +860,20 @@ class RoomSession {
855
860
  try {
856
861
  if (handle.webrtcStuff.stream) {
857
862
  if(!this.isRestarting) {
858
- handle.webrtcStuff.stream.getTracks().forEach(track => track.stop());
863
+ handle.webrtcStuff.stream?.getTracks().forEach(track => track.stop());
859
864
  }
860
865
  else {
861
- handle.webrtcStuff.stream.getTracks().forEach(track => track.onended = null);
866
+ handle.webrtcStuff.stream?.getTracks().forEach(track => track.onended = null);
862
867
  }
863
868
  }
864
869
  } catch (e) {
865
870
  // Do nothing
866
871
  }
867
872
 
868
- handle.webrtcStuff.stream.onremovetrack = null;
869
- handle.webrtcStuff.stream = null;
873
+ if(handle.webrtcStuff.stream) {
874
+ handle.webrtcStuff.stream.onremovetrack = null;
875
+ handle.webrtcStuff.stream = null;
876
+ }
870
877
 
871
878
  if (handle.webrtcStuff.dataChannel) {
872
879
  Object.keys(handle.webrtcStuff.dataChannel).forEach(label => {
@@ -1030,18 +1037,18 @@ class RoomSession {
1030
1037
  }
1031
1038
  let config = handle.webrtcStuff;
1032
1039
  config.streamMap = {};
1033
- config.tracksMap.forEach(tItem => {
1040
+ config.currentSubscriptions.forEach(tItem => {
1034
1041
  if(tItem.type === 'data') {
1035
1042
  return;
1036
1043
  }
1037
1044
  if(tItem.active === false) {
1038
1045
  return;
1039
1046
  }
1040
- const source = JSON.parse(tItem.description)?.source;
1047
+ const source = JSON.parse(tItem.feed_description)?.source;
1041
1048
  if(!config.streamMap[source]) {
1042
1049
  config.streamMap[source] = [];
1043
1050
  }
1044
- let trackId = config.pc.getTransceivers().find(t => t.mid === tItem.mid).receiver.track.id;
1051
+ let trackId = config.pc.getTransceivers().find(t => t.mid === tItem.mid)?.receiver?.track?.id;
1045
1052
  if(trackId) {
1046
1053
  config.streamMap[source].push(trackId);
1047
1054
  }
@@ -1537,13 +1544,13 @@ class RoomSession {
1537
1544
  if(!this._getHandle(handle.handleId)) {
1538
1545
  return;
1539
1546
  }
1547
+ this._updateRemoteParticipantStreamMap(handle.handleId);
1540
1548
 
1541
1549
  let transceiver = config.pc?.getTransceivers()?.find(
1542
1550
  t => t.receiver.track === ev.track);
1543
1551
 
1544
1552
  let mid = transceiver?.mid || ev.track.id;
1545
1553
  let source = Object.keys(config.streamMap).find(key => config.streamMap[key].includes(ev.track.id));
1546
- this._updateRemoteParticipantStreamMap(handle.handleId);
1547
1554
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1548
1555
  tid: generateUUID(),
1549
1556
  id: handle.handleId,
@@ -1565,9 +1572,9 @@ class RoomSession {
1565
1572
 
1566
1573
  if (event.track) {
1567
1574
  config.stream?.addTrack(event.track);
1575
+ this._updateRemoteParticipantStreamMap(handle.handleId);
1568
1576
  let mid = event.transceiver ? event.transceiver.mid : event.track.id;
1569
1577
  let source = Object.keys(config.streamMap).find(key => config.streamMap[key].includes(event.track.id));
1570
- this._updateRemoteParticipantStreamMap(handle.handleId);
1571
1578
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1572
1579
  tid: generateUUID(),
1573
1580
  mid,
@@ -1595,11 +1602,11 @@ class RoomSession {
1595
1602
  if(!this._getHandle(handle.handleId)) {
1596
1603
  return;
1597
1604
  }
1605
+ this._updateRemoteParticipantStreamMap(handle.handleId);
1598
1606
  let transceiver = config.pc?.getTransceivers()?.find(
1599
1607
  t => t.receiver.track === ev.target);
1600
1608
  let mid = transceiver?.mid || ev.target.id;
1601
1609
  let source = Object.keys(config.streamMap).find(key => config.streamMap[key].includes(ev.target.id));
1602
- this._updateRemoteParticipantStreamMap(handle.handleId);
1603
1610
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1604
1611
  tid: generateUUID(),
1605
1612
  id: handle.handleId,
@@ -1802,7 +1809,6 @@ class RoomSession {
1802
1809
  }
1803
1810
 
1804
1811
  _setupTransceivers(handleId, [audioSend, audioRecv, videoSend, videoRecv, audioTransceiver = null, videoTransceiver = null]) {
1805
-
1806
1812
  //TODO: this should be refactored to use handle's trackMap so we dont have to pass any parameters
1807
1813
 
1808
1814
  let handle = this._getHandle(handleId);
@@ -1811,7 +1817,7 @@ class RoomSession {
1811
1817
  }
1812
1818
  let config = handle.webrtcStuff;
1813
1819
 
1814
- const setTransceiver = (transceiver, send, recv) => {
1820
+ const setTransceiver = (transceiver, send, recv, kind = 'audio') => {
1815
1821
  if (!send && !recv) {
1816
1822
  // disabled: have we removed it?
1817
1823
  if (transceiver) {
@@ -1847,7 +1853,7 @@ class RoomSession {
1847
1853
  }
1848
1854
  } else {
1849
1855
  // In theory, this is the only case where we might not have a transceiver yet
1850
- config.pc.addTransceiver("audio", {direction: "recvonly"});
1856
+ config.pc.addTransceiver(kind, {direction: "recvonly"});
1851
1857
  }
1852
1858
  }
1853
1859
  }
@@ -1856,10 +1862,10 @@ class RoomSession {
1856
1862
  // if we're passing any transceivers, we work only on them, doesn't matter if one of them is null
1857
1863
  if(audioTransceiver || videoTransceiver) {
1858
1864
  if(audioTransceiver) {
1859
- setTransceiver(audioTransceiver, audioSend, audioRecv);
1865
+ setTransceiver(audioTransceiver, audioSend, audioRecv, 'audio');
1860
1866
  }
1861
1867
  if(videoTransceiver) {
1862
- setTransceiver(videoTransceiver, videoSend, videoRecv);
1868
+ setTransceiver(videoTransceiver, videoSend, videoRecv, 'video');
1863
1869
  }
1864
1870
  }
1865
1871
  // else we work on all transceivers
@@ -1872,13 +1878,13 @@ class RoomSession {
1872
1878
  (t.sender && t.sender.track && t.sender.track.kind === "audio") ||
1873
1879
  (t.receiver && t.receiver.track && t.receiver.track.kind === "audio")
1874
1880
  ) {
1875
- setTransceiver(t, audioSend, audioRecv);
1881
+ setTransceiver(t, audioSend, audioRecv, 'audio');
1876
1882
  }
1877
1883
  if (
1878
1884
  (t.sender && t.sender.track && t.sender.track.kind === "video") ||
1879
1885
  (t.receiver && t.receiver.track && t.receiver.track.kind === "video")
1880
1886
  ) {
1881
- setTransceiver(t, videoSend, videoRecv);
1887
+ setTransceiver(t, videoSend, videoRecv, 'video');
1882
1888
  }
1883
1889
  }
1884
1890
  }
@@ -2238,6 +2244,7 @@ class RoomSession {
2238
2244
 
2239
2245
  let hasAudio = !!(stream && stream.getAudioTracks().length > 0);
2240
2246
  let hasVideo = !!(stream && stream.getVideoTracks().length > 0);
2247
+
2241
2248
  this._setupTransceivers(this.handleId, [hasAudio, false, hasVideo, false, audioTransceiver, videoTransceiver]);
2242
2249
 
2243
2250
  const emitEvents = () => {
@@ -2341,7 +2348,7 @@ class RoomSession {
2341
2348
  config.streamMap[source].forEach(trackId => {
2342
2349
  let t = transceivers.find(transceiver => transceiver.sender.track && transceiver.sender.track.id === trackId)
2343
2350
  if(t) {
2344
- descriptions.push({mid: t.mid, description: JSON.stringify({source, intercomGroups: this._talkIntercomGroups})});
2351
+ descriptions.push({mid: t.mid, description: JSON.stringify({source, intercomGroups: this._talkIntercomChannels})});
2345
2352
  }
2346
2353
  })
2347
2354
  });
@@ -2496,14 +2503,14 @@ class RoomSession {
2496
2503
  }
2497
2504
 
2498
2505
 
2499
- setTalkIntercomGroups(groups = ['participants']) {
2506
+ setTalkIntercomChannels(groups = ['participants']) {
2500
2507
 
2501
2508
  if(typeof groups !== 'object' || !("length" in groups)) {
2502
- this._log('setTalkIntercomGroups: groups must be an array');
2509
+ this._log('setTalkIntercomChannels: groups must be an array');
2503
2510
  groups = [groups];
2504
2511
  }
2505
2512
 
2506
- this._talkIntercomGroups = structuredClone(groups);
2513
+ this._talkIntercomChannels = structuredClone(groups);
2507
2514
  let handle = this._getHandle(this.handleId);
2508
2515
  if (!handle) {
2509
2516
  return Promise.resolve();
@@ -2527,14 +2534,14 @@ class RoomSession {
2527
2534
  })
2528
2535
  }
2529
2536
 
2530
- setListenIntercomGroups(groups = ['participants']) {
2537
+ setListenIntercomChannels(groups = ['participants']) {
2531
2538
 
2532
2539
  if(typeof groups !== 'object' || !("length" in groups)) {
2533
- this._log('setListenIntercomGroups: groups must be an array');
2540
+ this._log('setListenIntercomChannels: groups must be an array');
2534
2541
  groups = [groups];
2535
2542
  }
2536
2543
 
2537
- this._listenIntercomGroups = structuredClone(groups);
2544
+ this._listenIntercomChannels = structuredClone(groups);
2538
2545
  let handle = this._getHandle(this.handleId);
2539
2546
  if (!handle) {
2540
2547
  return Promise.resolve();
@@ -2564,7 +2571,7 @@ class RoomSession {
2564
2571
  const description = JSON.parse(track.description);
2565
2572
  const intercomGroups = description?.intercomGroups || [];
2566
2573
 
2567
- if(this._listenIntercomGroups.some(g => intercomGroups.includes(g))) {
2574
+ if(this._listenIntercomChannels.some(g => intercomGroups.includes(g))) {
2568
2575
  subscribe.push({feed: track.id, mid: track.mid})
2569
2576
  }
2570
2577
  else {