@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,14 +1,14 @@
|
|
|
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 _libraryInstance = null;
|
|
8
8
|
let _videoElement = null;
|
|
9
9
|
let _roomId = null;
|
|
10
10
|
let _syncDisabled = false;
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
const syncDefaultWaitTime = 60000;
|
|
13
13
|
const syncShortWaitTime = 10000;
|
|
14
14
|
const maxSyncThreshold = 0.5;
|
|
@@ -20,42 +20,42 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
20
20
|
let isSyncing = false;
|
|
21
21
|
let seekingDebounceId = null
|
|
22
22
|
let seekingDebounceTimeout = 300;
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
let isPlaying = false;
|
|
25
25
|
let isProgrammaticallySeeked = false;
|
|
26
26
|
let isForcedMaster = false;
|
|
27
|
-
|
|
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();
|
|
@@ -184,7 +184,7 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
184
184
|
}, 1000);
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
const handleAddRemoteParticipant = () => {
|
|
189
189
|
if(isForcedMaster) {
|
|
190
190
|
propagateMasterFunc();
|
|
@@ -206,22 +206,22 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
206
206
|
handleStalledWaiting();
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
const executePlayerIotEvents = (data) => {
|
|
211
211
|
let rid = _roomId || room.roomId;
|
|
212
212
|
if(data.attributeName === 'playerReplay' && (!rid || data?.roomId === rid)) {
|
|
213
213
|
seekTo(0).then(() => playMedia());
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
|
|
216
216
|
if(data.attributeName === 'playerPlay' && (!rid || data?.roomId === rid)) {
|
|
217
217
|
playMedia();
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
|
|
220
220
|
if(data.attributeName === 'playerPause' && (!rid || data?.roomId === rid)) {
|
|
221
221
|
pauseMedia();
|
|
222
222
|
}
|
|
223
223
|
};
|
|
224
|
-
|
|
224
|
+
|
|
225
225
|
const parseIotEvents = (data) => {
|
|
226
226
|
if(data.event === 'template_updated') {
|
|
227
227
|
if(data.operation === 'multi') {
|
|
@@ -236,9 +236,9 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
|
-
|
|
239
|
+
|
|
240
240
|
const parseDataEvents = (msg = {}) => {
|
|
241
|
-
|
|
241
|
+
|
|
242
242
|
if(msg.videoroom === 'sync_source_set' && msg.wt_channel_id != "") {
|
|
243
243
|
emitter.emit('changePlayerSource', msg.wt_channel_id);
|
|
244
244
|
}
|
|
@@ -246,20 +246,20 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
246
246
|
roomSyncSend(msg.sync_slave_id).catch(()=>{});
|
|
247
247
|
}
|
|
248
248
|
else if(msg.videoroom === 'message') {
|
|
249
|
-
|
|
249
|
+
|
|
250
250
|
// ignoring non studio commands if master
|
|
251
251
|
if(isForcedMaster && msg.from !== null) {
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
|
-
|
|
254
|
+
|
|
255
255
|
if(_syncDisabled) {
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
|
-
|
|
258
|
+
|
|
259
259
|
if(msg.user_action === 'sync_seeking') {
|
|
260
260
|
seekMedia(msg)
|
|
261
261
|
.catch(() => {
|
|
262
|
-
|
|
262
|
+
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
265
|
else if(msg.user_action === 'sync_seeked') {
|
|
@@ -543,22 +543,22 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
543
543
|
__events: ['playerSyncing'],
|
|
544
544
|
|
|
545
545
|
initialize: ({hlsInstance, libraryInstance, propagateMaster = false, isStudio = false, roomId, syncDisabled} = {}) => {
|
|
546
|
-
|
|
546
|
+
|
|
547
547
|
_libraryInstance = hlsInstance || libraryInstance; // backwards comp;
|
|
548
548
|
_videoElement = _libraryInstance.media
|
|
549
549
|
_roomId = roomId;
|
|
550
550
|
_syncDisabled = syncDisabled;
|
|
551
|
-
|
|
551
|
+
|
|
552
552
|
if(!_libraryInstance) {
|
|
553
553
|
room._log('No hls.js player instance!');
|
|
554
554
|
return;
|
|
555
555
|
}
|
|
556
556
|
|
|
557
557
|
emitter.emit('playerSyncing', false);
|
|
558
|
-
|
|
558
|
+
|
|
559
559
|
isForcedMaster = propagateMaster;
|
|
560
560
|
isPlaying = _videoElement.paused === false;
|
|
561
|
-
|
|
561
|
+
|
|
562
562
|
room.on('disconnect', stopSyncLoop);
|
|
563
563
|
room.on('addLocalParticipant', handleAddLocalParticipant);
|
|
564
564
|
room.on('removeLocalParticipant', stopSyncLoop);
|
|
@@ -566,11 +566,11 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
566
566
|
room.on('removeRemoteParticipant', handleRemoveRemoteParticipant);
|
|
567
567
|
room.on('data', parseDataEvents);
|
|
568
568
|
wt.iot.$on('message', parseIotEvents);
|
|
569
|
-
|
|
569
|
+
|
|
570
570
|
if(isForcedMaster) {
|
|
571
571
|
propagateMasterFunc().catch(() => {});
|
|
572
572
|
}
|
|
573
|
-
|
|
573
|
+
|
|
574
574
|
if(_libraryInstance && _videoElement) {
|
|
575
575
|
(
|
|
576
576
|
propagateMaster || isStudio ?
|
|
@@ -589,9 +589,9 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
589
589
|
},
|
|
590
590
|
|
|
591
591
|
destroy: () => {
|
|
592
|
-
|
|
592
|
+
|
|
593
593
|
stopSyncLoop();
|
|
594
|
-
|
|
594
|
+
|
|
595
595
|
room.off('disconnect', stopSyncLoop);
|
|
596
596
|
room.off('addLocalParticipant', handleAddLocalParticipant);
|
|
597
597
|
room.off('removeLocalParticipant', stopSyncLoop);
|
|
@@ -599,11 +599,11 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
599
599
|
room.off('removeRemoteParticipant', handleRemoveRemoteParticipant);
|
|
600
600
|
room.off('data', parseDataEvents);
|
|
601
601
|
wt.iot.$off('message', parseIotEvents);
|
|
602
|
-
|
|
602
|
+
|
|
603
603
|
if(_libraryInstance) {
|
|
604
604
|
_libraryInstance.off('hlsError', buffering);
|
|
605
605
|
}
|
|
606
|
-
|
|
606
|
+
|
|
607
607
|
if(_videoElement) {
|
|
608
608
|
_videoElement.removeEventListener('playing', handlePlaying);
|
|
609
609
|
_videoElement.removeEventListener('pause', handlePause);
|
|
@@ -611,7 +611,7 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
611
611
|
_videoElement.removeEventListener('seeked', handleSeeked);
|
|
612
612
|
_videoElement.removeEventListener('ended', handleEnded);
|
|
613
613
|
}
|
|
614
|
-
|
|
614
|
+
|
|
615
615
|
_libraryInstance = null;
|
|
616
616
|
_videoElement = null;
|
|
617
617
|
}
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
* */
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
import {setExactTimeout} from "
|
|
20
|
+
import {setExactTimeout} from "../../models/utils";
|
|
21
21
|
|
|
22
22
|
const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
//SYNC VARS
|
|
25
25
|
let _libraryInstance = null;
|
|
26
26
|
let _videoElement = null;
|
|
27
27
|
let currentFragmentSn = null;
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
const syncDefaultWaitTime = 60000;
|
|
30
30
|
const syncShortWaitTime = 10000;
|
|
31
31
|
const maxSyncThreshold = 0.5;
|
|
@@ -35,39 +35,39 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
35
35
|
let syncNextWaitTime = null;
|
|
36
36
|
let stopFlag = false;
|
|
37
37
|
let isSyncing = false;
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
let playbackRate = 2;
|
|
40
40
|
let isPlaying = false;
|
|
41
41
|
let isPreloading = true;
|
|
42
42
|
let isProgrammaticallySeeked = false;
|
|
43
43
|
let shouldPropagateMaster = false;
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
const startSyncLoop = () => {
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
if(!isConnected()) {
|
|
48
48
|
room._log('--- Sync loop will not start due to user not connected yet ---');
|
|
49
49
|
return
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
if(syncWaitId) {
|
|
53
53
|
room._log('--- Sync loop already running ---');
|
|
54
54
|
return
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
room._log('--- Sync enabled ---');
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
stopFlag = false;
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
const loop = () => {
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
isSyncing = true;
|
|
64
64
|
emitter.emit('playerSyncing', true);
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
sync().finally(() => {
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
isSyncing = false;
|
|
69
69
|
emitter.emit('playerSyncing', false);
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
if(isConnected() && !stopFlag) {
|
|
72
72
|
syncWaitId = setTimeout(loop, syncNextWaitTime);
|
|
73
73
|
}
|
|
@@ -75,36 +75,36 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
75
75
|
room._log('--- Automatic stop due to user not connected or stop flag enabled ---');
|
|
76
76
|
stopSyncLoop();
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
})
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
};
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
loop();
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
const stopSyncLoop = () => {
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
room._log('--- Sync disabled ---');
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
clearTimeout(syncWaitId);
|
|
92
92
|
syncWaitId = null;
|
|
93
93
|
currentSyncRetry = 0
|
|
94
94
|
stopFlag = true;
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
const restartSyncLoop = () => {
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
room._log('--- Sync restarting ---');
|
|
101
101
|
stopSyncLoop();
|
|
102
102
|
startSyncLoop();
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
};
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
const setNextWaitTime = (didSyncFail = false) => {
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
if(!didSyncFail) {
|
|
109
109
|
syncNextWaitTime = syncDefaultWaitTime;
|
|
110
110
|
currentSyncRetry = 0
|
|
@@ -117,49 +117,49 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
117
117
|
syncNextWaitTime = syncShortWaitTime;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
room._log('--- Next sync will occur in ' + syncNextWaitTime / 1000 + ' seconds ---');
|
|
122
|
-
|
|
122
|
+
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
const sync = () => {
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
return getSyncData()
|
|
128
128
|
.then(syncData => {
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
if(syncData.isMaster) {
|
|
131
131
|
if(_videoElement.paused) _videoElement.play();
|
|
132
132
|
setNextWaitTime(false);
|
|
133
133
|
return Promise.resolve();
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
else if(shouldPropagateMaster) {
|
|
137
137
|
setNextWaitTime(false);
|
|
138
138
|
return propagateMasterFunc();
|
|
139
139
|
}
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
else {
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
const syncStartTime = Date.now();
|
|
144
144
|
const {position, isBufferSufficient} = calculateSyncDifferenceTime(syncData.masterFragmentSn, syncData.masterFragmentPos, syncData.ping);
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
if(position && Math.abs(position) <= maxSyncThreshold) {
|
|
147
147
|
room._log(`We're within max sync threshold, no need to resync now`);
|
|
148
148
|
setNextWaitTime(false);
|
|
149
149
|
return Promise.resolve();
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
if(position !== null) {
|
|
153
153
|
return seekBy(position)
|
|
154
154
|
.then(() => {
|
|
155
155
|
const seekDuration = (Date.now() - syncStartTime);
|
|
156
156
|
const {position, isBufferSufficient} = calculateSyncDifferenceTime(syncData.masterFragmentSn, syncData.masterFragmentPos + seekDuration, syncData.ping);
|
|
157
157
|
const syncPrecision = Math.abs(position);
|
|
158
|
-
|
|
158
|
+
|
|
159
159
|
room._log(`Insufficient buffer: `, !isBufferSufficient);
|
|
160
160
|
room._log(`Seek duration is ${seekDuration / 1000}`);
|
|
161
161
|
room._log(`Sync precision should be ${syncPrecision}`);
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
const didSyncFail = syncPrecision > maxSyncThreshold
|
|
164
164
|
setNextWaitTime(didSyncFail);
|
|
165
165
|
return Promise.resolve();
|
|
@@ -178,7 +178,7 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
178
178
|
return Promise.reject();
|
|
179
179
|
})
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
const handleAddLocalParticipant = () => {
|
|
183
183
|
if(shouldPropagateMaster) {
|
|
184
184
|
propagateMasterFunc();
|
|
@@ -205,7 +205,7 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
205
205
|
handleStalledWaiting();
|
|
206
206
|
}
|
|
207
207
|
};
|
|
208
|
-
|
|
208
|
+
|
|
209
209
|
const hlsFragChanged = (event, data) => {
|
|
210
210
|
currentFragmentSn = data.frag.sn;
|
|
211
211
|
};
|
|
@@ -577,14 +577,14 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
577
577
|
});
|
|
578
578
|
|
|
579
579
|
};
|
|
580
|
-
|
|
580
|
+
|
|
581
581
|
const clientPaused = () => {
|
|
582
582
|
room._log('Sending client paused');
|
|
583
|
-
|
|
583
|
+
|
|
584
584
|
if(!isConnected()) {
|
|
585
585
|
return Promise.resolve();
|
|
586
586
|
}
|
|
587
|
-
|
|
587
|
+
|
|
588
588
|
return room.sendMessage(room.handleId, {
|
|
589
589
|
body:{
|
|
590
590
|
request: "sync_paused",
|
|
@@ -594,7 +594,7 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
594
594
|
fragment_pos:0
|
|
595
595
|
}});
|
|
596
596
|
};
|
|
597
|
-
|
|
597
|
+
|
|
598
598
|
const propagateMasterFunc = () => {
|
|
599
599
|
room._log('Propagating master');
|
|
600
600
|
if(!isConnected()) {
|
|
@@ -616,34 +616,34 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
616
616
|
__events: ['playerSyncing'],
|
|
617
617
|
|
|
618
618
|
initialize: ({hlsInstance, libraryInstance, propagateMaster = false} = {}) => {
|
|
619
|
-
|
|
619
|
+
|
|
620
620
|
_libraryInstance = hlsInstance || libraryInstance; // backwards comp;
|
|
621
621
|
_videoElement = _libraryInstance.media
|
|
622
|
-
|
|
622
|
+
|
|
623
623
|
if(!_libraryInstance) {
|
|
624
624
|
room._log('No hls.js player instance!');
|
|
625
625
|
return;
|
|
626
626
|
}
|
|
627
|
-
|
|
627
|
+
|
|
628
628
|
shouldPropagateMaster = propagateMaster;
|
|
629
629
|
isPlaying = _videoElement.paused === false;
|
|
630
|
-
|
|
630
|
+
|
|
631
631
|
room.on('disconnect', stopSyncLoop);
|
|
632
632
|
room.on('removeLocalParticipant', stopSyncLoop);
|
|
633
633
|
room.on('addLocalParticipant', handleAddLocalParticipant);
|
|
634
634
|
room.on('addRemoteParticipant', handleAddRemoteParticipant);
|
|
635
635
|
room.on('data', parseDataEvents);
|
|
636
|
-
|
|
636
|
+
|
|
637
637
|
if(shouldPropagateMaster) {
|
|
638
638
|
propagateMasterFunc().catch(() => {});
|
|
639
639
|
}
|
|
640
|
-
|
|
640
|
+
|
|
641
641
|
if(_videoElement && _videoElement.paused === false) {
|
|
642
642
|
_libraryInstance.once('hlsFragChanged', () => {
|
|
643
643
|
restartSyncLoop();
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
|
-
|
|
646
|
+
|
|
647
647
|
_libraryInstance.on('hlsError', buffering);
|
|
648
648
|
_libraryInstance.on('hlsFragChanged', hlsFragChanged);
|
|
649
649
|
_videoElement.addEventListener('playing', handlePlaying);
|
|
@@ -652,27 +652,27 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
652
652
|
},
|
|
653
653
|
|
|
654
654
|
destroy: () => {
|
|
655
|
-
|
|
655
|
+
|
|
656
656
|
stopSyncLoop();
|
|
657
|
-
|
|
657
|
+
|
|
658
658
|
room.off('disconnect', stopSyncLoop);
|
|
659
659
|
room.off('removeLocalParticipant', stopSyncLoop);
|
|
660
660
|
room.off('addLocalParticipant', handleAddLocalParticipant);
|
|
661
661
|
room.off('addRemoteParticipant', handleAddRemoteParticipant);
|
|
662
662
|
room.off('data', parseDataEvents);
|
|
663
|
-
|
|
663
|
+
|
|
664
664
|
if(_libraryInstance) {
|
|
665
665
|
_libraryInstance.off('hlsError', buffering);
|
|
666
666
|
_libraryInstance.off('hlsFragChanged', hlsFragChanged);
|
|
667
667
|
}
|
|
668
|
-
|
|
668
|
+
|
|
669
669
|
if(_videoElement) {
|
|
670
670
|
_videoElement.removeEventListener('playing', handlePlaying);
|
|
671
671
|
_videoElement.removeEventListener('pause', handlePause);
|
|
672
672
|
}
|
|
673
|
-
|
|
673
|
+
|
|
674
674
|
_libraryInstance = null;
|
|
675
|
-
|
|
675
|
+
|
|
676
676
|
}
|
|
677
677
|
};
|
|
678
678
|
};
|