@reactoo/watchtogether-sdk-js 2.7.80 → 2.7.82
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.min.js +2 -2
- package/example/index.html +7 -1
- package/package.json +1 -1
- package/src/index.js +2 -2
- package/src/models/asset.js +1 -1
- package/src/models/auth.js +5 -5
- package/src/models/room-session.js +1 -1
- package/src/models/room.js +6 -6
- package/src/models/user.js +10 -10
- package/src/models/utils.js +261 -116
- package/src/modules/sync-modules/sync-dash-vod.js +63 -63
- package/src/modules/sync-modules/sync-dash.js +85 -85
- package/src/modules/sync-modules/sync-dazn-dash.js +92 -92
- package/src/modules/sync-modules/sync-dazn.js +91 -91
- package/src/modules/sync-modules/sync-doris.js +84 -84
- package/src/modules/sync-modules/sync-hls-vod.js +65 -65
- package/src/modules/sync-modules/sync-hls.js +58 -58
- package/src/modules/sync-modules/sync-module.js +68 -68
- package/src/modules/sync-modules/sync-native-hls-vod.js +66 -66
- package/src/modules/sync-modules/sync-native-hls.js +82 -82
- package/src/modules/sync-modules/sync-shaka-dash-vod.js +62 -62
- package/src/modules/sync-modules/sync-shaka-dash.js +93 -93
- package/src/modules/wt-iot.js +1 -1
- package/src/modules/wt-iot2.js +1 -1
- package/src/modules/wt-room.js +5 -4
- package/src/modules/wt-utils.js +0 -142
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {wait} from "
|
|
1
|
+
import {wait} from "../../models/utils";
|
|
2
2
|
|
|
3
3
|
const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
7
7
|
let _videoElement = null;
|
|
8
8
|
let _roomId = null;
|
|
9
9
|
let _syncDisabled = false;
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
const syncDefaultWaitTime = 60000;
|
|
12
12
|
const syncShortWaitTime = 10000;
|
|
13
13
|
const maxSyncThreshold = 0.5;
|
|
@@ -19,42 +19,42 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
19
19
|
let isSyncing = false;
|
|
20
20
|
let seekingDebounceId = null
|
|
21
21
|
let seekingDebounceTimeout = 300;
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
let isPlaying = false;
|
|
24
24
|
let isProgrammaticallySeeked = false;
|
|
25
25
|
let isForcedMaster = false;
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
const startSyncLoop = () => {
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
if(_syncDisabled) {
|
|
30
30
|
room._log('--- Sync loop will not start due to sync force disabled ---');
|
|
31
31
|
return
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
if(!isConnected()) {
|
|
35
35
|
room._log('--- Sync loop will not start due to user not connected yet ---');
|
|
36
36
|
return
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
if(syncWaitId) {
|
|
40
40
|
room._log('--- Sync loop already running ---');
|
|
41
41
|
return
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
room._log('--- Sync enabled ---');
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
stopFlag = false;
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
const loop = () => {
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
isSyncing = true;
|
|
51
51
|
emitter.emit('playerSyncing', true);
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
sync().finally(() => {
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
isSyncing = false;
|
|
56
56
|
emitter.emit('playerSyncing', false);
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
if(isConnected() && !stopFlag) {
|
|
59
59
|
syncWaitId = setTimeout(loop, syncNextWaitTime);
|
|
60
60
|
}
|
|
@@ -62,36 +62,36 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
62
62
|
room._log('--- Automatic stop due to user not connected or stop flag enabled ---');
|
|
63
63
|
stopSyncLoop();
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
})
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
};
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
loop();
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
const stopSyncLoop = () => {
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
room._log('--- Sync disabled ---');
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
clearTimeout(syncWaitId);
|
|
79
79
|
syncWaitId = null;
|
|
80
80
|
currentSyncRetry = 0
|
|
81
81
|
stopFlag = true;
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
const restartSyncLoop = () => {
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
room._log('--- Sync restarting ---');
|
|
88
88
|
stopSyncLoop();
|
|
89
89
|
startSyncLoop();
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
};
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
const setNextWaitTime = (didSyncFail = false) => {
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
if(!didSyncFail) {
|
|
96
96
|
syncNextWaitTime = syncDefaultWaitTime;
|
|
97
97
|
currentSyncRetry = 0
|
|
@@ -104,54 +104,54 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
104
104
|
syncNextWaitTime = syncShortWaitTime;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
room._log('--- Next sync will occur in ' + syncNextWaitTime / 1000 + ' seconds ---');
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
const sync = () => {
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
return getSyncData()
|
|
115
115
|
.then(syncData => {
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
if(syncData.isMaster || stopFlag) {
|
|
118
118
|
setNextWaitTime(false);
|
|
119
119
|
return Promise.resolve();
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
else if(isForcedMaster) {
|
|
123
123
|
setNextWaitTime(false);
|
|
124
124
|
return propagateMasterFunc();
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
else {
|
|
128
|
-
|
|
128
|
+
|
|
129
129
|
const syncStartTime = Date.now();
|
|
130
130
|
const {position, isBufferSufficient} = calculateSyncDifferenceTime(syncData.masterFragmentSn, syncData.masterFragmentPos, syncData.ping);
|
|
131
131
|
const currentPosition = getCurrentSegmentPosition() / 1000;
|
|
132
|
-
|
|
132
|
+
|
|
133
133
|
if(syncData.masterFragmentSn) {
|
|
134
134
|
playMedia()
|
|
135
135
|
} else {
|
|
136
136
|
pauseMedia()
|
|
137
137
|
}
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
if(position && Math.abs(position - currentPosition) <= maxSyncThreshold) {
|
|
140
140
|
room._log(`We're within max sync threshold, no need to resync now`);
|
|
141
141
|
setNextWaitTime(false);
|
|
142
142
|
return Promise.resolve();
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
if(position !== null) {
|
|
146
146
|
return seekTo(position)
|
|
147
147
|
.then(() => {
|
|
148
148
|
const seekDuration = (Date.now() - syncStartTime) / 1000;
|
|
149
149
|
const syncPrecision = Math.abs((position + (isPlaying ? seekDuration : 0)) - (getCurrentSegmentPosition() / 1000))
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
room._log(`Insufficient buffer: `, !isBufferSufficient);
|
|
152
152
|
room._log(`Seek duration is ${seekDuration}`);
|
|
153
153
|
room._log(`Sync precision should be ${syncPrecision}`);
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
const didSyncFail = syncPrecision > maxSyncThreshold
|
|
156
156
|
setNextWaitTime(didSyncFail);
|
|
157
157
|
return Promise.resolve();
|
|
@@ -169,8 +169,8 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
169
169
|
setNextWaitTime(true);
|
|
170
170
|
})
|
|
171
171
|
}
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
|
|
173
|
+
|
|
174
174
|
const handleAddLocalParticipant = () => {
|
|
175
175
|
if(isForcedMaster) {
|
|
176
176
|
propagateMasterFunc();
|
|
@@ -182,13 +182,13 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
182
182
|
}, 1000);
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
|
-
|
|
185
|
+
|
|
186
186
|
const handleAddRemoteParticipant = () => {
|
|
187
187
|
if(isForcedMaster) {
|
|
188
188
|
propagateMasterFunc();
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
const handleRemoveRemoteParticipant = () => {
|
|
193
193
|
if(isForcedMaster) {
|
|
194
194
|
propagateMasterFunc();
|
|
@@ -204,22 +204,22 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
204
204
|
handleStalledWaiting();
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
|
-
|
|
207
|
+
|
|
208
208
|
const executePlayerIotEvents = (data) => {
|
|
209
209
|
let rid = _roomId || room.roomId;
|
|
210
210
|
if(data.attributeName === 'playerReplay' && (!rid || data?.roomId === rid)) {
|
|
211
211
|
seekTo(0).then(() => playMedia());
|
|
212
212
|
}
|
|
213
|
-
|
|
213
|
+
|
|
214
214
|
if(data.attributeName === 'playerPlay' && (!rid || data?.roomId === rid)) {
|
|
215
215
|
playMedia();
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
if(data.attributeName === 'playerPause' && (!rid || data?.roomId === rid)) {
|
|
219
219
|
pauseMedia();
|
|
220
220
|
}
|
|
221
221
|
};
|
|
222
|
-
|
|
222
|
+
|
|
223
223
|
const parseIotEvents = (data) => {
|
|
224
224
|
if(data.event === 'template_updated') {
|
|
225
225
|
if(data.operation === 'multi') {
|
|
@@ -234,9 +234,9 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
|
-
|
|
237
|
+
|
|
238
238
|
const parseDataEvents = (msg = {}) => {
|
|
239
|
-
|
|
239
|
+
|
|
240
240
|
if(msg.videoroom === 'sync_source_set' && msg.wt_channel_id != "") {
|
|
241
241
|
emitter.emit('changePlayerSource', msg.wt_channel_id);
|
|
242
242
|
}
|
|
@@ -244,24 +244,24 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
244
244
|
roomSyncSend(msg.sync_slave_id).catch(()=>{});
|
|
245
245
|
}
|
|
246
246
|
else if(msg.videoroom === 'message') {
|
|
247
|
-
|
|
247
|
+
|
|
248
248
|
// ignoring non studio commands if master
|
|
249
249
|
if(isForcedMaster && msg.from !== null) {
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
|
|
253
253
|
if(_syncDisabled) {
|
|
254
254
|
return;
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
|
|
257
257
|
if(msg.user_action === 'sync_seeking') {
|
|
258
258
|
seekMedia(msg)
|
|
259
259
|
.catch(() => {
|
|
260
|
-
|
|
260
|
+
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
263
|
else if(msg.user_action === 'sync_seeked') {
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
}
|
|
266
266
|
else if(msg.user_action === 'sync_play' || msg.action === 'sync_play') {
|
|
267
267
|
playMedia();
|
|
@@ -541,22 +541,22 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
541
541
|
__events: ['playerSyncing'],
|
|
542
542
|
|
|
543
543
|
initialize: ({shakaInstance, libraryInstance, propagateMaster = false, isStudio = false, roomId, syncDisabled} = {}) => {
|
|
544
|
-
|
|
544
|
+
|
|
545
545
|
_libraryInstance = shakaInstance || libraryInstance;
|
|
546
546
|
_videoElement = _libraryInstance.getMediaElement();
|
|
547
547
|
_roomId = roomId;
|
|
548
548
|
_syncDisabled = syncDisabled;
|
|
549
|
-
|
|
549
|
+
|
|
550
550
|
if(!_libraryInstance) {
|
|
551
551
|
console.log('No shaka player instance');
|
|
552
552
|
return;
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
emitter.emit('playerSyncing', false);
|
|
556
|
-
|
|
556
|
+
|
|
557
557
|
isForcedMaster = propagateMaster;
|
|
558
558
|
isPlaying = _videoElement.paused === false;
|
|
559
|
-
|
|
559
|
+
|
|
560
560
|
room.on('disconnect', stopSyncLoop);
|
|
561
561
|
room.on('addLocalParticipant', handleAddLocalParticipant);
|
|
562
562
|
room.on('removeLocalParticipant', stopSyncLoop);
|
|
@@ -564,7 +564,7 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
564
564
|
room.on('removeRemoteParticipant', handleRemoveRemoteParticipant);
|
|
565
565
|
room.on('data', parseDataEvents);
|
|
566
566
|
wt.iot.$on('message', parseIotEvents);
|
|
567
|
-
|
|
567
|
+
|
|
568
568
|
if(isForcedMaster) {
|
|
569
569
|
propagateMasterFunc().catch(() => {});
|
|
570
570
|
}
|
|
@@ -588,7 +588,7 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
588
588
|
|
|
589
589
|
destroy: () => {
|
|
590
590
|
stopSyncLoop();
|
|
591
|
-
|
|
591
|
+
|
|
592
592
|
room.off('disconnect', stopSyncLoop);
|
|
593
593
|
room.off('addLocalParticipant', handleAddLocalParticipant);
|
|
594
594
|
room.off('removeLocalParticipant', stopSyncLoop);
|
|
@@ -608,7 +608,7 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
608
608
|
_videoElement.removeEventListener('seeked', handleSeeked);
|
|
609
609
|
_videoElement.removeEventListener('ended', handleEnded);
|
|
610
610
|
}
|
|
611
|
-
|
|
611
|
+
|
|
612
612
|
_libraryInstance = null;
|
|
613
613
|
_videoElement = null;
|
|
614
614
|
}
|