@flashphoner/websdk 2.0.244 → 2.0.246

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.
@@ -1,4 +1,4 @@
1
- Web SDK - 2.0.244
1
+ Web SDK - 2.0.246
2
2
 
3
3
  [Download builds](https://docs.flashphoner.com/display/WEBSDK2EN/Web+SDK+release+notes)
4
4
 
@@ -1,11 +1,18 @@
1
1
  const Browser = Flashphoner.Browser;
2
2
  const STATS_INTERVAL = 1000;
3
+ const QUALITY_COLORS = {
4
+ NONE: "",
5
+ AVAILABLE: "black",
6
+ SELECTED: "blue"
7
+ };
8
+ const QUALITY_AUTO = "Auto";
3
9
  let remoteVideo = null;
4
10
  let hlsPlayer = null;
5
11
  let playSrc = getUrlParam("src");
6
12
  let autoplay = eval(getUrlParam("autoplay")) || false;
7
13
  let llHlsEnabled = eval(getUrlParam("llhls")) || false;
8
14
  let playbackStats = null;
15
+ let qualityLevels = [];
9
16
 
10
17
  const loadPlayerPage = function() {
11
18
  loadPage("../hls-player/player-page.html", "playerPage", initPage );
@@ -72,10 +79,12 @@ const playBtnClick = function() {
72
79
  hlsPlayer.on(Hls.Events.MANIFEST_PARSED, function() {
73
80
  console.log("Play with HLS.js");
74
81
  remoteVideo.play();
82
+ initQualityLevels(hlsPlayer);
75
83
  });
76
84
  remoteVideo.onplaying = () => {
77
85
  console.log("playing event fired");
78
86
  displayPermalink(videoSrc);
87
+ displayQualitySwitch();
79
88
  }
80
89
  hlsPlayer.loadSource(videoSrc);
81
90
  hlsPlayer.attachMedia(remoteVideo);
@@ -91,7 +100,7 @@ const getHlsConfig = function(llHlsEnabled) {
91
100
  backBufferLength: 90,
92
101
  manifestLoadingTimeOut: 15000
93
102
  };
94
- console.log("Low Latency HLS: "+llHlsEnabled)
103
+ console.log("Low Latency HLS: " + llHlsEnabled)
95
104
  if(llHlsEnabled) {
96
105
  // Here we configure HLS.JS for lower latency
97
106
  config = {
@@ -146,6 +155,8 @@ function onStopped() {
146
155
  setText("applyBtn", "Play");
147
156
  setHandler("applyBtn", "click", playBtnClick, stopBtnClick);
148
157
  stopPlaybackStats();
158
+ hideItem("quality");
159
+ disposeQualityLevels();
149
160
  }
150
161
  }
151
162
 
@@ -248,6 +259,12 @@ const displayPermalink = function(src) {
248
259
  }
249
260
  }
250
261
 
262
+ const displayQualitySwitch = function() {
263
+ if (!autoplay && qualityLevels.length) {
264
+ showItem("quality")
265
+ }
266
+ }
267
+
251
268
  const hideAllToAutoplay = function() {
252
269
  hideItem("header");
253
270
  hideItem("notifyFlash");
@@ -342,4 +359,65 @@ const PlaybackStats = function(interval) {
342
359
  }
343
360
  };
344
361
  return playbackStats;
362
+ }
363
+
364
+ const initQualityLevels = function(player) {
365
+ if (player) {
366
+ let qualityDiv = document.getElementById("qualityBtns");
367
+ let qualityLevel;
368
+ for (let i = 0; i < player.levels.length; i++) {
369
+ qualityLevel = QualityLevel(player, player.levels[i].height, i, qualityDiv);
370
+ qualityLevels.push(qualityLevel);
371
+ }
372
+ if (qualityLevels.length) {
373
+ qualityLevel = QualityLevel(player, QUALITY_AUTO, -1, qualityDiv);
374
+ qualityLevels.push(qualityLevel);
375
+ }
376
+ }
377
+ }
378
+
379
+ const disposeQualityLevels = function() {
380
+ qualityLevels.forEach(level => {
381
+ if (level.button) {
382
+ level.button.remove();
383
+ }
384
+ });
385
+ qualityLevels = [];
386
+ }
387
+
388
+ const qualityBtnClick = function(button, player, index) {
389
+ if (player) {
390
+ player.currentLevel = index;
391
+ }
392
+ button.style.color = QUALITY_COLORS.SELECTED;
393
+ qualityLevels.forEach(item => {
394
+ if (item.button.id !== button.id) {
395
+ item.button.style.color = QUALITY_COLORS.AVAILABLE
396
+ }
397
+ });
398
+ }
399
+
400
+ const QualityLevel = function(object, levelId, index, btnParent) {
401
+ const btnId = "qualityBtn";
402
+ let button = document.createElement("button");
403
+ if (levelId === QUALITY_AUTO && index === -1) {
404
+ button.id = btnId + QUALITY_AUTO;
405
+ button.innerHTML = QUALITY_AUTO
406
+ } else {
407
+ button.id = btnId + index;
408
+ button.innerHTML = levelId;
409
+ }
410
+ button.type = "button";
411
+ button.className = "btn btn-default";
412
+ button.style.color = QUALITY_COLORS.AVAILABLE;
413
+ button.onclick = (event) => {
414
+ qualityBtnClick(button, object, index);
415
+ };
416
+ btnParent.appendChild(button);
417
+ const qualityLevel = {
418
+ level: levelId,
419
+ index: index,
420
+ button: button
421
+ };
422
+ return qualityLevel;
345
423
  }
@@ -7,12 +7,19 @@ const LIVE_THRESHOLD = 5;
7
7
  const LIVE_TOLERANCE = 5;
8
8
  const LIVE_UI_INTERVAL = 1000;
9
9
  const STATS_INTERVAL = 1000;
10
+ const QUALITY_COLORS = {
11
+ NONE: "",
12
+ AVAILABLE: "black",
13
+ SELECTED: "blue"
14
+ };
15
+ const QUALITY_AUTO = "Auto";
10
16
  let player = null;
11
17
  let liveUITimer = null;
12
18
  let videojsVersion = getUrlParam("version");
13
19
  let playSrc = getUrlParam("src");
14
20
  let autoplay = eval(getUrlParam("autoplay")) || false;
15
21
  let playbackStats = null;
22
+ let qualityLevels = [];
16
23
 
17
24
  const loadPlayerPage = function() {
18
25
  if (videojsVersion) {
@@ -44,27 +51,50 @@ const loadPlayerPage = function() {
44
51
  }
45
52
  }
46
53
 
47
- const onVideojsBtnClick = function () {
54
+ const onVideojsBtnClick = function() {
48
55
  loadVideoJS(getValue("videojsInput"));
49
56
  }
50
57
 
51
- const loadVideoJS = function (version) {
58
+ const loadVideoJS = function(version) {
52
59
  if (version) {
53
60
  videojsVersion = version;
54
61
  let playerPage = document.getElementById("playerPage");
55
62
  loadFile(version + "/video.js", "text/javascript").then( data => {
56
63
  console.log("HLS library loaded successfully", data);
57
- loadFile(version + "/video-js.css", "stylesheet").then ( data => {
58
- console.log("HLS library stylesheet loaded successfully", data);
64
+ loadStyles(version, playerPage);
65
+ }).catch( err => {
66
+ setText("videojsError", "Can't load VideoJS library");
67
+ console.error(err);
68
+ });
69
+ }
70
+ }
71
+
72
+ const loadStyles = function(version, playerPage) {
73
+ if (version) {
74
+ loadFile(version + "/video-js.css", "stylesheet").then ( data => {
75
+ console.log("HLS library stylesheet loaded successfully", data);
76
+ if (version === VIDEOJS_VERSION_TYPE.VIDEOJS7) {
77
+ loadQualityPlugin(version, playerPage);
78
+ } else {
59
79
  hideItem("videojsInputForm");
60
80
  loadPage("player-page.html", "playerPage", initPage);
61
- }).catch( err => {
62
- playerPage.innerHTML = "Can't load VideoJS library stylesheet";
63
- playerPage.setAttribute("class", "text-danger");
64
- console.error(err);
65
- })
81
+ }
66
82
  }).catch( err => {
67
- setText("videojsError", "Can't load VideoJS library");
83
+ playerPage.innerHTML = "Can't load VideoJS library stylesheet";
84
+ playerPage.setAttribute("class", "text-danger");
85
+ console.error(err);
86
+ });
87
+ }
88
+ }
89
+
90
+ const loadQualityPlugin = function(version, playerPage) {
91
+ if (version) {
92
+ loadFile(version + "/videojs-contrib-quality-levels.js", "text/javascript").then( data => {
93
+ console.log("HLS quality levels plugin loaded successfully", data);
94
+ hideItem("videojsInputForm");
95
+ loadPage("player-page.html", "playerPage", initPage);
96
+ }).catch( err => {
97
+ setText("videojsError", "Can't load VideoJS quality levels plugin");
68
98
  console.error(err);
69
99
  });
70
100
  }
@@ -183,6 +213,8 @@ const playBtnClick = function() {
183
213
  stopLiveUITimer();
184
214
  }
185
215
  }
216
+ initQualityLevels(player);
217
+ displayQualitySwitch();
186
218
  });
187
219
  player.src({
188
220
  src: videoSrc,
@@ -253,6 +285,7 @@ const onStarted = function() {
253
285
  setText("applyBtn", "Stop");
254
286
  setHandler("applyBtn", "click", stopBtnClick, playBtnClick);
255
287
  startPlaybackStats();
288
+ hideItem("quality");
256
289
  }
257
290
  }
258
291
 
@@ -265,6 +298,8 @@ const onStopped = function() {
265
298
  setText("applyBtn", "Play");
266
299
  setHandler("applyBtn", "click", playBtnClick, stopBtnClick);
267
300
  stopPlaybackStats();
301
+ hideItem("quality");
302
+ disposeQualityLevels();
268
303
  }
269
304
  if(!document.getElementById('remoteVideo')) {
270
305
  createRemoteVideo(document.getElementById('videoContainer'));
@@ -340,7 +375,12 @@ const initVideoJsPlayer = function(video, muted) {
340
375
  liveTolerance: LIVE_TOLERANCE
341
376
  },
342
377
  fill: true,
343
- muted: muted
378
+ muted: muted,
379
+ html5: {
380
+ vhs: {
381
+ limitRenditionByPlayerDimensions: false
382
+ }
383
+ }
344
384
  });
345
385
  console.log("Using VideoJs " + videojs.VERSION);
346
386
  if (Browser.isSafariWebRTC() && Browser.isiOS()) {
@@ -427,6 +467,12 @@ const displayPermalink = function(src) {
427
467
  }
428
468
  }
429
469
 
470
+ const displayQualitySwitch = function() {
471
+ if (!autoplay && qualityLevels.length) {
472
+ showItem("quality")
473
+ }
474
+ }
475
+
430
476
  const hideAllToAutoplay = function() {
431
477
  hideItem("header");
432
478
  hideItem("notifyFlash");
@@ -520,4 +566,81 @@ const PlaybackStats = function(interval) {
520
566
  }
521
567
  };
522
568
  return playbackStats;
523
- }
569
+ }
570
+
571
+ const initQualityLevels = function(player) {
572
+ if (player && !qualityLevels.length) {
573
+ let playerQualityLevels = player.qualityLevels();
574
+ if (playerQualityLevels) {
575
+ let qualityDiv = document.getElementById("qualityBtns");
576
+ let qualityLevel;
577
+ for (let i = 0; i < playerQualityLevels.length; i++) {
578
+ qualityLevel = QualityLevel(playerQualityLevels, playerQualityLevels[i].height, i, qualityDiv);
579
+ qualityLevels.push(qualityLevel);
580
+ }
581
+ if (qualityLevels.length) {
582
+ qualityLevel = QualityLevel(playerQualityLevels, QUALITY_AUTO, -1, qualityDiv);
583
+ qualityLevels.push(qualityLevel);
584
+ }
585
+ }
586
+ }
587
+ }
588
+
589
+ const disposeQualityLevels = function() {
590
+ qualityLevels.forEach(level => {
591
+ if (level.button) {
592
+ level.button.remove();
593
+ }
594
+ });
595
+ qualityLevels = [];
596
+ }
597
+
598
+ const qualityBtnClick = function(button, playerQualityLevels, index) {
599
+ if (playerQualityLevels && playerQualityLevels.length) {
600
+ let currentIndex = playerQualityLevels.selectedIndex_;
601
+ for (let i = 0; i < playerQualityLevels.length; i++) {
602
+ let qualityLevel = playerQualityLevels[i];
603
+ if (index === -1 || i === index) {
604
+ qualityLevel.enabled = true;
605
+ } else if (i === index) {
606
+ qualityLevel.enabled = true;
607
+ currentIndex = index;
608
+ } else {
609
+ qualityLevel.enabled = false;
610
+ }
611
+ }
612
+ playerQualityLevels.selectedIndex_ = currentIndex;
613
+ playerQualityLevels.trigger({ type: 'change', selectedIndex: currentIndex });
614
+ }
615
+ button.style.color = QUALITY_COLORS.SELECTED;
616
+ qualityLevels.forEach(item => {
617
+ if (item.button.id !== button.id) {
618
+ item.button.style.color = QUALITY_COLORS.AVAILABLE
619
+ }
620
+ });
621
+ }
622
+
623
+ const QualityLevel = function(object, levelId, index, btnParent) {
624
+ const btnId = "qualityBtn";
625
+ let button = document.createElement("button");
626
+ if (levelId === QUALITY_AUTO && index === -1) {
627
+ button.id = btnId + QUALITY_AUTO;
628
+ button.innerHTML = QUALITY_AUTO;
629
+ } else {
630
+ button.id = btnId + index;
631
+ button.innerHTML = levelId;
632
+ }
633
+ button.type = "button";
634
+ button.className = "btn btn-default";
635
+ button.style.color = QUALITY_COLORS.AVAILABLE;
636
+ button.onclick = (event) => {
637
+ qualityBtnClick(button, object, index);
638
+ };
639
+ btnParent.appendChild(button);
640
+ const qualityLevel = {
641
+ level: levelId,
642
+ index: index,
643
+ button: button
644
+ };
645
+ return qualityLevel;
646
+ }
@@ -55,22 +55,40 @@
55
55
  </div>
56
56
  </div>
57
57
 
58
- <div class="row" style="margin-top:10px">
58
+ <div class="row" style="margin-top: 10px">
59
+ <div class="col-sm-4 text-left" id="llHlsMode" style="display: none;">
60
+ <input id="llHlsEnabled" class="form-check-input" type="checkbox" value="">
61
+ <label class="form-check-label" for="llHlsEnabled">Low latency HLS</label>
62
+ </div>
63
+ </div>
64
+ <div class="row" style="margin-top: 5px">
59
65
  <div class="col-sm-12 text-center">
60
66
  <a id="permalink" href="#">Permalink</a>
61
67
  </div>
62
68
  </div>
69
+ <div class="row" style="margin-top: 10px">
70
+ <div class="col-sm-12 text-center">
71
+ <button id="applyBtn" type="button" class="btn btn-default">Play</button>
72
+ </div>
73
+ </div>
63
74
 
64
- <div class="row" style="margin-top: 20px">
65
- <div class="col-sm-4 text-left">
66
- <div id="llHlsMode" style="display: none;">
67
- <input id="llHlsEnabled" class="form-check-input" type="checkbox" value="">
68
- <label class="form-check-label" for="llHlsEnabled">Low latency HLS</label>
75
+ <div class="row" style="margin-top: 10px">
76
+ <div class="col-sm-12" id="quality" style="display: none;">
77
+ <div class="col-sm-4 text-right">
78
+ <label class="form-check-label" for="qualityBtns">Quality</label>
79
+ </div>
80
+ <div class="col-sm-8 text-center">
81
+ <div class="input-group-btn" id="qualityBtns">
82
+ </div>
69
83
  </div>
70
84
  </div>
71
- <div class="col-sm-5">
72
- <div id="backward" style="display: none;">
73
- <label class="form-check-label text-right" for="backBtnMax">&lt;&lt; seconds</label>
85
+ </div>
86
+ <div class="row" style="margin-top: 10px">
87
+ <div class="col-sm-12" id="backward" style="display: none;">
88
+ <div class="col-sm-4 text-right">
89
+ <label class="form-check-label" for="backBtnMax">Rewind back</label>
90
+ </div>
91
+ <div class="col-sm-8 text-center">
74
92
  <div class="input-group-btn">
75
93
  <button id="backBtnMax" type="button" class="btn btn-default">Max</button>
76
94
  <button id="backBtn30" type="button" class="btn btn-default">30</button>
@@ -79,9 +97,6 @@
79
97
  </div>
80
98
  </div>
81
99
  </div>
82
- <div class="col-sm-3 text-right">
83
- <button id="applyBtn" type="button" class="btn btn-default">Play</button>
84
- </div>
85
100
  </div>
86
101
  </fieldset>
87
102
  </div>