@reactoo/watchtogether-sdk-js 2.8.0-beta.2 → 2.8.0-beta.4

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.
@@ -559,6 +559,11 @@
559
559
  })
560
560
  }
561
561
 
562
+ window.getUserTalkIntercomChannels = function (id) {
563
+ let ch = Instance.room.getSessionByConstructId(constructId)?.getUserTalkIntercomChannels(id);
564
+ console.log(ch);
565
+ }
566
+
562
567
  window.setListenIntercomChannels = function(groups) {
563
568
  Instance.room.getSessionByConstructId(constructId).setListenIntercomChannels(groups)
564
569
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.8.0-beta.2",
3
+ "version": "2.8.0-beta.4",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
@@ -406,6 +406,13 @@ class RoomSession {
406
406
  }
407
407
  }
408
408
 
409
+ #hasAttendeeInCache(id) {
410
+ if(this.#subscriberHandle) {
411
+ return !!this.#subscriberHandle.webrtcStuff.userIdToDisplay[id];
412
+ }
413
+ return false
414
+ }
415
+
409
416
  #getCachedAttendeeIds() {
410
417
  return Object.keys(this.#subscriberHandle?.webrtcStuff?.userIdToDisplay || {});
411
418
  }
@@ -448,7 +455,7 @@ class RoomSession {
448
455
  });
449
456
  }
450
457
 
451
- #emitRemoteFeedUpdate(mid, {feedRemoval = false, addingTrack = false, removingTrack = false, track = null, source = null, attendee = null} = {}) {
458
+ #emitRemoteFeedUpdate(mid, {forceEmit = false,feedRemoval = false, addingTrack = false, removingTrack = false, track = null, source = null, attendee = null} = {}) {
452
459
 
453
460
  const transceiverData = this.#getTransceiverDataByMid(mid);
454
461
 
@@ -462,7 +469,7 @@ class RoomSession {
462
469
  description = JSON.parse(transceiverData.feed_description);
463
470
  } catch (e) {}
464
471
 
465
- if(!this.#shouldEmitFeedUpdate(parsedDisplay)) {
472
+ if(!this.#shouldEmitFeedUpdate(parsedDisplay) && !forceEmit && !removingTrack) {
466
473
  this._log('Not emitting feed update for', display, 'because of subscription rules');
467
474
  // we don't want to emit this event
468
475
  return;
@@ -513,7 +520,8 @@ class RoomSession {
513
520
  const display = this.#getDisplayById(id);
514
521
  const parsedDisplay = decodeJanusDisplay(display);
515
522
 
516
- if(!this.#shouldEmitFeedUpdate(parsedDisplay)) {
523
+ // we sometimes need to force emit, or emit when we unsubscribed and we're removing tracks
524
+ if(!this.#shouldEmitFeedUpdate(parsedDisplay, id) && !forceEmit && !removingTrack) {
517
525
  this._log('Not emitting feed update for', display, 'because of subscription rules');
518
526
  // we don't want to emit this event
519
527
  return;
@@ -654,6 +662,7 @@ class RoomSession {
654
662
  const subscribe = [];
655
663
  const unsubscribe = [];
656
664
  const flatSourceMap = [];
665
+ const forceEmitFeedRemoval = []
657
666
 
658
667
  for (let index in publishers) {
659
668
  if(publishers[index]["dummy"])
@@ -692,6 +701,10 @@ class RoomSession {
692
701
  if(isSubscribed) {
693
702
  unsubscribe.push({feed: id, mid: mid});
694
703
  this.#removeFromSubscribeMap(id, mid);
704
+ // we need to get rid of feed if we we're subscribed to it
705
+ if(forceEmitFeedRemoval.indexOf(id) === -1) {
706
+ forceEmitFeedRemoval.push(id);
707
+ }
695
708
  }
696
709
  continue;
697
710
  }
@@ -703,6 +716,9 @@ class RoomSession {
703
716
  }
704
717
  }
705
718
 
719
+ // we need to get rid of feed if we we're subscribed to it
720
+ forceEmitFeedRemoval.forEach(id => this.#emitRemoteFeedUpdate(null, {feedRemoval: true, forceEmit: true, attendee: {id:id}}))
721
+
706
722
  // check if we're subscribed to any mid that is no longer available in sources
707
723
 
708
724
  Object.keys(subscribedTo).forEach(id => {
@@ -2144,9 +2160,10 @@ class RoomSession {
2144
2160
 
2145
2161
  event.streams[0].onremovetrack = (ev) => {
2146
2162
 
2147
- this._log('Remote track removed', ev);
2148
-
2149
2163
  const trackIndex = config?.tracks?.findIndex(t => t.id === ev.track.id);
2164
+
2165
+ this._log('Remote track removed', ev, trackIndex);
2166
+
2150
2167
  if(trackIndex > -1) {
2151
2168
  config.tracks.splice(trackIndex, 1);
2152
2169
  }
@@ -2202,10 +2219,11 @@ class RoomSession {
2202
2219
  return;
2203
2220
 
2204
2221
  event.track.onended = (ev) => {
2205
- this._log('Remote track ended', ev);
2206
2222
 
2207
2223
  const trackIndex = config?.tracks?.findIndex(t => t.id === ev.target.id);
2208
2224
 
2225
+ this._log('Remote track ended', ev, trackIndex);
2226
+
2209
2227
  if(trackIndex > -1) {
2210
2228
  config.tracks.splice(trackIndex, 1);
2211
2229
  }
@@ -3089,14 +3107,14 @@ class RoomSession {
3089
3107
 
3090
3108
  getUserTalkIntercomChannels(userId) {
3091
3109
  let talkIntercomChannels = []
3092
- let transceiver = this.#subscriberHandle.webrtcStuff.transceiverMap.find(t => t.display && decodeJanusDisplay(t.display)?.userId === userId && t.description);
3110
+ let transceiver = this.#subscriberHandle.webrtcStuff.transceiverMap.find(t => t.feed_display && decodeJanusDisplay(t.feed_display)?.userId === userId && t.feed_description);
3093
3111
 
3094
3112
  if(!transceiver) {
3095
3113
  return talkIntercomChannels;
3096
3114
  }
3097
3115
 
3098
3116
  try {
3099
- let description = JSON.parse(transceiver.description);
3117
+ let description = JSON.parse(transceiver.feed_description);
3100
3118
  if(description.intercomGroups) {
3101
3119
  description.intercomGroups.forEach(group => {
3102
3120
  if(!talkIntercomChannels.includes(group)) {