@reactoo/watchtogether-sdk-js 2.8.56 → 2.8.58
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/dist/watchtogether-sdk.js +44 -20
- package/dist/watchtogether-sdk.js.map +1 -1
- package/dist/watchtogether-sdk.min.js +2 -2
- package/example/index.html +8 -0
- package/package.json +1 -1
- package/src/models/iot.js +1 -1
- package/src/models/room-session.js +4 -0
- package/src/modules/wt-room-sfu.js +46 -18
package/example/index.html
CHANGED
|
@@ -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
package/src/models/iot.js
CHANGED
|
@@ -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
|
}
|
|
@@ -1812,10 +1823,15 @@ class RoomSession {
|
|
|
1812
1823
|
for (let i in streams) {
|
|
1813
1824
|
const track = streams[i];
|
|
1814
1825
|
const mid = track.mid; // source.mid
|
|
1826
|
+
const type = track.type;
|
|
1815
1827
|
if(track.disabled) {
|
|
1816
1828
|
continue;
|
|
1817
1829
|
}
|
|
1818
1830
|
|
|
1831
|
+
if(type === 'video' && this._restrictToAudioOnly) {
|
|
1832
|
+
continue;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1819
1835
|
if(!this.#shouldSubscribeParticipant(id, userId, description)) {
|
|
1820
1836
|
continue;
|
|
1821
1837
|
}
|
|
@@ -2294,9 +2310,10 @@ class RoomSession {
|
|
|
2294
2310
|
#webrtc(handleId, enableOntrack = false, enableOnnegotiationneeded = false) {
|
|
2295
2311
|
|
|
2296
2312
|
let handle = this.#getHandle(handleId);
|
|
2313
|
+
|
|
2297
2314
|
if (!handle) {
|
|
2298
2315
|
this.emit('error', {
|
|
2299
|
-
type: '
|
|
2316
|
+
type: 'warning',
|
|
2300
2317
|
id: 24,
|
|
2301
2318
|
message: 'id non-existent',
|
|
2302
2319
|
data: [handleId, 'create rtc connection']
|
|
@@ -2962,39 +2979,39 @@ class RoomSession {
|
|
|
2962
2979
|
async publishLocal(stream = null, source = 'camera0') {
|
|
2963
2980
|
|
|
2964
2981
|
if(!this.isConnected || this.isDisconnecting) {
|
|
2965
|
-
return {
|
|
2982
|
+
return Promise.reject({
|
|
2966
2983
|
type: 'warning',
|
|
2967
2984
|
id: 35,
|
|
2968
2985
|
message: 'Either not connected or disconnecting',
|
|
2969
|
-
}
|
|
2986
|
+
})
|
|
2970
2987
|
}
|
|
2971
2988
|
|
|
2972
2989
|
if(stream?.getVideoTracks()?.length > 1) {
|
|
2973
|
-
return {
|
|
2990
|
+
return Promise.reject({
|
|
2974
2991
|
type: 'warning',
|
|
2975
2992
|
id: 36,
|
|
2976
2993
|
message: 'multiple video tracks not supported',
|
|
2977
2994
|
data: null
|
|
2978
|
-
}
|
|
2995
|
+
})
|
|
2979
2996
|
}
|
|
2980
2997
|
|
|
2981
2998
|
if(stream?.getAudioTracks()?.length > 1) {
|
|
2982
|
-
return {
|
|
2999
|
+
return Promise.reject({
|
|
2983
3000
|
type: 'warning',
|
|
2984
3001
|
id: 37,
|
|
2985
3002
|
message: 'multiple audio tracks not supported',
|
|
2986
3003
|
data: null
|
|
2987
|
-
}
|
|
3004
|
+
})
|
|
2988
3005
|
}
|
|
2989
3006
|
|
|
2990
3007
|
let handle = this.#publisherHandle;
|
|
2991
3008
|
if (!handle) {
|
|
2992
|
-
return {
|
|
3009
|
+
return Promise.reject({
|
|
2993
3010
|
type: 'error',
|
|
2994
3011
|
id: 38,
|
|
2995
3012
|
message: 'no local handle, connect before publishing',
|
|
2996
3013
|
data: null
|
|
2997
|
-
}
|
|
3014
|
+
})
|
|
2998
3015
|
}
|
|
2999
3016
|
|
|
3000
3017
|
this.emit('publishing', true);
|
|
@@ -3008,21 +3025,21 @@ class RoomSession {
|
|
|
3008
3025
|
}
|
|
3009
3026
|
|
|
3010
3027
|
if(config.stream?.getVideoTracks()?.length > 5) {
|
|
3011
|
-
return {
|
|
3028
|
+
return Promise.reject({
|
|
3012
3029
|
type: 'warning',
|
|
3013
3030
|
id: 48,
|
|
3014
3031
|
message: 'too many video tracks, only 5 supported',
|
|
3015
3032
|
data: null
|
|
3016
|
-
}
|
|
3033
|
+
})
|
|
3017
3034
|
}
|
|
3018
3035
|
|
|
3019
3036
|
if(config.stream?.getAudioTracks()?.length > 5) {
|
|
3020
|
-
return {
|
|
3037
|
+
return Promise.reject( {
|
|
3021
3038
|
type: 'warning',
|
|
3022
3039
|
id: 49,
|
|
3023
3040
|
message: 'too many audio tracks, only 5 supported',
|
|
3024
3041
|
data: null
|
|
3025
|
-
}
|
|
3042
|
+
})
|
|
3026
3043
|
}
|
|
3027
3044
|
|
|
3028
3045
|
let transceivers = config.pc.getTransceivers();
|
|
@@ -3251,7 +3268,7 @@ class RoomSession {
|
|
|
3251
3268
|
catch(e) {
|
|
3252
3269
|
this.emit('publishing', false);
|
|
3253
3270
|
this.emit('error', e);
|
|
3254
|
-
|
|
3271
|
+
return Promise.reject(e);
|
|
3255
3272
|
}
|
|
3256
3273
|
|
|
3257
3274
|
|
|
@@ -3489,6 +3506,17 @@ class RoomSession {
|
|
|
3489
3506
|
return await this.#updateSubscriptions();
|
|
3490
3507
|
}
|
|
3491
3508
|
|
|
3509
|
+
async setRestrictToAudioOnly(value = false) {
|
|
3510
|
+
|
|
3511
|
+
this._restrictToAudioOnly = !!value;
|
|
3512
|
+
if(!this.isConnected) {
|
|
3513
|
+
return
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
return await this.#updateSubscriptions();
|
|
3517
|
+
|
|
3518
|
+
}
|
|
3519
|
+
|
|
3492
3520
|
async setRestrictSubscribeToUserIds(userIds = []) {
|
|
3493
3521
|
|
|
3494
3522
|
if(typeof userIds !== 'object' || !("length" in userIds)) {
|