@reactoo/watchtogether-sdk-js 2.5.18 → 2.5.21

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.
@@ -24,7 +24,7 @@
24
24
 
25
25
  <script>
26
26
 
27
- let roomId = 'fc2d34f2-de58-42a0-9312-5cd40f2d754e'; //It will create room automatically if not set
27
+ let roomId = 'adab485a-548e-44a8-a9ca-157f3ba50c6e'; //It will create room automatically if not set
28
28
  let pinHash = undefined;//'967ca05f-7fab-a205-5913-39393bbbe923';
29
29
 
30
30
 
@@ -124,6 +124,7 @@
124
124
  .then(r => {
125
125
 
126
126
  if(roomId) {
127
+ console.log(roomId);
127
128
  return Promise.resolve({roomId, pinHash});
128
129
  }
129
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.5.18",
3
+ "version": "2.5.21",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -44,7 +44,7 @@
44
44
  "dependencies": {
45
45
  "@fingerprintjs/fingerprintjs": "^3.3.2",
46
46
  "aws-iot-device-sdk": "^2.2.11",
47
- "serialize-error": "^9.1.0",
47
+ "serialize-error": "9.1.0",
48
48
  "swagger-client": "^3.18.0",
49
49
  "webrtc-adapter": "^8.1.1"
50
50
  },
@@ -1,6 +1,6 @@
1
1
  let config = {
2
- apiUrl: 'https://api.reactoo.com/v2/swagger.json',
3
- devApiUrl: 'https://api.reactoo.com/dev2/swagger.json'
2
+ apiUrl: 'https://api.reactoo.com/v3/swagger.json',
3
+ devApiUrl: 'https://api.reactoo.com/dev3/swagger.json'
4
4
  };
5
5
 
6
6
  export default config;
@@ -451,9 +451,9 @@ class RoomSession {
451
451
  this._log('detached on', handle.handleId);
452
452
  this._removeParticipant(handle.handleId, null, true);
453
453
  } else if (type === "media") {
454
- this._log('Media event:', handle.handleId, json["type"], json["receiving"]);
454
+ this._log('Media event:', handle.handleId, json["type"], json["receiving"], json["mid"]);
455
455
  } else if (type === "slowlink") {
456
- this._log('Slowlink', handle.handleId, json["uplink"], json["nacks"]);
456
+ this._log('Slowlink', handle.handleId, json["uplink"], json["lost"], json["mid"]);
457
457
  } else if (type === "event") {
458
458
  //none universal
459
459
  } else if (type === 'timeout') {
@@ -481,10 +481,6 @@ class RoomSession {
481
481
  let unpublished = msg["unpublished"];
482
482
  let error = msg["error"];
483
483
 
484
- let allowedObservers = this._observerIds || [];
485
- let allowedTalkback = this._talkbackIds || [];
486
- let allowedInstructor = this._instuctorId || null;
487
-
488
484
  if (event === "joined") {
489
485
  this.id = msg["id"];
490
486
  this.privateId = msg["private_id"];
@@ -1161,10 +1157,11 @@ class RoomSession {
1161
1157
  id: handle.handleId,
1162
1158
  userId: handle.userId,
1163
1159
  stream: config.stream,
1160
+ track: null,
1164
1161
  optional: true,
1165
1162
  constructId: this.constructId,
1166
1163
  metaData: this.options.metaData,
1167
- adding: true,
1164
+ adding: false,
1168
1165
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1169
1166
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1170
1167
  })
@@ -1181,10 +1178,11 @@ class RoomSession {
1181
1178
  id: handle.handleId,
1182
1179
  userId: handle.userId,
1183
1180
  stream: config.stream,
1181
+ track: null,
1184
1182
  optional: true,
1185
1183
  constructId: this.constructId,
1186
1184
  metaData: this.options.metaData,
1187
- adding: true,
1185
+ adding: false,
1188
1186
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1189
1187
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1190
1188
  })
@@ -1216,19 +1214,20 @@ class RoomSession {
1216
1214
  if (enableOntrack) {
1217
1215
  config.pc.ontrack = (event) => {
1218
1216
 
1219
- // if(!event.streams)
1220
- // return;
1221
-
1217
+ if(!event.streams)
1218
+ return;
1219
+
1222
1220
  //config.stream = event.streams[0];
1223
1221
 
1224
1222
  if (!config.stream) {
1225
1223
  config.stream = new MediaStream();
1226
1224
  }
1227
-
1228
1225
  if (event.track) {
1226
+ let mid = event.transceiver ? event.transceiver.mid : event.track.id;
1229
1227
  config.stream.addTrack(event.track);
1230
1228
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1231
1229
  tid: generateUUID(),
1230
+ mid,
1232
1231
  id: handle.handleId,
1233
1232
  userId: handle.userId,
1234
1233
  stream: config.stream,
@@ -1244,17 +1243,27 @@ class RoomSession {
1244
1243
  return;
1245
1244
 
1246
1245
  event.track.onended = (ev) => {
1246
+
1247
+ let mid = ev.target.id;
1248
+ if(this.isUnifiedPlan) {
1249
+ let transceiver = config.pc.getTransceivers().find(
1250
+ t => t.receiver.track === ev.target);
1251
+ mid = transceiver.mid;
1252
+ }
1253
+
1247
1254
  if (config.stream) {
1248
1255
  config.stream && config.stream.removeTrack(ev.target);
1249
1256
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1250
1257
  tid: generateUUID(),
1251
1258
  id: handle.handleId,
1259
+ mid,
1252
1260
  userId: handle.userId,
1253
1261
  stream: config.stream,
1254
1262
  track: ev.target,
1255
1263
  constructId: this.constructId,
1256
1264
  metaData: this.options.metaData,
1257
1265
  adding: false,
1266
+ removing: true,
1258
1267
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1259
1268
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1260
1269
  });
@@ -1263,8 +1272,17 @@ class RoomSession {
1263
1272
 
1264
1273
  event.track.onmute = (ev) => {
1265
1274
  this._log('remoteTrackMuted', 'onmute');
1275
+
1276
+ let mid = ev.target.id;
1277
+ if(this.isUnifiedPlan) {
1278
+ let transceiver = config.pc.getTransceivers().find(
1279
+ t => t.receiver.track === ev.target);
1280
+ mid = transceiver.mid;
1281
+ }
1282
+
1266
1283
  this.emit('remoteTrackMuted', {
1267
1284
  id: handle.handleId,
1285
+ mid,
1268
1286
  userId: handle.userId,
1269
1287
  stream: config.stream,
1270
1288
  kind: ev.target.kind,
@@ -1275,8 +1293,17 @@ class RoomSession {
1275
1293
 
1276
1294
  event.track.onunmute = (ev) => {
1277
1295
  this._log('remoteTrackMuted', 'onunmute');
1296
+
1297
+ let mid = ev.target.id;
1298
+ if(this.isUnifiedPlan) {
1299
+ let transceiver = config.pc.getTransceivers().find(
1300
+ t => t.receiver.track === ev.target);
1301
+ mid = transceiver.mid;
1302
+ }
1303
+
1278
1304
  this.emit('remoteTrackMuted', {
1279
1305
  id: handle.handleId,
1306
+ mid,
1280
1307
  userId: handle.userId,
1281
1308
  stream: config.stream,
1282
1309
  kind: ev.target.kind,
@@ -1832,7 +1859,54 @@ class RoomSession {
1832
1859
  })
1833
1860
  .then(r => {
1834
1861
  this._isPublished = true;
1835
- this.emit('addLocalParticipant', {tid:generateUUID(), id: handle.handleId, userId: handle.userId, stream: config.stream});
1862
+ if(config.stream) {
1863
+ let tracks = config.stream.getTracks();
1864
+ tracks.forEach(track => {
1865
+ // used as a flag to not emit tracks that been already emitted
1866
+ if(!track.onended) {
1867
+ this.emit('addLocalParticipant', {
1868
+ tid: generateUUID(),
1869
+ id: handle.handleId,
1870
+ userId: handle.userId,
1871
+ track,
1872
+ stream: config.stream,
1873
+ adding: true,
1874
+ constructId: this.constructId,
1875
+ metaData: this.options.metaData,
1876
+ hasAudioTrack: hasAudio,
1877
+ hasVideoTrack: hasVideo
1878
+ });
1879
+ track.onended = (ev) => {
1880
+ this.emit('addLocalParticipant', {
1881
+ tid:generateUUID(),
1882
+ id: handle.handleId,
1883
+ userId: handle.userId,
1884
+ track: ev.target,
1885
+ stream: config.stream,
1886
+ adding: false,
1887
+ removing: true,
1888
+ constructId: this.constructId,
1889
+ metaData: this.options.metaData,
1890
+ hasAudioTrack: hasAudio,
1891
+ hasVideoTrack: hasVideo
1892
+ });
1893
+ }
1894
+ }
1895
+ })
1896
+ } else {
1897
+ this.emit('addLocalParticipant', {
1898
+ tid: generateUUID(),
1899
+ id: handle.handleId,
1900
+ userId: handle.userId,
1901
+ stream: null,
1902
+ adding: false,
1903
+ constructId: this.constructId,
1904
+ metaData: this.options.metaData,
1905
+ hasAudioTrack: hasAudio,
1906
+ hasVideoTrack: hasVideo
1907
+ });
1908
+ }
1909
+
1836
1910
  this.emit('published', {status: true, hasStream: !!config.stream});
1837
1911
  this.emit('publishing', false);
1838
1912
  this.emit('localHasVideo', hasVideo);
@@ -1858,7 +1932,7 @@ class RoomSession {
1858
1932
  : Promise.resolve()
1859
1933
  }
1860
1934
 
1861
- toggleAudio(value = null) {
1935
+ toggleAudio(value = null, mid) {
1862
1936
  let handle = this._getHandle(this.handleId);
1863
1937
  if (!handle) {
1864
1938
  return Promise.reject({type: 'error', id: 21, message: 'no local id, connect first', data: null})
@@ -1866,7 +1940,7 @@ class RoomSession {
1866
1940
  let config = handle.webrtcStuff;
1867
1941
  if (this.isUnifiedPlan) {
1868
1942
  let transceiver = config.pc.getTransceivers()
1869
- .find(t => t.sender && t.sender.track && t.receiver.track.kind === "audio" && t.stopped === false);
1943
+ .find(t => t.sender && t.sender.track && t.receiver.track.kind === "audio" && t.stopped === false && (mid ? t.mid === mid : true));
1870
1944
  if (transceiver) {
1871
1945
  transceiver.sender.track.enabled = value !== null ? !!value : !transceiver.sender.track.enabled;
1872
1946
  }
@@ -1877,10 +1951,10 @@ class RoomSession {
1877
1951
  }
1878
1952
  this.isAudioMuted = config.stream.getAudioTracks().length === 0 || !config.stream.getAudioTracks()[0].enabled;
1879
1953
  }
1880
- this.emit('localMuted', {type: 'audio', value: this.isAudioMuted});
1954
+ this.emit('localMuted', {type: 'audio', value: this.isAudioMuted, mid});
1881
1955
  }
1882
1956
 
1883
- toggleVideo() {
1957
+ toggleVideo(value = null, mid) {
1884
1958
  let handle = this._getHandle(this.handleId);
1885
1959
  if (!handle) {
1886
1960
  return Promise.reject({type: 'error', id: 21, message: 'no local id, connect first', data: null})
@@ -1889,19 +1963,19 @@ class RoomSession {
1889
1963
 
1890
1964
  if (this.isUnifiedPlan) {
1891
1965
  let transceiver = config.pc.getTransceivers()
1892
- .find(t => t.sender && t.sender.track && t.receiver.track.kind === "video" && t.stopped === false);
1966
+ .find(t => t.sender && t.sender.track && t.receiver.track.kind === "video" && t.stopped === false && (mid ? t.mid === mid : true));
1893
1967
  if (transceiver) {
1894
- transceiver.sender.track.enabled = !transceiver.sender.track.enabled;
1968
+ transceiver.sender.track.enabled = value !== null ? !!value : !transceiver.sender.track.enabled;
1895
1969
  }
1896
1970
  this.isVideoMuted = !transceiver || !transceiver.sender.track.enabled;
1897
1971
  }
1898
1972
  else {
1899
1973
  if (config.stream && config.stream.getVideoTracks().length) {
1900
- config.stream.getVideoTracks()[0].enabled = !config.stream.getVideoTracks()[0].enabled;
1974
+ config.stream.getVideoTracks()[0].enabled = value !== null ? !!value : !config.stream.getVideoTracks()[0].enabled;
1901
1975
  }
1902
1976
  this.isVideoMuted = config.stream.getVideoTracks().length === 0 || !config.stream.getVideoTracks()[0].enabled;
1903
1977
  }
1904
- this.emit('localMuted', {type: 'video', value: this.isVideoMuted});
1978
+ this.emit('localMuted', {type: 'video', value: this.isVideoMuted, mid});
1905
1979
  }
1906
1980
 
1907
1981
  setInstructorId(instructorId = null) {