@reactoo/watchtogether-sdk-js 2.6.28 → 2.6.30

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.28",
3
+ "version": "2.6.30",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -854,7 +854,6 @@ class RoomSession {
854
854
  // Do nothing
855
855
  }
856
856
 
857
- handle.webrtcStuff.clearTrackRemovedListener?.();
858
857
  handle.webrtcStuff.stream.onremovetrack = null;
859
858
  handle.webrtcStuff.stream = null;
860
859
 
@@ -890,7 +889,6 @@ class RoomSession {
890
889
  dtmfSender: null,
891
890
  trickle: true,
892
891
  iceDone: false,
893
- clearTrackRemovedListener: null,
894
892
  };
895
893
 
896
894
  if (handleId === this.handleId) {
@@ -2041,7 +2039,6 @@ class RoomSession {
2041
2039
  this._log(e);
2042
2040
  }
2043
2041
  config.stream.removeTrack(oldAudioStream);
2044
- config.stream.dispatchEvent(new CustomEvent("trackremoved", {detail: {track: oldAudioStream, source}}))
2045
2042
  }
2046
2043
 
2047
2044
  // remove old video track related to this source
@@ -2053,7 +2050,6 @@ class RoomSession {
2053
2050
  this._log(e);
2054
2051
  }
2055
2052
  config.stream.removeTrack(oldVideoStream);
2056
- config.stream.dispatchEvent(new CustomEvent("trackremoved", {detail: {track: oldVideoStream, source}}))
2057
2053
  }
2058
2054
 
2059
2055
  let audioTrackReplacePromise = Promise.resolve();
