@reactoo/watchtogether-sdk-js 2.7.80 → 2.7.81
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 +52636 -0
- package/dist/watchtogether-sdk.js.map +1 -0
- package/dist/watchtogether-sdk.min.js +2 -2
- 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 +5 -5
- 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 +3 -3
- package/src/modules/wt-utils.js +0 -142
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {setExactTimeout} from "
|
|
1
|
+
import {setExactTimeout} from "../../models/utils";
|
|
2
2
|
|
|
3
3
|
const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
//SYNC VARS
|
|
6
6
|
let _libraryInstance = null;
|
|
7
7
|
let _videoElement = null;
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
const syncDefaultWaitTime = 60000;
|
|
10
10
|
const syncShortWaitTime = 10000;
|
|
11
11
|
const maxSyncThreshold = 0.5;
|
|
@@ -15,40 +15,40 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
15
15
|
let syncNextWaitTime = null;
|
|
16
16
|
let stopFlag = false;
|
|
17
17
|
let isSyncing = false;
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
let playbackRate = 2;
|
|
20
20
|
let isPlaying = false;
|
|
21
21
|
let isPreloading = true;
|
|
22
22
|
let isProgrammaticallySeeked = false;
|
|
23
23
|
let shouldPropagateMaster = false;
|
|
24
24
|
let isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
const startSyncLoop = () => {
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
if(!isConnected()) {
|
|
29
29
|
room._log('--- Sync loop will not start due to user not connected yet ---');
|
|
30
30
|
return
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
if(syncWaitId) {
|
|
34
34
|
room._log('--- Sync loop already running ---');
|
|
35
35
|
return
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
room._log('--- Sync enabled ---');
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
stopFlag = false;
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
const loop = () => {
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
isSyncing = true;
|
|
45
45
|
emitter.emit('playerSyncing', true);
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
sync().finally(() => {
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
isSyncing = false;
|
|
50
50
|
emitter.emit('playerSyncing', false);
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
if(isConnected() && !stopFlag) {
|
|
53
53
|
syncWaitId = setTimeout(loop, syncNextWaitTime);
|
|
54
54
|
}
|
|
@@ -56,36 +56,36 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
56
56
|
room._log('--- Automatic stop due to user not connected or stop flag enabled ---');
|
|
57
57
|
stopSyncLoop();
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
})
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
loop();
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
const stopSyncLoop = () => {
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
room._log('--- Sync disabled ---');
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
clearTimeout(syncWaitId);
|
|
73
73
|
syncWaitId = null;
|
|
74
74
|
currentSyncRetry = 0
|
|
75
75
|
stopFlag = true;
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
};
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
const restartSyncLoop = () => {
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
room._log('--- Sync restarting ---');
|
|
82
82
|
stopSyncLoop();
|
|
83
83
|
startSyncLoop();
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
const setNextWaitTime = (didSyncFail = false) => {
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
if(!didSyncFail) {
|
|
90
90
|
syncNextWaitTime = syncDefaultWaitTime;
|
|
91
91
|
currentSyncRetry = 0
|
|
@@ -98,49 +98,49 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
98
98
|
syncNextWaitTime = syncShortWaitTime;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
room._log('--- Next sync will occur in ' + syncNextWaitTime / 1000 + ' seconds ---');
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
const sync = () => {
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
return getSyncData()
|
|
109
109
|
.then(syncData => {
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
if(syncData.isMaster) {
|
|
112
112
|
if(_videoElement.paused) _videoElement.play();
|
|
113
113
|
setNextWaitTime(false);
|
|
114
114
|
return Promise.resolve();
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
else if(shouldPropagateMaster) {
|
|
118
118
|
setNextWaitTime(false);
|
|
119
119
|
return propagateMasterFunc();
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
else {
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
const syncStartTime = Date.now();
|
|
125
125
|
const {position, act, isBufferSufficient} = calculateSyncDifferenceTime(syncData.masterFragmentSn, syncData.masterFragmentPos, syncData.ping);
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
if(position && Math.abs(position) <= maxSyncThreshold) {
|
|
128
128
|
room._log(`We're within max sync threshold, no need to resync now`);
|
|
129
129
|
setNextWaitTime(false);
|
|
130
130
|
return Promise.resolve();
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
|
|
133
133
|
if(position !== null) {
|
|
134
134
|
return seekDoris(position, act)
|
|
135
135
|
.then(() => {
|
|
136
136
|
const seekDuration = (Date.now() - syncStartTime);
|
|
137
137
|
const {position} = calculateSyncDifferenceTime(syncData.masterFragmentSn, syncData.masterFragmentPos + seekDuration, syncData.ping);
|
|
138
138
|
const syncPrecision = Math.abs(position);
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
room._log(`Insufficient buffer: `, !isBufferSufficient);
|
|
141
141
|
room._log(`Seek duration is ${seekDuration}`);
|
|
142
142
|
room._log(`Sync precision should be ${syncPrecision}`);
|
|
143
|
-
|
|
143
|
+
|
|
144
144
|
const didSyncFail = syncPrecision > maxSyncThreshold
|
|
145
145
|
setNextWaitTime(didSyncFail);
|
|
146
146
|
return Promise.resolve();
|
|
@@ -159,7 +159,7 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
159
159
|
return Promise.reject();
|
|
160
160
|
})
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
const handleAddLocalParticipant = () => {
|
|
164
164
|
if(shouldPropagateMaster) {
|
|
165
165
|
propagateMasterFunc();
|
|
@@ -170,17 +170,17 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
170
170
|
}, {once:true});
|
|
171
171
|
}
|
|
172
172
|
};
|
|
173
|
-
|
|
173
|
+
|
|
174
174
|
const handleAddRemoteParticipant = () => {
|
|
175
175
|
if(shouldPropagateMaster) {
|
|
176
176
|
propagateMasterFunc();
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
const isConnected = () => {
|
|
181
181
|
return room._isDataChannelOpen && room.isConnected;
|
|
182
182
|
};
|
|
183
|
-
|
|
183
|
+
|
|
184
184
|
const parseDataEvents = (msg = {}) => {
|
|
185
185
|
if(msg.videoroom === 'sync_source_set' && msg.wt_channel_id != "") {
|
|
186
186
|
emitter.emit('changePlayerSource', msg.wt_channel_id);
|
|
@@ -189,12 +189,12 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
189
189
|
roomSyncSend(msg.sync_slave_id).catch(()=>{});
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
|
-
|
|
192
|
+
|
|
193
193
|
const getCurrentSegmentPosition = () => {
|
|
194
194
|
var position;
|
|
195
195
|
return (position = _libraryInstance.getCurrentDate()) === null || position === void 0 ? 0 : position.getTime()
|
|
196
196
|
};
|
|
197
|
-
|
|
197
|
+
|
|
198
198
|
const calculateSyncDifferenceTime = (fragmentSn, fragmentPos, ping = 0) => {
|
|
199
199
|
var _pos;
|
|
200
200
|
let currentTime = (_pos = _libraryInstance.getCurrentDate()) === null || _pos === void 0 ? null : _pos.getTime()
|
|
@@ -204,12 +204,12 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
204
204
|
return {position: null, isBufferSufficient: false}
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
|
-
|
|
207
|
+
|
|
208
208
|
const seekDoris = (time, act) => {
|
|
209
209
|
//https://mcorp.no/lib/mediasync.js
|
|
210
210
|
return new Promise((resolve, reject) => {
|
|
211
211
|
if(time !== 0) {
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
if(isSafari) {
|
|
214
214
|
isProgrammaticallySeeked = true; // we need to ignore stall events since those are false alarm
|
|
215
215
|
_videoElement.addEventListener('playing', () => {
|
|
@@ -267,7 +267,7 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
267
267
|
} else resolve()
|
|
268
268
|
});
|
|
269
269
|
};
|
|
270
|
-
|
|
270
|
+
|
|
271
271
|
const handlePlaying = () => {
|
|
272
272
|
if(!isProgrammaticallySeeked) {
|
|
273
273
|
room._log('Handle playing');
|
|
@@ -277,13 +277,13 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
277
277
|
isPreloading = _videoElement.paused;
|
|
278
278
|
isPlaying = !_videoElement.paused;
|
|
279
279
|
};
|
|
280
|
-
|
|
280
|
+
|
|
281
281
|
const handlePause = () => {
|
|
282
282
|
stopSyncLoop()
|
|
283
283
|
clientPaused().catch(() => {});
|
|
284
284
|
isPlaying = !_videoElement.paused;
|
|
285
285
|
};
|
|
286
|
-
|
|
286
|
+
|
|
287
287
|
const handleStalledWaiting = () => {
|
|
288
288
|
room._log('handleStalledWaiting');
|
|
289
289
|
if(!isProgrammaticallySeeked) {
|
|
@@ -302,10 +302,10 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
302
302
|
}
|
|
303
303
|
}, 1000);
|
|
304
304
|
};
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
|
|
306
|
+
|
|
307
307
|
const roomSyncSend = (slaveId) => {
|
|
308
|
-
|
|
308
|
+
|
|
309
309
|
if(!_libraryInstance || !_videoElement) {
|
|
310
310
|
room._log(
|
|
311
311
|
`I've been asked for position even if we don't have player attached.
|
|
@@ -313,12 +313,12 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
313
313
|
);
|
|
314
314
|
return Promise.resolve();
|
|
315
315
|
}
|
|
316
|
-
|
|
316
|
+
|
|
317
317
|
let fragmentPosition = parseInt(getCurrentSegmentPosition());
|
|
318
|
-
|
|
318
|
+
|
|
319
319
|
room._log(`Sending my position to ${slaveId}`);
|
|
320
320
|
room._log(`Current time: ${fragmentPosition}`);
|
|
321
|
-
|
|
321
|
+
|
|
322
322
|
return room.sendMessage(room.handleId, {
|
|
323
323
|
body : {
|
|
324
324
|
request: "sync_response",
|
|
@@ -329,23 +329,23 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
329
329
|
slave_id: room.webrtcVersion > 1000 ? String(slaveId) : Number(slaveId)
|
|
330
330
|
}});
|
|
331
331
|
};
|
|
332
|
-
|
|
332
|
+
|
|
333
333
|
const getSyncData = () => {
|
|
334
|
-
|
|
334
|
+
|
|
335
335
|
room._log('Sending roomSync request');
|
|
336
336
|
let roomId = room.roomId;
|
|
337
337
|
let fragmentPosition = parseInt(getCurrentSegmentPosition());
|
|
338
|
-
|
|
338
|
+
|
|
339
339
|
return new Promise((resolve, reject) => {
|
|
340
|
-
|
|
340
|
+
|
|
341
341
|
let now = new Date().getTime();
|
|
342
342
|
let ping = null;
|
|
343
|
-
|
|
343
|
+
|
|
344
344
|
let sid = setTimeout(() => {
|
|
345
345
|
room.off('data', fn, this);
|
|
346
346
|
reject('Timeout');
|
|
347
347
|
}, 3000);
|
|
348
|
-
|
|
348
|
+
|
|
349
349
|
let body = {
|
|
350
350
|
request: "sync",
|
|
351
351
|
room: roomId,
|
|
@@ -353,32 +353,32 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
353
353
|
fragment: String("0"),
|
|
354
354
|
fragment_pos: Number(fragmentPosition)
|
|
355
355
|
};
|
|
356
|
-
|
|
356
|
+
|
|
357
357
|
let fn = (msg) => {
|
|
358
|
-
|
|
358
|
+
|
|
359
359
|
if(msg.videoroom && ['sync', 'sync_response'].includes(msg.videoroom)) {
|
|
360
|
-
|
|
360
|
+
|
|
361
361
|
if(msg.sync_master_await) {
|
|
362
362
|
room._log('Waiting for master position');
|
|
363
363
|
if(!ping) {
|
|
364
364
|
ping = (new Date().getTime() - now);
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
|
-
|
|
367
|
+
|
|
368
368
|
else if(msg.sync_master_fragment || msg.sync_master_fragment_pos) {
|
|
369
369
|
room._log('Got master position data');
|
|
370
370
|
if(!ping) {
|
|
371
371
|
ping = (new Date().getTime() - now);
|
|
372
372
|
}
|
|
373
|
-
|
|
373
|
+
|
|
374
374
|
room._log(`I'm master: ${!!msg.sync_master_self}`);
|
|
375
375
|
room._log(`Ping: ${ping}`);
|
|
376
376
|
room._log(`Master fragment: ${msg.sync_master_fragment}`);
|
|
377
377
|
room._log(`Master fragment position: ${msg.sync_master_fragment_pos}`);
|
|
378
|
-
|
|
378
|
+
|
|
379
379
|
room.off('data', fn, this);
|
|
380
380
|
clearTimeout(sid);
|
|
381
|
-
|
|
381
|
+
|
|
382
382
|
resolve({
|
|
383
383
|
isMaster: !!msg.sync_master_self,
|
|
384
384
|
ping: ping,
|
|
@@ -386,7 +386,7 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
386
386
|
masterFragmentSn: parseInt(msg.sync_master_fragment),
|
|
387
387
|
});
|
|
388
388
|
}
|
|
389
|
-
|
|
389
|
+
|
|
390
390
|
else {
|
|
391
391
|
clearTimeout(sid);
|
|
392
392
|
reject('Master lost connection')
|
|
@@ -401,14 +401,14 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
401
401
|
});
|
|
402
402
|
});
|
|
403
403
|
};
|
|
404
|
-
|
|
404
|
+
|
|
405
405
|
const clientPaused = () => {
|
|
406
406
|
room._log('Sending client paused');
|
|
407
|
-
|
|
407
|
+
|
|
408
408
|
if(!isConnected()) {
|
|
409
409
|
return Promise.resolve();
|
|
410
410
|
}
|
|
411
|
-
|
|
411
|
+
|
|
412
412
|
return room.sendMessage(room.handleId, {
|
|
413
413
|
body:{
|
|
414
414
|
request: "sync_paused",
|
|
@@ -418,7 +418,7 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
418
418
|
fragment_pos:0
|
|
419
419
|
}});
|
|
420
420
|
};
|
|
421
|
-
|
|
421
|
+
|
|
422
422
|
const propagateMasterFunc = () => {
|
|
423
423
|
room._log('Propagating master');
|
|
424
424
|
if(!isConnected()) {
|
|
@@ -440,29 +440,29 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
440
440
|
__events: ['playerSyncing'],
|
|
441
441
|
|
|
442
442
|
initialize: ({dorisInstance, libraryInstance, propagateMaster = false} = {}) => {
|
|
443
|
-
|
|
443
|
+
|
|
444
444
|
_libraryInstance = dorisInstance || libraryInstance;
|
|
445
445
|
_videoElement = _libraryInstance.sourceHandler.getElement();
|
|
446
|
-
|
|
446
|
+
|
|
447
447
|
shouldPropagateMaster = propagateMaster;
|
|
448
448
|
isPlaying = _videoElement.paused === false;
|
|
449
|
-
|
|
449
|
+
|
|
450
450
|
room.on('disconnect', stopSyncLoop);
|
|
451
451
|
room.on('removeLocalParticipant', stopSyncLoop);
|
|
452
452
|
room.on('addLocalParticipant', handleAddLocalParticipant);
|
|
453
453
|
room.on('addRemoteParticipant', handleAddRemoteParticipant);
|
|
454
454
|
room.on('data', parseDataEvents);
|
|
455
|
-
|
|
455
|
+
|
|
456
456
|
if(shouldPropagateMaster) {
|
|
457
457
|
propagateMasterFunc().catch(() => {});
|
|
458
458
|
}
|
|
459
|
-
|
|
459
|
+
|
|
460
460
|
if(_videoElement && _videoElement.paused === false) {
|
|
461
461
|
_videoElement.addEventListener('progress', () => {
|
|
462
462
|
restartSyncLoop();
|
|
463
463
|
}, {once:true});
|
|
464
464
|
}
|
|
465
|
-
|
|
465
|
+
|
|
466
466
|
_videoElement.addEventListener('timeupdate', stalledGenerator);
|
|
467
467
|
_videoElement.addEventListener('playing', handlePlaying);
|
|
468
468
|
_videoElement.addEventListener('pause', handlePause);
|
|
@@ -471,20 +471,20 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
|
|
|
471
471
|
|
|
472
472
|
destroy: () => {
|
|
473
473
|
stopSyncLoop();
|
|
474
|
-
|
|
474
|
+
|
|
475
475
|
room.off('disconnect', stopSyncLoop);
|
|
476
476
|
room.off('removeLocalParticipant', stopSyncLoop);
|
|
477
477
|
room.off('addLocalParticipant', handleAddLocalParticipant);
|
|
478
478
|
room.off('addRemoteParticipant', handleAddRemoteParticipant);
|
|
479
479
|
room.off('data', parseDataEvents);
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
|
|
481
|
+
|
|
482
482
|
if(_videoElement) {
|
|
483
483
|
_videoElement.removeEventListener('timeupdate', stalledGenerator);
|
|
484
484
|
_videoElement.removeEventListener('playing', handlePlaying);
|
|
485
485
|
_videoElement.removeEventListener('pause', handlePause);
|
|
486
486
|
}
|
|
487
|
-
|
|
487
|
+
|
|
488
488
|
_libraryInstance = null;
|
|
489
489
|
}
|
|
490
490
|
};
|