@reactoo/watchtogether-sdk-js 2.6.62 → 2.6.63

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.63",
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(),
@@ -899,7 +905,8 @@ class RoomSession {
899
905
  stream: null,
900
906
  streamMap: {},
901
907
  tracksMap: [],
902
- currentSubscriptions: [],
908
+ transceiverMap: [],
909
+ subscribeMap: [],
903
910
  mySdp: null,
904
911
  mediaConstraints: null,
905
912
  pc: null,
@@ -951,7 +958,8 @@ class RoomSession {
951
958
  stream: null,
952
959
  streamMap: {},
953
960
  tracksMap: [],
954
- currentSubscriptions: [],
961
+ transceiverMap: [],
962
+ subscribeMap: [],
955
963
  mySdp: null,
956
964
  mediaConstraints: null,
957
965
  pc: null,
@@ -968,7 +976,33 @@ class RoomSession {
968
976
  })
969
977
  }
970
978
 
971
- _isAlreadySubscribed(handleId, stream) {
979
+
980
+ _updateSubscribeMap(handleId, subscribe, unsubscribe) {
981
+ let handle = this._getHandle(handleId);
982
+ if (!handle) {
983
+ this.emit('error', {
984
+ type: 'warning',
985
+ id: 15,
986
+ message: 'id non-existent',
987
+ data: [handleId, 'updateSubscribeMap']
988
+ });
989
+ return;
990
+ }
991
+ let currentSubscribeMap = handle.webrtcStuff.subscribeMap;
992
+ subscribe.forEach(s => {
993
+ if(!currentSubscribeMap.find(c => c.feed === s.feed && c.mid === s.mid)) {
994
+ currentSubscribeMap.push(s);
995
+ }
996
+ });
997
+ unsubscribe.forEach(s => {
998
+ let index = currentSubscribeMap.findIndex(c => c.feed === s.feed && c.mid === s.mid);
999
+ if(index > -1) {
1000
+ currentSubscribeMap.splice(index, 1);
1001
+ }
1002
+ });
1003
+ }
1004
+
1005
+ _isAlreadySubscribed(handleId, feed, mid) {
972
1006
  let handle = this._getHandle(handleId);
973
1007
  if (!handle) {
974
1008
  this.emit('error', {
@@ -979,23 +1013,23 @@ class RoomSession {
979
1013
  });
980
1014
  return;
981
1015
  }
982
- return handle.webrtcStuff.currentSubscriptions.filter(t => t.active).findIndex(t => t.mid === stream.mid) > -1
1016
+ return handle.webrtcStuff.subscribeMap.findIndex(t => t.mid === mid && t.feed === feed) > -1
983
1017
  }
984
1018
 
985
- _updateCurrentSubscriptions(handleId, streams) {
986
- this._log('Updating current subscription data', handleId, streams);
1019
+ _updateTransceiverMap(handleId, streams) {
1020
+ this._log('Updating current transceiver map', handleId, streams);
987
1021
  let handle = this._getHandle(handleId);
988
1022
  if (!handle) {
989
1023
  this.emit('error', {
990
1024
  type: 'warning',
991
1025
  id: 15,
992
1026
  message: 'id non-existent',
993
- data: [handleId, 'updateCurrentSubscriptions']
1027
+ data: [handleId, 'updateTransceiverMap']
994
1028
  });
995
1029
  return;
996
1030
  }
997
1031
  let config = handle.webrtcStuff;
998
- config.currentSubscriptions = structuredClone(streams);
1032
+ config.transceiverMap = structuredClone(streams);
999
1033
  }
1000
1034
 
1001
1035
  _updateParticipantsTrackData(handleId, streams) {
@@ -1037,7 +1071,7 @@ class RoomSession {
1037
1071
  }
1038
1072
  let config = handle.webrtcStuff;
1039
1073
  config.streamMap = {};
1040
- config.currentSubscriptions.forEach(tItem => {
1074
+ config.transceiverMap.forEach(tItem => {
1041
1075
  if(tItem.type === 'data') {
1042
1076
  return;
1043
1077
  }
@@ -2565,20 +2599,22 @@ class RoomSession {
2565
2599
 
2566
2600
  tracksMap.forEach(track => {
2567
2601
  if(track.type === 'data') {
2568
- //subscribe.push({feed: track.id, mid: track.mid})
2569
2602
  return;
2570
2603
  }
2571
2604
  const description = JSON.parse(track.description);
2572
2605
  const intercomGroups = description?.intercomGroups || [];
2573
-
2574
2606
  if(this._listenIntercomChannels.some(g => intercomGroups.includes(g))) {
2575
- subscribe.push({feed: track.id, mid: track.mid})
2607
+ if(!this._isAlreadySubscribed(participant.handleId, track.id, track.mid)) {
2608
+ subscribe.push({feed: track.id, mid: track.mid})
2609
+ }
2576
2610
  }
2577
2611
  else {
2578
2612
  unsubscribe.push({feed: track.id, mid: track.mid})
2579
2613
  }
2580
2614
  });
2581
2615
 
2616
+ this._updateSubscribeMap(participant.handleId, subscribe, unsubscribe);
2617
+
2582
2618
  if(subscribe.length || unsubscribe.length) {
2583
2619
  promises.push(this.sendMessage(handle.handleId, {
2584
2620
  body: {