@reactoo/watchtogether-sdk-js 2.8.39 → 2.8.41

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.8.39",
3
+ "version": "2.8.41",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
@@ -63,7 +63,7 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
63
63
 
64
64
  room.on('error', (e) => {
65
65
  if(e?.type === 'error') {
66
- ___.disconnect(true);
66
+ ___.disconnect();
67
67
  }
68
68
  });
69
69
 
@@ -152,10 +152,10 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
152
152
  })
153
153
  },
154
154
 
155
- disconnect: function (dontWaitForResponses) {
155
+ disconnect: function () {
156
156
  clearTimeout(alpTimeoutId);
157
157
  abortController?.abort?.();
158
- return room.disconnect(dontWaitForResponses);
158
+ return room.disconnect();
159
159
  },
160
160
 
161
161
  //TODO: refactor restart method
@@ -253,7 +253,6 @@ class RoomSession {
253
253
  this.simulcastSettings = null;
254
254
  this.useWebsockets = null;
255
255
 
256
-
257
256
  this.defaultSimulcastSettings = {
258
257
  "default" : {
259
258
  mode: "controlled", // controlled, manual, browserControlled
@@ -662,7 +661,11 @@ class RoomSession {
662
661
 
663
662
  async #updateSubscriptions() {
664
663
 
665
- // no subscriber handle, we create one and subscribe to relevant participants
664
+
665
+ // added sanity check
666
+ await this.#availablePublishersSanityCheck();
667
+
668
+ // no subscription yet, we create one and subscribe to relevant participants
666
669
 
667
670
  if(!this.#subscriberJoinPromise) {
668
671
  await this.#joinAsSubscriber(this.roomId, this.pin, this.userId);
@@ -818,6 +821,43 @@ class RoomSession {
818
821
  }
819
822
  }
820
823
 
824
+ async #availablePublishersSanityCheck() {
825
+ const list = await this.sendMessage(this.handleId, {body: {request: 'listparticipants', room: this.roomId}})
826
+ const participants = list.participants || [];
827
+ const availablePublishers = [...(this.#subscriberHandle?.webrtcStuff?.availablePublishers ?? [])];
828
+
829
+ availablePublishers.forEach(publisher => {
830
+
831
+ const checkedParticipant = participants.find(p => p.id === publisher.id);
832
+ if(!checkedParticipant) {
833
+ // this publisher is not in the list, we need to remove it
834
+ this._log('Sanity check - Removing publisher', publisher.id, 'from availablePublishers');
835
+ this.#updateAvailablePublishersTrackData([], publisher.id);
836
+ this.#emitRemoteFeedUpdate(null, {feedRemoval: true, attendee: {id: publisher.id}});
837
+ this.#removeAttendeeFromCache(publisher.id);
838
+ this.emit('error', {
839
+ type: 'warning',
840
+ id: 50,
841
+ message: 'sanity check - removing publisher from availablePublishers',
842
+ data: publisher.id
843
+ });
844
+ }
845
+ else if(checkedParticipant.publisher === false) {
846
+ // this publisher is not in the list, we need to remove it
847
+ this._log('Sanity check - Removing publisher', publisher.id, 'from availablePublishers');
848
+ this.#updateAvailablePublishersTrackData([], publisher.id);
849
+ this.#emitRemoteFeedUpdate(null, {feedRemoval: true, attendee: {id: publisher.id}});
850
+ this.emit('error', {
851
+ type: 'warning',
852
+ id: 51,
853
+ message: 'sanity check - removing publisher from availablePublishers',
854
+ data: publisher.id
855
+ });
856
+ }
857
+
858
+ });
859
+ }
860
+
821
861
  #getTransceiverDataByMid(mid) {
822
862
  return this.#subscriberHandle.webrtcStuff.transceiverMap.find(t => t.mid === mid);
823
863
  }
@@ -2098,21 +2138,38 @@ class RoomSession {
2098
2138
  })
2099
2139
  }
2100
2140
 
2101
- await this.#destroyHandle(this.#publisherHandle?.handleId, false);
2102
- await this.#destroyHandle(this.#subscriberHandle?.handleId, false);
2103
-
2141
+ try {
2142
+ await this.#destroyHandle(this.#publisherHandle?.handleId, false);
2143
+ } catch (e) {
2144
+ this._log('Error destroying publisher handle:', e);
2145
+ }
2146
+
2147
+ try {
2148
+ await this.#destroyHandle(this.#subscriberHandle?.handleId, false);
2149
+ } catch (e) {
2150
+ this._log('Error destroying subscriber handle:', e);
2151
+ }
2152
+
2104
2153
  this.#wipeListeners();
2105
2154
 
2106
2155
  if(!this.useWebsockets) {
2107
2156
 
2108
2157
  if(this.token) {
2109
- await this.#send({"janus": "destroy"}, true);
2158
+ try {
2159
+ await this.#send({"janus": "destroy"}, true);
2160
+ } catch (e) {
2161
+ this._log('Error sending destroy message:', e);
2162
+ }
2110
2163
  }
2111
2164
  }
2112
2165
 
2113
2166
  else if (this.ws && this.ws.readyState === 1) {
2114
- await this.#send({"janus": "destroy"}, true);
2115
- this.ws.close();
2167
+ try {
2168
+ await this.#send({"janus": "destroy"}, true);
2169
+ this.ws.close();
2170
+ } catch (e) {
2171
+ this._log('Error in websocket cleanup:', e);
2172
+ }
2116
2173
  }
2117
2174
 
2118
2175
  this.#subscriberJoinPromise = null;