@@ -87,7 +87,7 @@ describe('VideoReplayer - no starting gap', () => {
87
87
onFinished : jest . fn ( ) ,
88
88
onLoaded : jest . fn ( ) ,
89
89
onBuffer : jest . fn ( ) ,
90
- durationMs : 40 ,
90
+ durationMs : 40000 ,
91
91
} ) ;
92
92
// @ts -expect-error private
93
93
expect ( inst . _currentIndex ) . toEqual ( 0 ) ;
@@ -113,7 +113,7 @@ describe('VideoReplayer - no starting gap', () => {
113
113
onFinished : jest . fn ( ) ,
114
114
onLoaded : jest . fn ( ) ,
115
115
onBuffer : jest . fn ( ) ,
116
- durationMs : 40 ,
116
+ durationMs : 40000 ,
117
117
} ) ;
118
118
const playPromise = inst . play ( 18100 ) ;
119
119
// @ts -expect-error private
@@ -142,7 +142,7 @@ describe('VideoReplayer - no starting gap', () => {
142
142
onFinished : jest . fn ( ) ,
143
143
onLoaded : jest . fn ( ) ,
144
144
onBuffer : jest . fn ( ) ,
145
- durationMs : 40 ,
145
+ durationMs : 40000 ,
146
146
} ) ;
147
147
const playPromise = inst . play ( 50000 ) ;
148
148
// 15000 -> 20000 is a gap, so player should start playing @ index 3, from
@@ -165,7 +165,7 @@ describe('VideoReplayer - no starting gap', () => {
165
165
onFinished : jest . fn ( ) ,
166
166
onLoaded : jest . fn ( ) ,
167
167
onBuffer : jest . fn ( ) ,
168
- durationMs : 40 ,
168
+ durationMs : 40000 ,
169
169
} ) ;
170
170
const playPromise = inst . play ( 0 ) ;
171
171
jest . advanceTimersByTime ( 2500 ) ;
@@ -185,7 +185,7 @@ describe('VideoReplayer - no starting gap', () => {
185
185
onFinished : jest . fn ( ) ,
186
186
onLoaded : jest . fn ( ) ,
187
187
onBuffer : jest . fn ( ) ,
188
- durationMs : 50 ,
188
+ durationMs : 50000 ,
189
189
} ) ;
190
190
// play at segment 7
191
191
const playPromise = inst . play ( 45_003 ) ;
@@ -220,7 +220,7 @@ describe('VideoReplayer - no starting gap', () => {
220
220
onFinished : jest . fn ( ) ,
221
221
onLoaded : jest . fn ( ) ,
222
222
onBuffer : jest . fn ( ) ,
223
- durationMs : 60 ,
223
+ durationMs : 55000 ,
224
224
} ) ;
225
225
// play at segment 7
226
226
const playPromise = inst . play ( 45_003 ) ;
@@ -294,7 +294,7 @@ describe('VideoReplayer - with starting gap', () => {
294
294
onFinished : jest . fn ( ) ,
295
295
onLoaded : jest . fn ( ) ,
296
296
onBuffer : jest . fn ( ) ,
297
- durationMs : 40 ,
297
+ durationMs : 40000 ,
298
298
} ) ;
299
299
// @ts -expect-error private
300
300
expect ( inst . _currentIndex ) . toEqual ( 0 ) ;
@@ -318,7 +318,7 @@ describe('VideoReplayer - with starting gap', () => {
318
318
onFinished : jest . fn ( ) ,
319
319
onLoaded : jest . fn ( ) ,
320
320
onBuffer : jest . fn ( ) ,
321
- durationMs : 40 ,
321
+ durationMs : 40000 ,
322
322
} ) ;
323
323
const playPromise = inst . play ( 18100 ) ;
324
324
// @ts -expect-error private
@@ -347,7 +347,7 @@ describe('VideoReplayer - with starting gap', () => {
347
347
onFinished : jest . fn ( ) ,
348
348
onLoaded : jest . fn ( ) ,
349
349
onBuffer : jest . fn ( ) ,
350
- durationMs : 40 ,
350
+ durationMs : 40000 ,
351
351
} ) ;
352
352
const playPromise = inst . play ( 50000 ) ;
353
353
// 15000 -> 20000 is a gap, so player should start playing @ index 3, from
@@ -361,3 +361,115 @@ describe('VideoReplayer - with starting gap', () => {
361
361
expect ( inst . getVideo ( inst . _currentIndex ) ?. currentTime ) . toEqual ( 5 ) ;
362
362
} ) ;
363
363
} ) ;
364
+
365
+ describe ( 'VideoReplayer - with ending gap' , ( ) => {
366
+ beforeEach ( ( ) => {
367
+ jest . clearAllTimers ( ) ;
368
+ } ) ;
369
+
370
+ const attachments = [
371
+ {
372
+ id : 0 ,
373
+ timestamp : 2500 ,
374
+ duration : 5000 ,
375
+ } ,
376
+ // no gap
377
+ {
378
+ id : 1 ,
379
+ timestamp : 5000 ,
380
+ duration : 5000 ,
381
+ } ,
382
+ {
383
+ id : 2 ,
384
+ timestamp : 10_001 ,
385
+ duration : 5000 ,
386
+ } ,
387
+ // 5 second gap
388
+ {
389
+ id : 3 ,
390
+ timestamp : 20_000 ,
391
+ duration : 5000 ,
392
+ } ,
393
+ // 5 second gap
394
+ {
395
+ id : 4 ,
396
+ timestamp : 30_000 ,
397
+ duration : 5000 ,
398
+ } ,
399
+ {
400
+ id : 5 ,
401
+ timestamp : 35_002 ,
402
+ duration : 5000 ,
403
+ } ,
404
+ ] ;
405
+
406
+ it ( 'keeps playing until the end if there is an ending gap' , async ( ) => {
407
+ const root = document . createElement ( 'div' ) ;
408
+ const inst = new VideoReplayer ( attachments , {
409
+ videoApiPrefix : '/foo/' ,
410
+ root,
411
+ start : 0 ,
412
+ onFinished : jest . fn ( ) ,
413
+ onLoaded : jest . fn ( ) ,
414
+ onBuffer : jest . fn ( ) ,
415
+ durationMs : 50000 ,
416
+ } ) ;
417
+ // actual length of the segments is 40s
418
+ // 10s gap at the end
419
+
420
+ // play at the last segment
421
+ const playPromise = inst . play ( 36000 ) ;
422
+ await playPromise ;
423
+ jest . advanceTimersByTime ( 4000 ) ;
424
+
425
+ // we're still within the last segment (5)
426
+ // @ts -expect-error private
427
+ expect ( inst . _currentIndex ) . toEqual ( 5 ) ;
428
+ expect ( inst . getCurrentTime ( ) ) . toEqual ( 40000 ) ;
429
+
430
+ // now we are in the gap
431
+ // timer should still be going since the duration is 50s
432
+ jest . advanceTimersByTime ( 5000 ) ;
433
+ // @ts -expect-error private
434
+ expect ( inst . _isPlaying ) . toEqual ( true ) ;
435
+
436
+ // a long time passes
437
+ // ensure the timer stops at the end duration (50s)
438
+ jest . advanceTimersByTime ( 60000 ) ;
439
+ expect ( inst . getCurrentTime ( ) ) . toEqual ( 50000 ) ;
440
+ // @ts -expect-error private
441
+ expect ( inst . _isPlaying ) . toEqual ( false ) ;
442
+ } ) ;
443
+
444
+ it ( 'ends at the proper time if seeking into a gap at the end' , async ( ) => {
445
+ const root = document . createElement ( 'div' ) ;
446
+ const inst = new VideoReplayer ( attachments , {
447
+ videoApiPrefix : '/foo/' ,
448
+ root,
449
+ start : 0 ,
450
+ onFinished : jest . fn ( ) ,
451
+ onLoaded : jest . fn ( ) ,
452
+ onBuffer : jest . fn ( ) ,
453
+ durationMs : 50000 ,
454
+ } ) ;
455
+ // actual length of the segments is 40s
456
+ // 10s gap at the end
457
+
458
+ // play at the gap
459
+ const playPromise = inst . play ( 40002 ) ;
460
+ await playPromise ;
461
+ jest . advanceTimersByTime ( 4000 ) ;
462
+
463
+ // we should be still playing in the gap
464
+ expect ( inst . getCurrentTime ( ) ) . toEqual ( 44002 ) ;
465
+ // @ts -expect-error private
466
+ expect ( inst . _isPlaying ) . toEqual ( true ) ;
467
+
468
+ // a long time passes
469
+ // ensure the timer stops at the end duration (50s)
470
+ jest . advanceTimersByTime ( 60000 ) ;
471
+ expect ( inst . getCurrentTime ( ) ) . toBeLessThan ( 50100 ) ;
472
+ // @ts -expect-error private
473
+ expect ( inst . _isPlaying ) . toEqual ( false ) ;
474
+ } ) ;
475
+ } ) ;
0 commit comments