@@ -2157,7 +2153,6 @@ class RoomSession {
2157
2153
  this.isVideoEnabled = !!(config.stream && config.stream.getVideoTracks().length > 0);
2158
2154
 
2159
2155
  // we possibly created new transceivers, so we need to get them again
2160
-
2161
2156
  transceivers = config.pc.getTransceivers();
2162
2157
  existingTracks = [...(config.streamMap[source] || [])];
2163
2158
  if(!audioTransceiver) {
@@ -2171,44 +2166,32 @@ class RoomSession {
2171
2166
  let hasVideo = !!(stream && stream.getVideoTracks().length > 0);
2172
2167
  this._setupTransceivers(this.handleId, [hasAudio, false, hasVideo, false, audioTransceiver, videoTransceiver]);
2173
2168
 
2174
-
2175
2169
  const emitEvents = () => {
2176
2170
  this.isPublished = true;
2177
2171
 
2178
2172
  if(!config.stream.onremovetrack) {
2179
2173
  config.stream.onremovetrack = (ev) => {};
2180
-
2181
- let trackremoved = (ev) => {
2182
-
2183
- config.streamMap[ev.detail.source] = config.streamMap[ev.detail.source].filter(id => id !== ev.detail.track.id);
2184
- if(config.streamMap[ev.detail.source].length === 0) {
2185
- delete config.streamMap[ev.detail.source];
2186
- }
2187
-
2188
- this.emit('addLocalParticipant', {
2189
- tid: generateUUID(),
2190
- id: handle.handleId,
2191
- constructId: this.constructId,
2192
- userId: decodeJanusDisplay(handle.userId)?.userId,
2193
- role: decodeJanusDisplay(this.display)?.role,
2194
- track: ev.detail.track,
2195
- stream: config.stream,
2196
- streamMap: structuredClone(config.streamMap),
2197
- source: ev.detail.source,
2198
- adding: false,
2199
- removing: true,
2200
- hasAudioTrack: hasAudio,
2201
- hasVideoTrack: hasVideo,
2202
- });
2203
- }
2204
-
2205
- config.stream.addEventListener('trackremoved', trackremoved);
2206
- config.clearTrackRemovedListener = () => {
2207
- config.stream.removeEventListener('trackremoved', trackremoved);
2208
- }
2209
2174
  }
2210
2175
 
2176
+ let republishTimeoutId = null;
2211
2177
  let tracks = config.stream.getTracks();
2178
+
2179
+ this.emit('addLocalParticipant', {
2180
+ tid: generateUUID(),
2181
+ id: handle.handleId,
2182
+ userId: decodeJanusDisplay(handle.userId)?.userId,
2183
+ role: decodeJanusDisplay(this.display)?.role,
2184
+ stream: tracks.length ? config.stream : null, // that null is there due to backward compatibility
2185
+ track: null,
2186
+ streamMap: structuredClone(config.streamMap),
2187
+ source,
2188
+ adding: false,
2189
+ removing: false,
2190
+ constructId: this.constructId,
2191
+ hasAudioTrack: hasAudio,
2192
+ hasVideoTrack: hasVideo
2193
+ });
2194
+
2212
2195
  if(tracks.length) {
2213
2196
  tracks.forEach(track => {
2214
2197
  // used as a flag to not emit tracks that been already emitted
@@ -2224,6 +2207,7 @@ class RoomSession {
2224
2207
  streamMap: structuredClone(config.streamMap),
2225
2208
  source,
2226
2209
  adding: true,
2210
+ removing: false,
2227
2211
  constructId: this.constructId,
2228
2212
  hasAudioTrack: hasAudio,
2229
2213
  hasVideoTrack: hasVideo
@@ -2231,29 +2215,16 @@ class RoomSession {
2231
2215
 
2232
2216
  track.onended = (ev) => {
2233
2217
  config.stream.removeTrack(track);
2234
- config.stream.dispatchEvent(new CustomEvent("trackremoved", {detail: {track, source}}))
2235
- this._republishOnTrackEnded(source);
2218
+ clearTimeout(republishTimeoutId);
2219
+ republishTimeoutId = setTimeout(() => {
2220
+ this._republishOnTrackEnded(source);
2221
+ }, 100);
2222
+
2236
2223
  }
2237
2224
  }
2238
2225
  })
2239
2226
  }
2240
2227
 
2241
- else {
2242
- this.emit('addLocalParticipant', {
2243
- tid: generateUUID(),
2244
- id: handle.handleId,
2245
- userId: decodeJanusDisplay(handle.userId)?.userId,
2246
- role: decodeJanusDisplay(this.display)?.role,
2247
- stream: null,
2248
- streamMap: structuredClone(config.streamMap),
2249
- source,
2250
- adding: false,
2251
- constructId: this.constructId,
2252
- hasAudioTrack: hasAudio,
2253
- hasVideoTrack: hasVideo
2254
- });
2255
- }
2256
-
2257
2228
  this.isMuted = [];
2258
2229
  for(const source of Object.keys(config.streamMap)) {
2259
2230
  const audioTrack = config.stream?.getAudioTracks()?.find(track => config.streamMap[source].includes(track.id));
@@ -2374,7 +2345,7 @@ class RoomSession {
2374
2345
  return Promise.reject({type: 'error', id: 21, message: 'no local id, connect first', data: null})
2375
2346
  }
2376
2347
  let config = handle.webrtcStuff;
2377
- let transceivers = config.pc.getTransceivers().filter(t => t.currentDirection !== 'inactive');
2348
+ let transceivers = config.pc.getTransceivers()?.filter(t => t.currentDirection !== 'inactive');
2378
2349
  let transceiver = null;
2379
2350
  if(source) {
2380
2351
  transceiver = transceivers
@@ -2408,7 +2379,7 @@ class RoomSession {
2408
2379
  return Promise.reject({type: 'error', id: 21, message: 'no local id, connect first', data: null})
2409
2380
  }
2410
2381
  let config = handle.webrtcStuff;
2411
- let transceivers = config.pc.getTransceivers().filter(t => t.currentDirection !== 'inactive');
2382
+ let transceivers = config.pc.getTransceivers()?.filter(t => t.currentDirection !== 'inactive');
2412
2383
  let transceiver = null;
2413
2384
  if(source) {
2414
2385
  transceiver = transceivers