@reactoo/watchtogether-sdk-js 2.8.56 → 2.8.57

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.
@@ -584,6 +584,14 @@
584
584
  Instance.room.getSessionByConstructId(constructId).sendMessageViaDataChannel(null, {cicina:true})
585
585
  }
586
586
 
587
+ window.audioOnlyOn = function() {
588
+ Instance.room.getSessionByConstructId(constructId).setRestrictToAudioOnly(true)
589
+ }
590
+
591
+ window.audioOnlyOff = function() {
592
+ Instance.room.getSessionByConstructId(constructId).setRestrictToAudioOnly(false)
593
+ }
594
+
587
595
  </script>
588
596
 
589
597
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.8.56",
3
+ "version": "2.8.57",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
package/src/models/iot.js CHANGED
@@ -275,7 +275,7 @@ let iot = function () {
275
275
  }
276
276
 
277
277
  this.__privates.iot.log('Connection check failed:', error);
278
- this.iot.$emit('iotConnectionLost');
278
+ this.iot.$emit('iotConnectionLost', error);
279
279
  return this.iot.__updateCredentials();
280
280
  });
281
281
  },
@@ -371,6 +371,10 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
371
371
  return room.toggleVideo(value, source);
372
372
  },
373
373
 
374
+ setRestrictToAudioOnly: (value = false) => {
375
+ return room.setRestrictToAudioOnly(value);
376
+ },
377
+
374
378
  setRestrictSubscribeToUserIds: (userIds = []) => {
375
379
  return room.setRestrictSubscribeToUserIds(userIds);
376
380
  },
