@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,13 +1,13 @@
|
|
|
1
|
-
import {wait} from "
|
|
1
|
+
import {wait} from "../../models/utils";
|
|
2
2
|
|
|
3
3
|
const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
|
|
6
6
|
//SYNC VARS
|
|
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,43 +19,43 @@ const syncVodHlsJs = 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
|
-
|
|
27
|
-
|
|
26
|
+
|
|
27
|
+
|
|
28
28
|
const startSyncLoop = () => {
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
if(_syncDisabled) {
|
|
31
31
|
room._log('--- Sync loop will not start due to sync force disabled ---');
|
|
32
32
|
return
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
if(!isConnected()) {
|
|
36
36
|
room._log('--- Sync loop will not start due to user not connected yet ---');
|
|
37
37
|
return
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
if(syncWaitId) {
|
|
41
41
|
room._log('--- Sync loop already running ---');
|
|
42
42
|
return
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
room._log('--- Sync enabled ---');
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
stopFlag = false;
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
const loop = () => {
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
isSyncing = true;
|
|
52
52
|
emitter.emit('playerSyncing', true);
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
sync().finally(() => {
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
isSyncing = false;
|
|
57
57
|
emitter.emit('playerSyncing', false);
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
if(isConnected() && !stopFlag) {
|
|
60
60
|
syncWaitId = setTimeout(loop, syncNextWaitTime);
|
|
61
61
|
}
|
|
@@ -63,36 +63,36 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
63
63
|
room._log('--- Automatic stop due to user not connected or stop flag enabled ---');
|
|
64
64
|
stopSyncLoop();
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
})
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
loop();
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
};
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
const stopSyncLoop = () => {
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
room._log('--- Sync disabled ---');
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
clearTimeout(syncWaitId);
|
|
80
80
|
syncWaitId = null;
|
|
81
81
|
currentSyncRetry = 0
|
|
82
82
|
stopFlag = true;
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
};
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
const restartSyncLoop = () => {
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
room._log('--- Sync restarting ---');
|
|
89
89
|
stopSyncLoop();
|
|
90
90
|
startSyncLoop();
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
};
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
const setNextWaitTime = (didSyncFail = false) => {
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
if(!didSyncFail) {
|
|
97
97
|
syncNextWaitTime = syncDefaultWaitTime;
|
|
98
98
|
currentSyncRetry = 0
|
|
@@ -105,54 +105,54 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
105
105
|
syncNextWaitTime = syncShortWaitTime;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
room._log('--- Next sync will occur in ' + syncNextWaitTime / 1000 + ' seconds ---');
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
const sync = () => {
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
return getSyncData()
|
|
116
116
|
.then(syncData => {
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
if(syncData.isMaster || stopFlag) {
|
|
119
119
|
setNextWaitTime(false);
|
|
120
120
|
return Promise.resolve();
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
|
|
123
123
|
else if(isForcedMaster) {
|
|
124
124
|
setNextWaitTime(false);
|
|
125
125
|
return propagateMasterFunc();
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
else {
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
const syncStartTime = Date.now();
|
|
131
131
|
const {position, isBufferSufficient} = calculateSyncDifferenceTime(syncData.masterFragmentSn, syncData.masterFragmentPos, syncData.ping);
|
|
132
132
|
const currentPosition = getCurrentSegmentPosition() / 1000;
|
|
133
|
-
|
|
133
|
+
|
|
134
134
|
if(syncData.masterFragmentSn) {
|
|
135
135
|
playMedia()
|
|
136
136
|
} else {
|
|
137
137
|
pauseMedia()
|
|
138
138
|
}
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
if(position && Math.abs(position - currentPosition) <= maxSyncThreshold) {
|
|
141
141
|
room._log(`We're within max sync threshold, no need to resync now`);
|
|
142
142
|
setNextWaitTime(false);
|
|
143
143
|
return Promise.resolve();
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
if(position !== null) {
|
|
147
147
|
return seekTo(position)
|
|
148
148
|
.then(() => {
|
|
149
149
|
const seekDuration = (Date.now() - syncStartTime) / 1000;
|
|
150
150
|
const syncPrecision = Math.abs((position + (isPlaying ? seekDuration : 0)) - (getCurrentSegmentPosition() / 1000))
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
room._log(`Insufficient buffer: `, !isBufferSufficient);
|
|
153
153
|
room._log(`Seek duration is ${seekDuration}`);
|
|
154
154
|
room._log(`Sync precision should be ${syncPrecision}`);
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
const didSyncFail = syncPrecision > maxSyncThreshold
|
|
157
157
|
setNextWaitTime(didSyncFail);
|
|
158
158
|
return Promise.resolve();
|
|
@@ -170,7 +170,7 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
170
170
|
setNextWaitTime(true);
|
|
171
171
|
})
|
|
172
172
|
}
|
|
173
|
-
|
|
173
|
+
|
|
174
174
|
const handleAddLocalParticipant = () => {
|
|
175
175
|
if(isForcedMaster) {
|
|
176
176
|
propagateMasterFunc();
|
|
@@ -182,7 +182,7 @@ const syncVodHlsJs = 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();
|
|
@@ -198,22 +198,22 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
198
198
|
const isConnected = () => {
|
|
199
199
|
return room._isDataChannelOpen && room.isConnected;
|
|
200
200
|
};
|
|
201
|
-
|
|
201
|
+
|
|
202
202
|
const executePlayerIotEvents = (data) => {
|
|
203
203
|
let rid = _roomId || room.roomId;
|
|
204
204
|
if(data.attributeName === 'playerReplay' && (!rid || data?.roomId === rid)) {
|
|
205
205
|
seekTo(0).then(() => playMedia());
|
|
206
206
|
}
|
|
207
|
-
|
|
207
|
+
|
|
208
208
|
if(data.attributeName === 'playerPlay' && (!rid || data?.roomId === rid)) {
|
|
209
209
|
playMedia();
|
|
210
210
|
}
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
if(data.attributeName === 'playerPause' && (!rid || data?.roomId === rid)) {
|
|
213
213
|
pauseMedia();
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
|
-
|
|
216
|
+
|
|
217
217
|
const parseIotEvents = (data) => {
|
|
218
218
|
if(data.event === 'template_updated') {
|
|
219
219
|
if(data.operation === 'multi') {
|
|
@@ -228,9 +228,9 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
|
-
|
|
231
|
+
|
|
232
232
|
const parseDataEvents = (msg = {}) => {
|
|
233
|
-
|
|
233
|
+
|
|
234
234
|
if(msg.videoroom === 'sync_source_set' && msg.wt_channel_id != "") {
|
|
235
235
|
emitter.emit('changePlayerSource', msg.wt_channel_id);
|
|
236
236
|
}
|
|
@@ -238,20 +238,20 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
238
238
|
roomSyncSend(msg.sync_slave_id).catch(()=>{});
|
|
239
239
|
}
|
|
240
240
|
else if(msg.videoroom === 'message') {
|
|
241
|
-
|
|
241
|
+
|
|
242
242
|
// ignoring non studio commands if master
|
|
243
243
|
if(isForcedMaster && msg.from !== null) {
|
|
244
244
|
return;
|
|
245
245
|
}
|
|
246
|
-
|
|
246
|
+
|
|
247
247
|
if(_syncDisabled) {
|
|
248
248
|
return;
|
|
249
249
|
}
|
|
250
|
-
|
|
250
|
+
|
|
251
251
|
if(msg.user_action === 'sync_seeking') {
|
|
252
252
|
seekMedia(msg)
|
|
253
253
|
.catch(() => {
|
|
254
|
-
|
|
254
|
+
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
257
|
else if(msg.user_action === 'sync_seeked') {
|
|
@@ -535,21 +535,21 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
535
535
|
__events: ['playerSyncing'],
|
|
536
536
|
|
|
537
537
|
initialize: ({videoElement , propagateMaster = false, isStudio = false, roomId, syncDisabled} = {}) => {
|
|
538
|
-
|
|
538
|
+
|
|
539
539
|
_videoElement = videoElement;
|
|
540
540
|
_roomId = roomId;
|
|
541
541
|
_syncDisabled = syncDisabled;
|
|
542
|
-
|
|
542
|
+
|
|
543
543
|
if(!_videoElement) {
|
|
544
544
|
room._log('No video element present!');
|
|
545
545
|
return;
|
|
546
546
|
}
|
|
547
547
|
|
|
548
548
|
emitter.emit('playerSyncing', false);
|
|
549
|
-
|
|
549
|
+
|
|
550
550
|
isForcedMaster = propagateMaster;
|
|
551
551
|
isPlaying = _videoElement.paused === false;
|
|
552
|
-
|
|
552
|
+
|
|
553
553
|
room.on('disconnect', stopSyncLoop);
|
|
554
554
|
room.on('addLocalParticipant', handleAddLocalParticipant);
|
|
555
555
|
room.on('removeLocalParticipant', stopSyncLoop);
|
|
@@ -557,11 +557,11 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
557
557
|
room.on('removeRemoteParticipant', handleRemoveRemoteParticipant);
|
|
558
558
|
room.on('data', parseDataEvents);
|
|
559
559
|
wt.iot.$on('message', parseIotEvents);
|
|
560
|
-
|
|
560
|
+
|
|
561
561
|
if(isForcedMaster) {
|
|
562
562
|
propagateMasterFunc().catch(() => {});
|
|
563
563
|
}
|
|
564
|
-
|
|
564
|
+
|
|
565
565
|
if(_videoElement) {
|
|
566
566
|
(
|
|
567
567
|
propagateMaster || isStudio ?
|
|
@@ -580,9 +580,9 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
580
580
|
},
|
|
581
581
|
|
|
582
582
|
destroy: () => {
|
|
583
|
-
|
|
583
|
+
|
|
584
584
|
stopSyncLoop();
|
|
585
|
-
|
|
585
|
+
|
|
586
586
|
room.off('disconnect', stopSyncLoop);
|
|
587
587
|
room.off('addLocalParticipant', handleAddLocalParticipant);
|
|
588
588
|
room.off('removeLocalParticipant', stopSyncLoop);
|
|
@@ -590,8 +590,8 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
590
590
|
room.off('removeRemoteParticipant', handleRemoveRemoteParticipant);
|
|
591
591
|
room.off('data', parseDataEvents);
|
|
592
592
|
wt.iot.$off('message', parseIotEvents);
|
|
593
|
-
|
|
594
|
-
|
|
593
|
+
|
|
594
|
+
|
|
595
595
|
if(_videoElement) {
|
|
596
596
|
_videoElement.removeEventListener('stalled', handleStalledWaiting);
|
|
597
597
|
_videoElement.removeEventListener('playing', handlePlaying);
|
|
@@ -600,7 +600,7 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
600
600
|
_videoElement.removeEventListener('seeked', handleSeeked);
|
|
601
601
|
_videoElement.removeEventListener('ended', handleEnded);
|
|
602
602
|
}
|
|
603
|
-
|
|
603
|
+
|
|
604
604
|
_videoElement = null;
|
|
605
605
|
}
|
|
606
606
|
};
|