@reactoo/watchtogether-sdk-js 2.6.24 → 2.6.26

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.24",
3
+ "version": "2.6.26",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -518,8 +518,23 @@ class RoomSession {
518
518
  this.id = msg["id"];
519
519
  this.privateId = msg["private_id"];
520
520
  this.isConnected = true;
521
- this.emit('joined', true);
522
521
  this._log('We have successfully joined Room');
522
+ this.emit('joined', true, this.constructId);
523
+ this.emit('addLocalParticipant', {
524
+ tid: generateUUID(),
525
+ id: handle.handleId,
526
+ constructId: this.constructId,
527
+ userId: decodeJanusDisplay(handle.userId)?.userId,
528
+ role: decodeJanusDisplay(this.display)?.role,
529
+ track: null,
530
+ stream: null,
531
+ streamMap: {},
532
+ source: null,
533
+ adding: false,
534
+ removing: false,
535
+ hasAudioTrack: false,
536
+ hasVideoTrack: false,
537
+ });
523
538
  for (let f in list) {
524
539
  let userId = list[f]["display"];
525
540
  let streams = list[f]["streams"] || [];
@@ -732,10 +747,11 @@ class RoomSession {
732
747
  userId: decodeJanusDisplay(handle.userId)?.userId,
733
748
  role: decodeJanusDisplay(handle.userId)?.role,
734
749
  stream: null,
735
- streamMap: handle.webrtcStuff?.streamMap,
750
+ streamMap: structuredClone(handle.webrtcStuff?.streamMap),
736
751
  source: null,
737
752
  track: null,
738
753
  adding: false,
754
+ removing: false,
739
755
  constructId: this.constructId,
740
756
  hasAudioTrack: false,
741
757
  hasVideoTrack: false
@@ -1159,7 +1175,7 @@ class RoomSession {
1159
1175
  }
1160
1176
 
1161
1177
  disconnect() {
1162
-
1178
+
1163
1179
  if (this.isDisconnecting) {
1164
1180
  return Promise.resolve();
1165
1181
  }
@@ -1367,9 +1383,9 @@ class RoomSession {
1367
1383
  pc_config.bundlePolicy = "max-bundle";
1368
1384
  }
1369
1385
 
1370
- // pc_config.bundlePolicy = 'balanced';
1371
- // pc_config.iceTransportPolicy = 'relay';
1372
- // pc_config.rtcpMuxPolicy = "negotiate";
1386
+ // pc_config.bundlePolicy = 'balanced';
1387
+ // pc_config.iceTransportPolicy = 'relay';
1388
+ // pc_config.rtcpMuxPolicy = "negotiate";
1373
1389
 
1374
1390
  this._log('new RTCPeerConnection', pc_config, pc_constraints);
1375
1391
 
@@ -1394,12 +1410,12 @@ class RoomSession {
1394
1410
  userId: decodeJanusDisplay(handle.userId)?.userId,
1395
1411
  role: decodeJanusDisplay(handle.userId)?.role,
1396
1412
  stream: config.stream,
1397
- streamMap: config.streamMap,
1413
+ streamMap: structuredClone(config.streamMap),
1398
1414
  track: null,
1399
1415
  source: null,
1400
- optional: true,
1401
1416
  constructId: this.constructId,
1402
1417
  adding: false,
1418
+ removing: false,
1403
1419
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1404
1420
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1405
1421
  })
@@ -1417,10 +1433,9 @@ class RoomSession {
1417
1433
  userId: decodeJanusDisplay(handle.userId)?.userId,
1418
1434
  role: decodeJanusDisplay(handle.userId)?.role,
1419
1435
  stream: config.stream,
1420
- streamMap: config.streamMap,
1436
+ streamMap: structuredClone(config.streamMap),
1421
1437
  track: null,
1422
1438
  source: null,
1423
- optional: true,
1424
1439
  constructId: this.constructId,
1425
1440
  adding: false,
1426
1441
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
@@ -1479,7 +1494,7 @@ class RoomSession {
1479
1494
  userId: decodeJanusDisplay(handle.userId)?.userId,
1480
1495
  role: decodeJanusDisplay(handle.userId)?.role,
1481
1496
  stream: config.stream,
1482
- streamMap: config.streamMap,
1497
+ streamMap: structuredClone(config.streamMap),
1483
1498
  source,
1484
1499
  track: ev.track,
1485
1500
  adding: false,
@@ -1502,11 +1517,12 @@ class RoomSession {
1502
1517
  userId: decodeJanusDisplay(handle.userId)?.userId,
1503
1518
  role: decodeJanusDisplay(handle.userId)?.role,
1504
1519
  stream: config.stream,
1505
- streamMap: config.streamMap,
1520
+ streamMap: structuredClone(config.streamMap),
1506
1521
  source,
1507
1522
  track: event.track,
1508
1523
  constructId: this.constructId,
1509
1524
  adding: true,
1525
+ removing: false,
1510
1526
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1511
1527
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1512
1528
  });
@@ -1532,7 +1548,7 @@ class RoomSession {
1532
1548
  userId: decodeJanusDisplay(handle.userId)?.userId,
1533
1549
  role: decodeJanusDisplay(handle.userId)?.role,
1534
1550
  stream: config.stream,
1535
- streamMap: config.streamMap,
1551
+ streamMap: structuredClone(config.streamMap),
1536
1552
  source,
1537
1553
  track: ev.target,
1538
1554
  adding: false,
@@ -1556,7 +1572,7 @@ class RoomSession {
1556
1572
  userId: decodeJanusDisplay(handle.userId)?.userId,
1557
1573
  role: decodeJanusDisplay(handle.userId)?.role,
1558
1574
  stream: config.stream,
1559
- streamMap: config.streamMap,
1575
+ streamMap: structuredClone(config.streamMap),
1560
1576
  source,
1561
1577
  kind: ev.target.kind,
1562
1578
  track: ev.target,
@@ -1578,7 +1594,7 @@ class RoomSession {
1578
1594
  userId: decodeJanusDisplay(handle.userId)?.userId,
1579
1595
  role: decodeJanusDisplay(handle.userId)?.role,
1580
1596
  stream: config.stream,
1581
- streamMap: config.streamMap,
1597
+ streamMap: structuredClone(config.streamMap),
1582
1598
  source,
1583
1599
  kind: ev.target.kind,
1584
1600
  track: ev.target,
@@ -2008,7 +2024,12 @@ class RoomSession {
2008
2024
  let needsNegotiation = false;
2009
2025
  let transceivers = config.pc.getTransceivers();
2010
2026
  let existingTracks = [...(config.streamMap[source] || [])];
2011
- config.streamMap[source] = stream?.getTracks()?.map(track => track.id) || [];
2027
+
2028
+ if(stream?.getTracks().length) {
2029
+ config.streamMap[source] = stream?.getTracks()?.map(track => track.id) || [];
2030
+ } else {
2031
+ delete config.streamMap[source];
2032
+ }
2012
2033
 
2013
2034
  // remove old audio track related to this source
2014
2035
  let oldAudioStream = config?.stream?.getAudioTracks()?.find(track => existingTracks.includes(track.id));
@@ -2051,7 +2072,7 @@ class RoomSession {
2051
2072
  videoTransceiver = transceiver;
2052
2073
  }
2053
2074
 
2054
- // Reusing existing transceivers
2075
+ // Reusing existing transceivers
2055
2076
  // TODO: if we start using different codecs for different sources, we need to check for that here
2056
2077
 
2057
2078
  else if(transceiver.currentDirection === 'inactive' && transceiver.sender?.getParameters()?.codecs?.find(c => c.mimeType.indexOf('audio') > -1) && replaceAudio && !audioTransceiver) {
@@ -2166,7 +2187,7 @@ class RoomSession {
2166
2187
  role: decodeJanusDisplay(this.display)?.role,
2167
2188
  track: ev.detail,
2168
2189
  stream: config.stream,
2169
- streamMap: config.streamMap,
2190
+ streamMap: structuredClone(config.streamMap),
2170
2191
  source,
2171
2192
  adding: false,
2172
2193
  removing: true,
@@ -2194,7 +2215,7 @@ class RoomSession {
2194
2215
  role: decodeJanusDisplay(this.display)?.role,
2195
2216
  track,
2196
2217
  stream: config.stream,
2197
- streamMap: config.streamMap,
2218
+ streamMap: structuredClone(config.streamMap),
2198
2219
  source,
2199
2220
  adding: true,
2200
2221
  constructId: this.constructId,
@@ -2211,7 +2232,6 @@ class RoomSession {
2211
2232
  })
2212
2233
  }
2213
2234
 
2214
- //TODO: legacy event, remove in future
2215
2235
  else {
2216
2236
  this.emit('addLocalParticipant', {
2217
2237
  tid: generateUUID(),
@@ -2219,7 +2239,7 @@ class RoomSession {
2219
2239
  userId: decodeJanusDisplay(handle.userId)?.userId,
2220
2240
  role: decodeJanusDisplay(this.display)?.role,
2221
2241
  stream: null,
2222
- streamMap: config.streamMap,
2242
+ streamMap: structuredClone(config.streamMap),
2223
2243
  source,
2224
2244
  adding: false,
2225
2245
  constructId: this.constructId,