@@ -317,12 +317,14 @@ class RoomSession {
317
317
  this._longPollTimeout = 60000;
318
318
  this._maxev = 10;
319
319
  this._keepAliveId = null;
320
+ this._isDataChannelOpen = false;
321
+ this._abortController = null;
322
+
323
+ this._restrictToAudioOnly = false;
320
324
  this._restrictSubscribeToUserIds = []; // all if empty
321
325
  this._talkIntercomChannels = ['participants'];
322
326
  this._listenIntercomChannels = ['participants'];
323
327
  this._roomType = 'watchparty';
324
- this._isDataChannelOpen = false;
325
- this._abortController = null;
326
328
 
327
329
  this.userRoleSubscriptionRules = {
328
330
  ...RoomSession.userRoleSubscriptionRules,
@@ -330,11 +332,10 @@ class RoomSession {
330
332
  }
331
333
 
332
334
  this._log = RoomSession.noop;
335
+
333
336
  if (this.options.debug) {
334
337
  this.#enableDebug();
335
338
  }
336
-
337
-
338
339
  }
339
340
 
340
341
  #httpAPICall = function(url, options) {
@@ -718,6 +719,7 @@ class RoomSession {
718
719
  for (let i in streams) {
719
720
  const track = streams[i];
720
721
  const mid = track.mid; // source.mid
722
+ const type = track.type; // source.type
721
723
  flatSourceMap.push({id: id, mid: mid});
722
724
 
723
725
  const isSubscribed = this.#isSubscribedToMid(id, mid);
@@ -730,6 +732,14 @@ class RoomSession {
730
732
  continue;
731
733
  }
732
734
 
735
+ if(type === 'video' && this._restrictToAudioOnly) {
736
+ if(isSubscribed) {
737
+ unsubscribe.push({feed: id, mid: mid});
738
+ this.#removeFromSubscribeMap(id, mid);
739
+ }
740
+ continue;
741
+ }
742
+
733
743
  if(!this.#shouldSubscribeParticipant(id, userId, description)) {
734
744
  if(isSubscribed) {
735
745
  unsubscribe.push({feed: id, mid: mid});
@@ -1220,6 +1230,7 @@ class RoomSession {
1220
1230
  this.disconnect().catch(()=>{});
1221
1231
  }
1222
1232
  }
1233
+ // we got warning, so just emit it
1223
1234
  else {
1224
1235
  this.emit('error', e)
1225
1236
  }
@@ -2294,9 +2305,10 @@ class RoomSession {
2294
2305
  #webrtc(handleId, enableOntrack = false, enableOnnegotiationneeded = false) {
2295
2306
 
2296
2307
  let handle = this.#getHandle(handleId);
2308
+
2297
2309
  if (!handle) {
2298
2310
  this.emit('error', {
2299
- type: 'error',
2311
+ type: 'warning',
2300
2312
  id: 24,
2301
2313
  message: 'id non-existent',
2302
2314
  data: [handleId, 'create rtc connection']
@@ -2962,39 +2974,39 @@ class RoomSession {
2962
2974
  async publishLocal(stream = null, source = 'camera0') {
2963
2975
 
2964
2976
  if(!this.isConnected || this.isDisconnecting) {
2965
- return {
2977
+ return Promise.reject({
2966
2978
  type: 'warning',
2967
2979
  id: 35,
2968
2980
  message: 'Either not connected or disconnecting',
2969
- }
2981
+ })
2970
2982
  }
2971
2983
 
2972
2984
  if(stream?.getVideoTracks()?.length > 1) {
2973
- return {
2985
+ return Promise.reject({
2974
2986
  type: 'warning',
2975
2987
  id: 36,
2976
2988
  message: 'multiple video tracks not supported',
2977
2989
  data: null
2978
- }
2990
+ })
2979
2991
  }
2980
2992
 
2981
2993
  if(stream?.getAudioTracks()?.length > 1) {
2982
- return {
2994
+ return Promise.reject({
2983
2995
  type: 'warning',
2984
2996
  id: 37,
2985
2997
  message: 'multiple audio tracks not supported',
2986
2998
  data: null
2987
- }
2999
+ })
2988
3000
  }
2989
3001
 
2990
3002
  let handle = this.#publisherHandle;
2991
3003
  if (!handle) {
2992
- return {
3004
+ return Promise.reject({
2993
3005
  type: 'error',
2994
3006
  id: 38,
2995
3007
  message: 'no local handle, connect before publishing',
2996
3008
  data: null
2997
- }
3009
+ })
2998
3010
  }
2999
3011
 
3000
3012
  this.emit('publishing', true);
@@ -3008,21 +3020,21 @@ class RoomSession {
3008
3020
  }
3009
3021
 
3010
3022
  if(config.stream?.getVideoTracks()?.length > 5) {
3011
- return {
3023
+ return Promise.reject({
3012
3024
  type: 'warning',
3013
3025
  id: 48,
3014
3026
  message: 'too many video tracks, only 5 supported',
3015
3027
  data: null
3016
- }
3028
+ })
3017
3029
  }
3018
3030
 
3019
3031
  if(config.stream?.getAudioTracks()?.length > 5) {
3020
- return {
3032
+ return Promise.reject( {
3021
3033
  type: 'warning',
3022
3034
  id: 49,
3023
3035
  message: 'too many audio tracks, only 5 supported',
3024
3036
  data: null
3025
- }
3037
+ })
3026
3038
  }
3027
3039
 
3028
3040
  let transceivers = config.pc.getTransceivers();
@@ -3251,7 +3263,7 @@ class RoomSession {
3251
3263
  catch(e) {
3252
3264
  this.emit('publishing', false);
3253
3265
  this.emit('error', e);
3254
- throw e;
3266
+ return Promise.reject(e);
3255
3267
  }
3256
3268
 
3257
3269
 
@@ -3489,6 +3501,17 @@ class RoomSession {
3489
3501
  return await this.#updateSubscriptions();
3490
3502
  }
3491
3503
 
3504
+ async setRestrictToAudioOnly(value = false) {
3505
+
3506
+ this._restrictToAudioOnly = !!value;
3507
+ if(!this.isConnected) {
3508
+ return
3509
+ }
3510
+
3511
+ return await this.#updateSubscriptions();
3512
+
3513
+ }
3514
+
3492
3515
  async setRestrictSubscribeToUserIds(userIds = []) {
3493
3516
 
3494
3517
  if(typeof userIds !== 'object' || !("length" in userIds)) {