@reactoo/watchtogether-sdk-js 2.6.62 → 2.6.64

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.6.62",
3
+ "version": "2.6.64",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -565,13 +565,15 @@ class RoomSession {
565
565
  this._createParticipant(userId, id)
566
566
  .then(handle => {
567
567
  this._updateParticipantsTrackData(handle.handleId, streams);
568
+ const subscribe = streams.filter(s => !s.disabled && this._intercomSubscribe(s)).map(stream => ({feed: stream.id, mid: stream.mid}));
569
+ handle.webrtcStuff.subscribeMap = structuredClone(subscribe);
568
570
  return this.sendMessage(handle.handleId, {
569
571
  body: {
570
572
  "request": "join",
571
573
  "room": this.roomId,
572
574
  "ptype": "subscriber",
573
575
  "private_id": this.privateId,
574
- streams: streams.filter(s => !s.disabled && this._intercomSubscribe(s)).map(stream => ({feed: stream.id, mid: stream.mid})),
576
+ streams: subscribe,
575
577
  //"feed": id,
576
578
  ...(this.webrtcVersion > 1000 ? {id: this.userId} : {}),
577
579
  pin: this.pin
@@ -608,12 +610,14 @@ class RoomSession {
608
610
  this._updateParticipantsTrackData(handle.handleId, streams)
609
611
 
610
612
  let subscribe = streams
611
- .filter(stream => !stream.disabled && this._intercomSubscribe(stream) && !this._isAlreadySubscribed(handle.handleId, stream))
613
+ .filter(stream => !stream.disabled && this._intercomSubscribe(stream) && !this._isAlreadySubscribed(handle.handleId, stream.id, stream.mid))
612
614
  .map(s => ({feed: s.id, mid: s.mid}));
613
615
 
614
616
  let unsubscribe = streams.filter(stream => stream.disabled || !this._intercomSubscribe(stream))
615
617
  .map(s => ({feed: s.id, mid: s.mid}));
616
618
 
619
+ this._updateSubscribeMap(handle.handleId, subscribe, unsubscribe);
620
+
617
621
  this._log('Already subscribed to user: ', userId, 'Update streams', subscribe, unsubscribe);
618
622
 
619
623
  if(subscribe.length || unsubscribe.length) {
@@ -631,13 +635,15 @@ class RoomSession {
631
635
  this._createParticipant(userId, id)
632
636
  .then(handle => {
633
637
  this._updateParticipantsTrackData(handle.handleId, streams);
638
+ const subscribe = streams.filter(s => !s.disabled && this._intercomSubscribe(s)).map(stream => ({feed: stream.id, mid: stream.mid}));
639
+ handle.webrtcStuff.subscribeMap = structuredClone(subscribe);
634
640
  return this.sendMessage(handle.handleId, {
635
641
  body: {
636
642
  "request": "join",
637
643
  "room": this.roomId,
638
644
  "ptype": "subscriber",
639
645
  "private_id": this.privateId,
640
- streams: streams.filter(s => !s.disabled && this._intercomSubscribe(s)).map(stream => ({feed: stream.id, mid: stream.mid})),
646
+ streams: subscribe,
641
647
  ...(this.webrtcVersion > 1000 ? {id: this.userId} : {}),
642
648
  pin: this.pin
643
649
  }
@@ -747,7 +753,7 @@ class RoomSession {
747
753
  if (event === "updated") {
748
754
  this._log('Remote has updated tracks', msg);
749
755
  if(msg["streams"]) {
750
- this._updateCurrentSubscriptions(handle.handleId, msg["streams"]);
756
+ this._updateTransceiverMap(handle.handleId, msg["streams"]);
751
757
  }
752
758
 
753
759
  }
@@ -755,7 +761,7 @@ class RoomSession {
755
761
  if (event === "attached") {
756
762
  this._log('Remote have successfully joined Room', msg);
757
763
  if(msg["streams"]) {
758
- this._updateCurrentSubscriptions(handle.handleId, msg["streams"] || []);
764
+ this._updateTransceiverMap(handle.handleId, msg["streams"] || []);
759
765
  }
760
766
  this.emit(this._getAddParticipantEventName(handle.handleId), {
761
767
  tid: generateUUID(),
@@ -764,6 +770,7 @@ class RoomSession {
764
770
  role: decodeJanusDisplay(handle.userId)?.role,
765
771
  stream: null,
766
772
  streamMap: structuredClone(handle.webrtcStuff?.streamMap),
773
+ talkIntercomChannels: structuredClone(this._talkIntercomChannels),
767
774
  source: null,
768
775
  track: null,
769
776
  adding: false,
@@ -899,7 +906,8 @@ class RoomSession {
899
906
  stream: null,
900
907
  streamMap: {},
901
908
  tracksMap: [],
902
- currentSubscriptions: [],
909
+ transceiverMap: [],
910
+ subscribeMap: [],
903
911
  mySdp: null,
904
912
  mediaConstraints: null,
905
913
  pc: null,
@@ -951,7 +959,8 @@ class RoomSession {
951
959
  stream: null,
952
960
  streamMap: {},
953
961
  tracksMap: [],
954
- currentSubscriptions: [],
962
+ transceiverMap: [],
963
+ subscribeMap: [],
955
964
  mySdp: null,
956
965
  mediaConstraints: null,
957
966
  pc: null,
@@ -968,7 +977,33 @@ class RoomSession {
968
977
  })
969
978
  }
970
979
 
971
- _isAlreadySubscribed(handleId, stream) {
980
+
981
+ _updateSubscribeMap(handleId, subscribe, unsubscribe) {
982
+ let handle = this._getHandle(handleId);
983
+ if (!handle) {
984
+ this.emit('error', {
985
+ type: 'warning',
986
+ id: 15,
987
+ message: 'id non-existent',
988
+ data: [handleId, 'updateSubscribeMap']
989
+ });
990
+ return;
991
+ }
992
+ let currentSubscribeMap = handle.webrtcStuff.subscribeMap;
993
+ subscribe.forEach(s => {
994
+ if(!currentSubscribeMap.find(c => c.feed === s.feed && c.mid === s.mid)) {
995
+ currentSubscribeMap.push(s);
996
+ }
997
+ });
998
+ unsubscribe.forEach(s => {
999
+ let index = currentSubscribeMap.findIndex(c => c.feed === s.feed && c.mid === s.mid);
1000
+ if(index > -1) {
1001
+ currentSubscribeMap.splice(index, 1);
1002
+ }
1003
+ });
1004
+ }
1005
+
1006
+ _isAlreadySubscribed(handleId, feed, mid) {
972
1007
  let handle = this._getHandle(handleId);
973
1008
  if (!handle) {
974
1009
  this.emit('error', {
@@ -979,23 +1014,23 @@ class RoomSession {
979
1014
  });
980
1015
  return;
981
1016
  }
982
- return handle.webrtcStuff.currentSubscriptions.filter(t => t.active).findIndex(t => t.mid === stream.mid) > -1
1017
+ return handle.webrtcStuff.subscribeMap.findIndex(t => t.mid === mid && t.feed === feed) > -1
983
1018
  }
984
1019
 
985
- _updateCurrentSubscriptions(handleId, streams) {
986
- this._log('Updating current subscription data', handleId, streams);
1020
+ _updateTransceiverMap(handleId, streams) {
1021
+ this._log('Updating current transceiver map', handleId, streams);
987
1022
  let handle = this._getHandle(handleId);
988
1023
  if (!handle) {
989
1024
  this.emit('error', {
990
1025
  type: 'warning',
991
1026
  id: 15,
992
1027
  message: 'id non-existent',
993
- data: [handleId, 'updateCurrentSubscriptions']
1028
+ data: [handleId, 'updateTransceiverMap']
994
1029
  });
995
1030
  return;
996
1031
  }
997
1032
  let config = handle.webrtcStuff;
998
- config.currentSubscriptions = structuredClone(streams);
1033
+ config.transceiverMap = structuredClone(streams);
999
1034
  }
1000
1035
 
1001
1036
  _updateParticipantsTrackData(handleId, streams) {
@@ -1037,7 +1072,7 @@ class RoomSession {
1037
1072
  }
1038
1073
  let config = handle.webrtcStuff;
1039
1074
  config.streamMap = {};
1040
- config.currentSubscriptions.forEach(tItem => {
1075
+ config.transceiverMap.forEach(tItem => {
1041
1076
  if(tItem.type === 'data') {
1042
1077
  return;
1043
1078
  }
@@ -1469,6 +1504,7 @@ class RoomSession {
1469
1504
  role: decodeJanusDisplay(handle.userId)?.role,
1470
1505
  stream: config.stream,
1471
1506
  streamMap: structuredClone(config.streamMap),
1507
+ talkIntercomChannels: structuredClone(this._talkIntercomChannels),
1472
1508
  track: null,
1473
1509
  source: null,
1474
1510
  constructId: this.constructId,
@@ -1493,6 +1529,7 @@ class RoomSession {
1493
1529
  role: decodeJanusDisplay(handle.userId)?.role,
1494
1530
  stream: config.stream,
1495
1531
  streamMap: structuredClone(config.streamMap),
1532
+ talkIntercomChannels: structuredClone(this._talkIntercomChannels),
1496
1533
  track: null,
1497
1534
  source: null,
1498
1535
  constructId: this.constructId,
@@ -1560,6 +1597,7 @@ class RoomSession {
1560
1597
  role: decodeJanusDisplay(handle.userId)?.role,
1561
1598
  stream: config.stream,
1562
1599
  streamMap: structuredClone(config.streamMap),
1600
+ talkIntercomChannels: structuredClone(this._talkIntercomChannels),
1563
1601
  source,
1564
1602
  track: ev.track,
1565
1603
  adding: false,
@@ -1583,6 +1621,7 @@ class RoomSession {
1583
1621
  role: decodeJanusDisplay(handle.userId)?.role,
1584
1622
  stream: config.stream,
1585
1623
  streamMap: structuredClone(config.streamMap),
1624
+ talkIntercomChannels: structuredClone(this._talkIntercomChannels),
1586
1625
  source,
1587
1626
  track: event.track,
1588
1627
  constructId: this.constructId,
@@ -1616,6 +1655,7 @@ class RoomSession {
1616
1655
  role: decodeJanusDisplay(handle.userId)?.role,
1617
1656
  stream: config.stream,
1618
1657
  streamMap: structuredClone(config.streamMap),
1658
+ talkIntercomChannels: structuredClone(this._talkIntercomChannels),
1619
1659
  source,
1620
1660
  track: ev.target,
1621
1661
  adding: false,
@@ -2565,20 +2605,22 @@ class RoomSession {
2565
2605
 
2566
2606
  tracksMap.forEach(track => {
2567
2607
  if(track.type === 'data') {
2568
- //subscribe.push({feed: track.id, mid: track.mid})
2569
2608
  return;
2570
2609
  }
2571
2610
  const description = JSON.parse(track.description);
2572
2611
  const intercomGroups = description?.intercomGroups || [];
2573
-
2574
2612
  if(this._listenIntercomChannels.some(g => intercomGroups.includes(g))) {
2575
- subscribe.push({feed: track.id, mid: track.mid})
2613
+ if(!this._isAlreadySubscribed(participant.handleId, track.id, track.mid)) {
2614
+ subscribe.push({feed: track.id, mid: track.mid})
2615
+ }
2576
2616
  }
2577
2617
  else {
2578
2618
  unsubscribe.push({feed: track.id, mid: track.mid})
2579
2619
  }
2580
2620
  });
2581
2621
 
2622
+ this._updateSubscribeMap(participant.handleId, subscribe, unsubscribe);
2623
+
2582
2624
  if(subscribe.length || unsubscribe.length) {
2583
2625
  promises.push(this.sendMessage(handle.handleId, {
2584
2626
  body: {