/
streaming.MediaPlayer.js
1121 lines (861 loc) · 47.1 KB
/
streaming.MediaPlayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import SpecHelper from './helpers/SpecHelper';
import VideoElementMock from './mocks/VideoElementMock';
import StreamControllerMock from './mocks/StreamControllerMock';
import CapabilitiesMock from './mocks/CapabilitiesMock';
import PlaybackControllerMock from './mocks/PlaybackControllerMock';
import AbrControllerMock from './mocks/AbrControllerMock';
import MediaPlayer from './../../src/streaming/MediaPlayer';
import VideoModel from './../../src/streaming/models/VideoModel';
import MediaPlayerModelMock from './mocks//MediaPlayerModelMock';
import MediaControllerMock from './mocks/MediaControllerMock';
import ObjectUtils from './../../src/streaming/utils/ObjectUtils';
import Constants from '../../src/streaming/constants/Constants';
import Settings from '../../src/core/Settings';
const expect = require('chai').expect;
const ELEMENT_NOT_ATTACHED_ERROR = 'You must first call attachView() to set the video element before calling this method';
const PLAYBACK_NOT_INITIALIZED_ERROR = 'You must first call initialize() and set a valid source and view before calling this method';
const STREAMING_NOT_INITIALIZED_ERROR = 'You must first call initialize() and set a source before calling this method';
const SOURCE_NOT_ATTACHED_ERROR = 'You must first call attachSource() with a valid source before calling this method';
const MEDIA_PLAYER_NOT_INITIALIZED_ERROR = 'MediaPlayer not initialized!';
describe('MediaPlayer', function () {
before(function () {
global.dashjs = {};
});
after(function () {
delete global.dashjs;
});
const context = {};
const specHelper = new SpecHelper();
let dummyUrl = specHelper.getDummyUrl();
// init mock
const videoElementMock = new VideoElementMock();
const capaMock = new CapabilitiesMock();
const streamControllerMock = new StreamControllerMock();
const abrControllerMock = new AbrControllerMock();
const playbackControllerMock = new PlaybackControllerMock();
const mediaPlayerModel = new MediaPlayerModelMock();
const mediaControllerMock = new MediaControllerMock();
const objectUtils = ObjectUtils(context).getInstance();
const settings = Settings(context).getInstance();
let player;
beforeEach(function () {
player = MediaPlayer().create();
// to avoid unwanted log
const debug = player.getDebug();
expect(debug).to.exist; // jshint ignore:line
player.setConfig({
streamController: streamControllerMock,
capabilities: capaMock,
playbackController: playbackControllerMock,
mediaPlayerModel: mediaPlayerModel,
abrController: abrControllerMock,
mediaController: mediaControllerMock,
settings: settings
});
});
afterEach(function () {
player = null;
settings.reset();
});
describe('Init Functions', function () {
describe('When it is not initialized', function () {
it('Method isReady should return false', function () {
const isReady = player.isReady();
expect(isReady).to.be.false; // jshint ignore:line
});
});
describe('When it is initializing', function () {
it('Method initialize should not initialize if MSE is not supported', function () {
capaMock.setMediaSourceSupported(false);
player.initialize(videoElementMock, dummyUrl, false);
const isReady = player.isReady();
expect(isReady).to.be.false; // jshint ignore:line
capaMock.setMediaSourceSupported(true);
});
it('Method initialize should send an error if MSE is not supported', function (done) {
capaMock.setMediaSourceSupported(false);
const playerError = function (/*e*/) {
player.off('error', playerError);
const isReady = player.isReady();
expect(isReady).to.be.false; // jshint ignore:line
// reinit mock
capaMock.setMediaSourceSupported(true);
done();
};
player.on('error', playerError, this);
player.initialize(videoElementMock, dummyUrl, false);
});
});
describe('When it is initialized', function () {
beforeEach(function () {
player.initialize(videoElementMock, dummyUrl, false);
});
it('Method isReady should return true', function () {
const isReady = player.isReady();
expect(isReady).to.be.true; // jshint ignore:line
});
});
});
describe('Playback Functions', function () {
describe('When it is not initialized', function () {
it('Method play should throw an exception', function () {
expect(player.play).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method pause should throw an exception', function () {
expect(player.pause).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method isPaused should throw an exception', function () {
expect(player.isPaused).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method seek should throw an exception', function () {
expect(player.seek).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method isSeeking should throw an exception', function () {
expect(player.isSeeking).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method isDynamic should throw an exception', function () {
expect(player.isDynamic).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method setPlaybackRate should throw an exception', function () {
expect(player.setPlaybackRate).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
it('Method getPlaybackRate should throw an exception', function () {
expect(player.getPlaybackRate).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
it('Method setMute should throw an exception', function () {
expect(player.setMute.bind(player, true)).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
it('Method isMuted should throw an exception', function () {
expect(player.isMuted).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
it('Method setVolume should throw an exception', function () {
expect(player.setVolume.bind(player, 0.6)).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
it('Method getVolume should throw an exception', function () {
expect(player.getVolume).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
it('Method time should throw an exception', function () {
expect(player.time).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method duration should throw an exception', function () {
expect(player.duration).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method timeAsUTC should throw an exception', function () {
expect(player.timeAsUTC).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method durationAsUTC should throw an exception', function () {
expect(player.durationAsUTC).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method preload should throw an exception', function () {
expect(player.preload).to.throw(SOURCE_NOT_ATTACHED_ERROR);
});
});
describe('When it is initialized', function () {
beforeEach(function () {
playbackControllerMock.reset();
videoElementMock.reset();
player.initialize(videoElementMock, dummyUrl, false);
});
it('Method getDVRWindowSize should return 0', function () {
let dvrWindowSize = player.getDVRWindowSize();
expect(dvrWindowSize).equal(0); // jshint ignore:line
});
it('Method getDVRSeekOffset should return 0', function () {
let dvrSeekOffset = player.getDVRSeekOffset();
expect(dvrSeekOffset).equal(0); // jshint ignore:line
});
it('Method play should start playing', function () {
let isPlaying = playbackControllerMock.isPlaying();
expect(isPlaying).to.be.false; // jshint ignore:line
player.play();
isPlaying = playbackControllerMock.isPlaying();
expect(isPlaying).to.be.true; // jshint ignore:line
});
it('Method pause should pause playback', function () {
let paused = playbackControllerMock.isPaused();
expect(paused).to.be.false; // jshint ignore:line
player.pause();
paused = playbackControllerMock.isPaused();
expect(paused).to.be.true; // jshint ignore:line
});
it('Method isPaused should return pause state', function () {
player.play();
let paused = player.isPaused();
expect(paused).to.be.false; // jshint ignore:line
player.pause();
paused = player.isPaused();
expect(paused).to.be.true; // jshint ignore:line
player.play();
paused = player.isPaused();
expect(paused).to.be.false; // jshint ignore:line
});
it('Method seek should throw an exception', function () {
let isSeeking = playbackControllerMock.isSeeking();
expect(isSeeking).to.be.false; // jshint ignore:line
expect(player.seek).to.throw(Constants.BAD_ARGUMENT_ERROR);
isSeeking = playbackControllerMock.isSeeking();
expect(isSeeking).to.be.false; // jshint ignore:line
expect(player.seek.bind(player, NaN)).to.throw(Constants.BAD_ARGUMENT_ERROR);
isSeeking = playbackControllerMock.isSeeking();
expect(isSeeking).to.be.false; // jshint ignore:line
});
it('Method setMute should throw an exception', function () {
let isMuted = player.isMuted();
expect(isMuted).to.be.false; // jshint ignore:line
expect(player.setMute.bind(player, 1)).to.throw(Constants.BAD_ARGUMENT_ERROR);
isMuted = player.isMuted();
expect(isMuted).to.be.false; // jshint ignore:line
});
it('Method setVolume should throw an exception', function () {
expect(player.setVolume.bind(player, true)).to.throw(Constants.BAD_ARGUMENT_ERROR);
});
it('Method setAutoPlay should throw an exception', function () {
expect(player.setAutoPlay.bind(player, 'string')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(player.setAutoPlay.bind(player, 12)).to.throw(Constants.BAD_ARGUMENT_ERROR);
});
it('Method isDynamic should get dynamic value', function () {
let isDynamic = player.isDynamic();
expect(isDynamic).to.be.false; // jshint ignore:line
playbackControllerMock.setIsDynamic(true);
isDynamic = player.isDynamic();
expect(isDynamic).to.be.true; // jshint ignore:line
});
it('Method setPlaybackRate should change playback value of video element', function () {
let playbackRate = videoElementMock.playbackRate;
expect(playbackRate).to.equal(0);
const newPlaybackRate = 5;
player.setPlaybackRate(newPlaybackRate);
playbackRate = videoElementMock.playbackRate;
expect(playbackRate).to.equal(newPlaybackRate);
});
it('Method getPlaybackRate should return video element playback rate', function () {
const elementPlayBackRate = videoElementMock.playbackRate;
const playerPlayBackRate = player.getPlaybackRate();
expect(playerPlayBackRate).to.equal(elementPlayBackRate);
});
it('Method setMute should change mute value of video element', function () {
let isMuted = videoElementMock.muted;
expect(isMuted).to.be.false; // jshint ignore:line
player.setMute(true);
isMuted = videoElementMock.muted;
expect(isMuted).to.be.true; // jshint ignore:line
player.setMute(false);
isMuted = videoElementMock.muted;
expect(isMuted).to.be.false; // jshint ignore:line
});
it('Method isMuted should return mute state', function () {
let isMuted = player.isMuted();
expect(isMuted).to.be.false; // jshint ignore:line
player.setMute(true);
isMuted = player.isMuted();
expect(isMuted).to.be.true; // jshint ignore:line
player.setMute(false);
isMuted = player.isMuted();
expect(isMuted).to.be.false; // jshint ignore:line
});
it('Method setVolume should change volume value of video element', function () {
let volume = videoElementMock.volume;
expect(volume).to.equal(0);
player.setVolume(0.5);
volume = videoElementMock.volume;
expect(volume).to.equal(0.5);
player.setVolume(0.4);
volume = videoElementMock.volume;
expect(volume).to.equal(0.4);
});
it('Method getVolume should return mute state', function () {
let volume = player.getVolume();
expect(volume).to.equal(0);
player.setVolume(0.2);
volume = player.getVolume();
expect(volume).to.equal(0.2);
player.setVolume(0.6);
volume = player.getVolume();
expect(volume).to.equal(0.6);
});
it('Method time should return time of playback', function () {
let time = player.time();
expect(time).to.equal(0);
videoElementMock.currentTime = 15;
time = player.time();
expect(time).to.equal(15);
videoElementMock.currentTime = 4;
time = player.time();
expect(time).to.equal(4);
});
it('Method duration should return duration of playback', function () {
let duration = player.duration();
expect(duration).to.equal(0);
videoElementMock.duration = 15;
duration = player.duration();
expect(duration).to.equal(15);
videoElementMock.duration = 4;
duration = player.duration();
expect(duration).to.equal(4);
});
});
});
describe('AbrController Functions', function () {
afterEach(function () {
abrControllerMock.reset();
settings.reset();
});
it('should configure MaxAllowedBitrateFor', function () {
let maxAllowedBitrateFor = player.getSettings().streaming.abr.maxBitrate.audio;
expect(maxAllowedBitrateFor === -1).to.be.true; // jshint ignore:line
player.updateSettings({
'streaming': {
'abr': {
'maxBitrate': {
'audio': 5
}
}
}
});
maxAllowedBitrateFor = player.getSettings().streaming.abr.maxBitrate.audio;
expect(maxAllowedBitrateFor).to.equal(5);
});
it('should configure MinAllowedBitrateFor', function () {
let minAllowedBitrateFor = player.getSettings().streaming.abr.minBitrate.audio;
expect(minAllowedBitrateFor === -1).to.be.true; // jshint ignore:line
player.updateSettings({
'streaming': {
'abr': {
'minBitrate': {
'audio': 5
}
}
}
});
minAllowedBitrateFor = player.getSettings().streaming.abr.minBitrate.audio;
expect(minAllowedBitrateFor).to.equal(5);
});
it('should configure MaxAllowedRepresentationRatioFor', function () {
let maxAllowedRepresentationRatioFor = player.getSettings().streaming.abr.maxRepresentationRatio.audio;
expect(maxAllowedRepresentationRatioFor).to.equal(1);
player.updateSettings({
'streaming': {
'abr': {
'maxRepresentationRatio': {
'audio': 5
}
}
}
});
maxAllowedRepresentationRatioFor = player.getSettings().streaming.abr.maxRepresentationRatio.audio;
expect(maxAllowedRepresentationRatioFor).to.equal(5);
});
it('should update portal size', function () {
let elementHeight = abrControllerMock.getElementHeight();
let elementWidth = abrControllerMock.getElementWidth();
let windowResizeEventCalled = abrControllerMock.getWindowResizeEventCalled();
expect(elementHeight).to.be.undefined; // jshint ignore:line
expect(elementWidth).to.be.undefined; // jshint ignore:line
expect(windowResizeEventCalled).to.be.false; // jshint ignore:line
player.updatePortalSize();
elementHeight = abrControllerMock.getElementHeight();
elementWidth = abrControllerMock.getElementWidth();
windowResizeEventCalled = abrControllerMock.getWindowResizeEventCalled();
expect(elementHeight).to.equal(10);
expect(elementWidth).to.equal(10);
expect(windowResizeEventCalled).to.be.true; // jshint ignore:line
});
it('should configure bitrate according to playback area size', function () {
let limitBitrateByPortal = player.getSettings().streaming.abr.limitBitrateByPortal;
expect(limitBitrateByPortal).to.be.false; // jshint ignore:line
player.updateSettings({
'streaming': {
'abr': {
'limitBitrateByPortal': true
}
}
});
limitBitrateByPortal = player.getSettings().streaming.abr.limitBitrateByPortal;
expect(limitBitrateByPortal).to.be.true; // jshint ignore:line
});
it('should configure usePixelRatioInLimitBitrateByPortal', function () {
let UsePixelRatioInLimitBitrateByPortal = player.getSettings().streaming.abr.usePixelRatioInLimitBitrateByPortal;
expect(UsePixelRatioInLimitBitrateByPortal).to.be.false; // jshint ignore:line
player.updateSettings({
'streaming': {
'abr': {
'usePixelRatioInLimitBitrateByPortal': true
}
}
});
UsePixelRatioInLimitBitrateByPortal = player.getSettings().streaming.abr.usePixelRatioInLimitBitrateByPortal;
expect(UsePixelRatioInLimitBitrateByPortal).to.be.true; // jshint ignore:line
});
it('should configure initialRepresentationRatioFor', function () {
let initialRepresentationRatioFor = player.getSettings().streaming.abr.initialRepresentationRatio.video;
expect(initialRepresentationRatioFor).to.equal(-1); // jshint ignore:line
player.updateSettings({
'streaming': {
'abr': {
'initialRepresentationRatio': {
'video': 10
}
}
}
});
initialRepresentationRatioFor = player.getSettings().streaming.abr.initialRepresentationRatio.video;
expect(initialRepresentationRatioFor).to.equal(10);
});
it('should not set setAutoSwitchBitrateFor value if it\'s not a boolean type', function () {
let autoSwitchBitrateForVideo = player.getSettings().streaming.abr.autoSwitchBitrate.video;
expect(autoSwitchBitrateForVideo).to.be.true; // jshint ignore:line
player.updateSettings({
'streaming': {
'abr': {
'autoSwitchBitrate': {
'video': false
}
}
}
});
autoSwitchBitrateForVideo = player.getSettings().streaming.abr.autoSwitchBitrate.video;
expect(autoSwitchBitrateForVideo).to.be.false; // jshint ignore:line
});
it('Method getAverageThroughput should return 0 when throughputHistory is not set up', function () {
const averageThroughput = player.getAverageThroughput(Constants.VIDEO);
expect(averageThroughput).to.equal(0);
});
it('Method getAverageThroughput should value computed from ThroughputHistory', function () {
const AVERAGE_THROUGHPUT = 2000;
abrControllerMock.throughputHistory = {
getAverageThroughput: function () {
return AVERAGE_THROUGHPUT;
}
};
const averageThroughput = player.getAverageThroughput(Constants.VIDEO);
expect(averageThroughput).to.equal(AVERAGE_THROUGHPUT);
});
describe('When it is not initialized', function () {
it('Method getQualityFor should throw an exception', function () {
expect(player.getQualityFor).to.throw(STREAMING_NOT_INITIALIZED_ERROR);
});
it('Method setQualityFor should throw an exception', function () {
expect(player.setQualityFor).to.throw(STREAMING_NOT_INITIALIZED_ERROR);
});
});
describe('When it is initialized', function () {
beforeEach(function () {
player.initialize(videoElementMock, dummyUrl, false);
});
it('should configure quality for type', function () {
let qualityFor = abrControllerMock.getQualityFor('video', {
id: 'dummyId'
});
expect(qualityFor).to.equal(abrControllerMock.QUALITY_DEFAULT());
qualityFor = player.getQualityFor('video');
expect(qualityFor).to.equal(abrControllerMock.QUALITY_DEFAULT());
player.setQualityFor('video', 10);
qualityFor = abrControllerMock.getQualityFor('video', {
id: 'dummyId'
});
expect(qualityFor).to.equal(10);
qualityFor = player.getQualityFor('video');
expect(qualityFor).to.equal(10);
});
it('Method getTopBitrateInfoFor should return null when type is undefined', function () {
const topBitrateInfo = player.getTopBitrateInfoFor();
expect(topBitrateInfo).to.be.null; // jshint ignore:line
});
});
});
describe('Media Player Configuration Functions', function () {
afterEach(function () {
mediaPlayerModel.reset();
settings.reset();
});
it('should configure autoplay', function () {
let autoplay = player.getAutoPlay();
expect(autoplay).to.be.true; // jshint ignore:line
player.setAutoPlay(false);
autoplay = player.getAutoPlay();
expect(autoplay).to.be.false; // jshint ignore:line
});
it('should configure LiveDelayFragmentCount', function () {
let liveDelayFragmentCount = player.getSettings().streaming.liveDelayFragmentCount;
expect(liveDelayFragmentCount).to.be.NaN; // jshint ignore:line
player.updateSettings({'streaming': { 'liveDelayFragmentCount': 5 }});
liveDelayFragmentCount = player.getSettings().streaming.liveDelayFragmentCount;
expect(liveDelayFragmentCount).to.equal(5);
});
it('should configure useSuggestedPresentationDelay', function () {
let useSuggestedPresentationDelay = player.getSettings().streaming.useSuggestedPresentationDelay;
expect(useSuggestedPresentationDelay).to.be.true; // jshint ignore:line
player.updateSettings({'streaming': { 'useSuggestedPresentationDelay': false }});
useSuggestedPresentationDelay = player.getSettings().streaming.useSuggestedPresentationDelay;
expect(useSuggestedPresentationDelay).to.be.false; // jshint ignore:line
});
it('should configure scheduleWhilePaused', function () {
let scheduleWhilePaused = player.getSettings().streaming.scheduleWhilePaused;
expect(scheduleWhilePaused).to.be.true; // jshint ignore:line
player.updateSettings({'streaming': { 'scheduleWhilePaused': false }});
scheduleWhilePaused = player.getSettings().streaming.scheduleWhilePaused;
expect(scheduleWhilePaused).to.be.false; // jshint ignore:line
});
it('should configure fastSwitchEnabled', function () {
let fastSwitchEnabled = player.getSettings().streaming.fastSwitchEnabled;
expect(fastSwitchEnabled).to.be.false; // jshint ignore:line
player.updateSettings({'streaming': { 'fastSwitchEnabled': true }});
fastSwitchEnabled = player.getSettings().streaming.fastSwitchEnabled;
expect(fastSwitchEnabled).to.be.true; // jshint ignore:line
});
it('should configure useDefaultABRRules', function () {
let useDefaultABRRules = player.getSettings().streaming.abr.useDefaultABRRules;
expect(useDefaultABRRules).to.be.true; // jshint ignore:line
player.updateSettings({'streaming': { 'abr': { 'useDefaultABRRules': false }}});
useDefaultABRRules = player.getSettings().streaming.abr.useDefaultABRRules;
expect(useDefaultABRRules).to.be.false; // jshint ignore:line
});
it('should manage custom ABR rules', function () {
let customRules = mediaPlayerModel.getABRCustomRules();
expect(customRules.length).to.equal(0);
player.addABRCustomRule('custom', 'testRule', {});
customRules = mediaPlayerModel.getABRCustomRules();
expect(customRules.length).to.equal(1);
expect(customRules[0].rulename).to.equal('testRule');
player.addABRCustomRule('custom', 'testRule2', {});
player.addABRCustomRule('custom', 'testRule3', {});
customRules = mediaPlayerModel.getABRCustomRules();
expect(customRules.length).to.equal(3);
player.removeABRCustomRule('testRule');
customRules = mediaPlayerModel.getABRCustomRules();
expect(customRules.length).to.equal(2);
player.removeABRCustomRule();
customRules = mediaPlayerModel.getABRCustomRules();
expect(customRules.length).to.equal(0);
});
it('should manage UTC timing sources', function () {
let utcTimingSources = mediaPlayerModel.getUTCTimingSources();
expect(utcTimingSources.length).to.equal(0);
player.addUTCTimingSource('urn:mpeg:dash:utc:http-head:2014', 'http://time.akamai.com');
player.addUTCTimingSource('urn:mpeg:dash:utc:http-iso:2014', 'http://time.akamai.com');
utcTimingSources = mediaPlayerModel.getUTCTimingSources();
expect(utcTimingSources.length).to.equal(2);
player.removeUTCTimingSource('urn:mpeg:dash:utc:http-head:2014', 'http://time.akamai.com');
utcTimingSources = mediaPlayerModel.getUTCTimingSources();
expect(utcTimingSources.length).to.equal(1);
player.clearDefaultUTCTimingSources();
utcTimingSources = mediaPlayerModel.getUTCTimingSources();
expect(utcTimingSources.length).to.equal(0);
player.restoreDefaultUTCTimingSources();
utcTimingSources = mediaPlayerModel.getUTCTimingSources();
expect(utcTimingSources.length).to.equal(1);
});
it('should configure useManifestDateHeaderTimeSource', function () {
let useManifestDateHeaderTimeSource = player.getSettings().streaming.useManifestDateHeaderTimeSource;
expect(useManifestDateHeaderTimeSource).to.be.true; // jshint ignore:line
player.updateSettings({'streaming': { 'useManifestDateHeaderTimeSource': false }});
useManifestDateHeaderTimeSource = player.getSettings().streaming.useManifestDateHeaderTimeSource;
expect(useManifestDateHeaderTimeSource).to.be.false; // jshint ignore:line
});
it('should configure BufferToKeep', function () {
let BufferToKeep = player.getSettings().streaming.bufferToKeep;
expect(BufferToKeep).to.equal(20);
player.updateSettings({'streaming': { 'bufferToKeep': 50 }});
BufferToKeep = player.getSettings().streaming.bufferToKeep;
expect(BufferToKeep).to.equal(50);
});
it('should configure BufferPruningInterval', function () {
let BufferPruningInterval = player.getSettings().streaming.bufferPruningInterval;
expect(BufferPruningInterval).to.equal(10);
player.updateSettings({'streaming': { 'bufferPruningInterval': 50 }});
BufferPruningInterval = player.getSettings().streaming.bufferPruningInterval;
expect(BufferPruningInterval).to.equal(50);
});
it('should configure StableBufferTime', function () {
let StableBufferTime = player.getSettings().streaming.stableBufferTime;
expect(StableBufferTime).to.equal(12);
});
it('should configure BufferTimeAtTopQuality', function () {
let BufferTimeAtTopQuality = player.getSettings().streaming.bufferTimeAtTopQuality;
expect(BufferTimeAtTopQuality).to.equal(30);
player.updateSettings({'streaming': { 'bufferTimeAtTopQuality': 50 }});
BufferTimeAtTopQuality = player.getSettings().streaming.bufferTimeAtTopQuality;
expect(BufferTimeAtTopQuality).to.equal(50);
});
it('should configure BufferTimeAtTopQualityLongForm', function () {
let bufferTimeAtTopQualityLongForm = player.getSettings().streaming.bufferTimeAtTopQualityLongForm;
expect(bufferTimeAtTopQualityLongForm).to.equal(60);
player.updateSettings({'streaming': { 'bufferTimeAtTopQualityLongForm': 50 }});
bufferTimeAtTopQualityLongForm = player.getSettings().streaming.bufferTimeAtTopQualityLongForm;
expect(bufferTimeAtTopQualityLongForm).to.equal(50);
});
it('should configure LongFormContentDurationThreshold', function () {
let LongFormContentDurationThreshold = player.getSettings().streaming.longFormContentDurationThreshold;
expect(LongFormContentDurationThreshold).to.equal(600);
player.updateSettings({'streaming': { 'longFormContentDurationThreshold': 50 }});
LongFormContentDurationThreshold = player.getSettings().streaming.longFormContentDurationThreshold;
expect(LongFormContentDurationThreshold).to.equal(50);
});
it('should configure cacheLoadThresholds', function () {
let cacheLoadThresholdForVideo = player.getSettings().streaming.cacheLoadThresholds[Constants.VIDEO];
expect(cacheLoadThresholdForVideo).to.equal(50);
player.updateSettings({'streaming': { 'cacheLoadThresholds': { 'video': 10 } }});
cacheLoadThresholdForVideo = player.getSettings().streaming.cacheLoadThresholds[Constants.VIDEO];
expect(cacheLoadThresholdForVideo).to.equal(10);
let cacheLoadThresholdForAudio = player.getSettings().streaming.cacheLoadThresholds[Constants.AUDIO];
expect(cacheLoadThresholdForAudio).to.equal(5);
player.updateSettings({'streaming': { 'cacheLoadThresholds': { 'audio': 2 } }});
cacheLoadThresholdForAudio = player.getSettings().streaming.cacheLoadThresholds[Constants.AUDIO];
expect(cacheLoadThresholdForAudio).to.equal(2);
});
it('should configure jumpGap feature', function () {
let jumpGaps = player.getSettings().streaming.jumpGaps;
expect(jumpGaps).to.equal(true);
player.updateSettings({'streaming': { 'jumpGaps': false }});
jumpGaps = player.getSettings().streaming.jumpGaps;
expect(jumpGaps).to.equal(false);
let smallGapLimit = player.getSettings().streaming.smallGapLimit;
expect(smallGapLimit).to.equal(1.5);
player.updateSettings({'streaming': { 'smallGapLimit': 0.5 }});
smallGapLimit = player.getSettings().streaming.smallGapLimit;
expect(smallGapLimit).to.equal(0.5);
});
it('should configure manifestUpdateRetryInterval', function () {
let manifestUpdateRetryInterval = player.getSettings().streaming.manifestUpdateRetryInterval;
expect(manifestUpdateRetryInterval).to.equal(100);
player.updateSettings({'streaming': { 'manifestUpdateRetryInterval': 200 }});
manifestUpdateRetryInterval = player.getSettings().streaming.manifestUpdateRetryInterval;
expect(manifestUpdateRetryInterval).to.equal(200);
});
it('should configure BandwidthSafetyFactor', function () {
let bandwidthSafetyFactor = player.getSettings().streaming.abr.bandwidthSafetyFactor;
expect(bandwidthSafetyFactor).to.equal(0.9);
player.updateSettings({
'streaming': {
'abr': {
'bandwidthSafetyFactor': 0.1
}
}
});
bandwidthSafetyFactor = player.getSettings().streaming.abr.bandwidthSafetyFactor;
expect(bandwidthSafetyFactor).to.equal(0.1);
});
it('should configure AbandonLoadTimeout', function () {
let AbandonLoadTimeout = player.getSettings().streaming.abandonLoadTimeout;
expect(AbandonLoadTimeout).to.equal(10000);
player.updateSettings({
'streaming': {
'abandonLoadTimeout': 50
}
});
AbandonLoadTimeout = player.getSettings().streaming.abandonLoadTimeout;
expect(AbandonLoadTimeout).to.equal(50);
});
it('should configure XHRWithCredentials', function () {
let XHRWithCredentials = mediaPlayerModel.getXHRWithCredentialsForType('GET');
expect(XHRWithCredentials).to.equal(false);
XHRWithCredentials = player.getXHRWithCredentialsForType('GET');
expect(XHRWithCredentials).to.equal(false);
player.setXHRWithCredentialsForType('GET', true);
XHRWithCredentials = mediaPlayerModel.getXHRWithCredentialsForType('GET');
expect(XHRWithCredentials).to.equal(true);
XHRWithCredentials = player.getXHRWithCredentialsForType('GET');
expect(XHRWithCredentials).to.equal(true);
});
});
describe('Text Management Functions', function () {
describe('When it is not initialized', function () {
it('Method setTextTrack should throw an exception', function () {
expect(player.setTextTrack).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
});
it('Method setTextDefaultLanguage should throw an invalid Arguments exception when lang is undefined', function () {
expect(player.setTextDefaultLanguage).to.throw(Constants.BAD_ARGUMENT_ERROR);
});
it('Method setTextDefaultEnabled should throw an invalid Arguments exception when enable is undefined', function () {
expect(player.setTextDefaultEnabled).to.throw(Constants.BAD_ARGUMENT_ERROR);
});
it('Method getTextDefaultEnabled should return true', function () {
expect(player.getTextDefaultEnabled()).to.be.true; // jshint ignore:line
});
});
});
describe('Video Element Management Functions', function () {
describe('When it is not initialized', function () {
it('Method attachView should throw an exception when attaching a view', function () {
expect(player.attachView).to.throw(MEDIA_PLAYER_NOT_INITIALIZED_ERROR);
});
it('Method getVideoElement should throw an exception', function () {
expect(player.getVideoElement).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
it('Method attachTTMLRenderingDiv should throw an exception', function () {
expect(player.getVideoElement).to.throw(ELEMENT_NOT_ATTACHED_ERROR);
});
});
describe('When it is initialized', function () {
beforeEach(function () {
player.initialize(videoElementMock, dummyUrl, false);
});
it('Method getVideoElement should return video element', function () {
const element = player.getVideoElement();
const areEquals = objectUtils.areEqual(element, videoElementMock);
expect(areEquals).to.be.true; // jshint ignore:line
});
it('should be able to attach view', function () {
let element = player.getVideoElement();
const objectUtils = ObjectUtils(context).getInstance();
let areEquals = objectUtils.areEqual(element, videoElementMock);
expect(areEquals).to.be.true; // jshint ignore:line
const myNewView = new VideoElementMock();
player.attachView(myNewView);
element = player.getVideoElement();
areEquals = objectUtils.areEqual(element, myNewView);
expect(areEquals).to.be.true; // jshint ignore:line
});
it('should be able to attach TTML renderer div', function () {
let ttmlRenderer = player.getTTMLRenderingDiv();
expect(ttmlRenderer).to.be.undefined; // jshint ignore:line
const myTTMLRenderer = {
style: {}
};
player.attachTTMLRenderingDiv(myTTMLRenderer);
ttmlRenderer = player.getTTMLRenderingDiv();
const areEquals = objectUtils.areEqual(ttmlRenderer, myTTMLRenderer);
expect(areEquals).to.be.true; // jshint ignore:line
});
it('Method attachView should throw an exception when attaching a view which is not VIDEO or AUDIO DOM element', function () {
player.attachView(null);
const myNewView = {
view: 'view'
};
expect(player.attachView.bind(player, myNewView)).to.throw(VideoModel.VIDEO_MODEL_WRONG_ELEMENT_TYPE);
});
});
});
describe('Stream and Track Management Functions', function () {
describe('When it is not initialized', function () {
it('Method getBitrateInfoListFor should throw an exception', function () {
expect(player.getBitrateInfoListFor).to.throw('You must first call initialize() and set a source before calling this method');
});
it('Method getStreamsFromManifest should throw an exception', function () {
expect(player.getStreamsFromManifest).to.throw('You must first call initialize() and set a source before calling this method');
});
it('Method getTracksFor should throw an exception', function () {
expect(player.getTracksFor).to.throw('You must first call initialize() and set a source before calling this method');
});
it('Method getTracksForTypeFromManifest should throw an exception', function () {
expect(player.getTracksForTypeFromManifest).to.throw('You must first call initialize() and set a source before calling this method');
});
it('Method getCurrentTrackFor should throw an exception', function () {
expect(player.getCurrentTrackFor).to.throw('You must first call initialize() and set a source before calling this method');
});
it('Method setCurrentTrack should throw an exception', function () {
expect(player.setCurrentTrack).to.throw('You must first call initialize() and set a source before calling this method');
});
it('Method setInitialMediaSettingsFor should throw an exception', function () {
expect(player.setInitialMediaSettingsFor).to.throw(MEDIA_PLAYER_NOT_INITIALIZED_ERROR);
});
it('Method getInitialMediaSettingsFor should throw an exception', function () {
expect(player.getInitialMediaSettingsFor).to.throw(MEDIA_PLAYER_NOT_INITIALIZED_ERROR);
});
it('Method getTrackSwitchModeFor should throw an exception', function () {
expect(player.getTrackSwitchModeFor).to.throw(MEDIA_PLAYER_NOT_INITIALIZED_ERROR);
});
it('Method setTrackSwitchModeFor should throw an exception', function () {
expect(player.setTrackSwitchModeFor).to.throw(MEDIA_PLAYER_NOT_INITIALIZED_ERROR);
});
it('Method setSelectionModeForInitialTrack should throw an exception', function () {
expect(player.setSelectionModeForInitialTrack).to.throw(MEDIA_PLAYER_NOT_INITIALIZED_ERROR);
});
it('Method getSelectionModeForInitialTrack should throw an exception', function () {
expect(player.getSelectionModeForInitialTrack).to.throw(MEDIA_PLAYER_NOT_INITIALIZED_ERROR);
});