@reactoo/watchtogether-sdk-js 2.5.20 → 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.20",
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",
@@ -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') {
@@ -1157,10 +1157,11 @@ class RoomSession {
1157
1157
  id: handle.handleId,
1158
1158
  userId: handle.userId,
1159
1159
  stream: config.stream,
1160
+ track: null,
1160
1161
  optional: true,
1161
1162
  constructId: this.constructId,
1162
1163
  metaData: this.options.metaData,
1163
- adding: true,
1164
+ adding: false,
1164
1165
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1165
1166
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1166
1167
  })
@@ -1177,10 +1178,11 @@ class RoomSession {
1177
1178
  id: handle.handleId,
1178
1179
  userId: handle.userId,
1179
1180
  stream: config.stream,
1181
+ track: null,
1180
1182
  optional: true,
1181
1183
  constructId: this.constructId,
1182
1184
  metaData: this.options.metaData,
1183
- adding: true,
1185
+ adding: false,
1184
1186
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1185
1187
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1186
1188
  })
@@ -1212,19 +1214,20 @@ class RoomSession {
1212
1214
  if (enableOntrack) {
1213
1215
  config.pc.ontrack = (event) => {
1214
1216
 
1215
- // if(!event.streams)
1216
- // return;
1217
-
1217
+ if(!event.streams)
1218
+ return;
1219
+
1218
1220
  //config.stream = event.streams[0];
1219
1221
 
1220
1222
  if (!config.stream) {
1221
1223
  config.stream = new MediaStream();
1222
1224
  }
1223
-
1224
1225
  if (event.track) {
1226
+ let mid = event.transceiver ? event.transceiver.mid : event.track.id;
1225
1227
  config.stream.addTrack(event.track);
1226
1228
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1227
1229
  tid: generateUUID(),
1230
+ mid,
1228
1231
  id: handle.handleId,
1229
1232
  userId: handle.userId,
1230
1233
  stream: config.stream,
@@ -1240,17 +1243,27 @@ class RoomSession {
1240
1243
  return;
1241
1244
 
1242
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
+
1243
1254
  if (config.stream) {
1244
1255
  config.stream && config.stream.removeTrack(ev.target);
1245
1256
  this.emit(this._getAddParticipantEventName(handle.handleId), {
1246
1257
  tid: generateUUID(),
1247
1258
  id: handle.handleId,
1259
+ mid,
1248
1260
  userId: handle.userId,
1249
1261
  stream: config.stream,
1250
1262
  track: ev.target,
1251
1263
  constructId: this.constructId,
1252
1264
  metaData: this.options.metaData,
1253
1265
  adding: false,
1266
+ removing: true,
1254
1267
  hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),
1255
1268
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
1256
1269
  });
@@ -1259,8 +1272,17 @@ class RoomSession {
1259
1272
 
1260
1273
  event.track.onmute = (ev) => {
1261
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
+
1262
1283
  this.emit('remoteTrackMuted', {
1263
1284
  id: handle.handleId,
1285
+ mid,
1264
1286
  userId: handle.userId,
1265
1287
  stream: config.stream,
1266
1288
  kind: ev.target.kind,
@@ -1271,8 +1293,17 @@ class RoomSession {
1271
1293
 
1272
1294
  event.track.onunmute = (ev) => {
1273
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
+
1274
1304
  this.emit('remoteTrackMuted', {
1275
1305
  id: handle.handleId,
1306
+ mid,
1276
1307
  userId: handle.userId,
1277
1308
  stream: config.stream,
1278
1309
  kind: ev.target.kind,
@@ -1828,7 +1859,54 @@ class RoomSession {
1828
1859
  })
1829
1860
  .then(r => {
1830
1861
  this._isPublished = true;
1831
- 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
+
1832
1910
  this.emit('published', {status: true, hasStream: !!config.stream});
1833
1911
  this.emit('publishing', false);
1834
1912
  this.emit('localHasVideo', hasVideo);
@@ -1854,7 +1932,7 @@ class RoomSession {
1854
1932
  : Promise.resolve()
1855
1933
  }
1856
1934
 
1857
- toggleAudio(value = null) {
1935
+ toggleAudio(value = null, mid) {
1858
1936
  let handle = this._getHandle(this.handleId);
1859
1937
  if (!handle) {
1860
1938
  return Promise.reject({type: 'error', id: 21, message: 'no local id, connect first', data: null})
@@ -1862,7 +1940,7 @@ class RoomSession {
1862
1940
  let config = handle.webrtcStuff;
1863
1941
  if (this.isUnifiedPlan) {
1864
1942
  let transceiver = config.pc.getTransceivers()
1865
- .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));
1866
1944
  if (transceiver) {
1867
1945
  transceiver.sender.track.enabled = value !== null ? !!value : !transceiver.sender.track.enabled;
1868
1946
  }
@@ -1873,10 +1951,10 @@ class RoomSession {
1873
1951
  }
1874
1952
  this.isAudioMuted = config.stream.getAudioTracks().length === 0 || !config.stream.getAudioTracks()[0].enabled;
1875
1953
  }
1876
- this.emit('localMuted', {type: 'audio', value: this.isAudioMuted});
1954
+ this.emit('localMuted', {type: 'audio', value: this.isAudioMuted, mid});
1877
1955
  }
1878
1956
 
1879
- toggleVideo() {
1957
+ toggleVideo(value = null, mid) {
1880
1958
  let handle = this._getHandle(this.handleId);
1881
1959
  if (!handle) {
1882
1960
  return Promise.reject({type: 'error', id: 21, message: 'no local id, connect first', data: null})
@@ -1885,19 +1963,19 @@ class RoomSession {
1885
1963
 
1886
1964
  if (this.isUnifiedPlan) {
1887
1965
  let transceiver = config.pc.getTransceivers()
1888
- .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));
1889
1967
  if (transceiver) {
1890
- transceiver.sender.track.enabled = !transceiver.sender.track.enabled;
1968
+ transceiver.sender.track.enabled = value !== null ? !!value : !transceiver.sender.track.enabled;
1891
1969
  }
1892
1970
  this.isVideoMuted = !transceiver || !transceiver.sender.track.enabled;
1893
1971
  }
1894
1972
  else {
1895
1973
  if (config.stream && config.stream.getVideoTracks().length) {
1896
- config.stream.getVideoTracks()[0].enabled = !config.stream.getVideoTracks()[0].enabled;
1974
+ config.stream.getVideoTracks()[0].enabled = value !== null ? !!value : !config.stream.getVideoTracks()[0].enabled;
1897
1975
  }
1898
1976
  this.isVideoMuted = config.stream.getVideoTracks().length === 0 || !config.stream.getVideoTracks()[0].enabled;
1899
1977
  }
1900
- this.emit('localMuted', {type: 'video', value: this.isVideoMuted});
1978
+ this.emit('localMuted', {type: 'video', value: this.isVideoMuted, mid});
1901
1979
  }
1902
1980
 
1903
1981
  setInstructorId(instructorId = null) {