@npo/player 1.18.3 → 1.18.4

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,117 +1,121 @@
1
1
  import { AdTagType, PlayerEvent } from 'bitmovin-player';
2
2
  import { NpoPlayerUIVariants } from '../../types/interfaces';
3
3
  export async function handlePreRolls(playerapi, streamObject, npoplayer) {
4
- if (streamObject.metadata.hasPreroll == 'false' || streamObject.assets.preroll == null) {
5
- return;
6
- }
7
- let prerollUrl = streamObject.assets.preroll;
8
- let adIndex = 0;
9
- let totalAds = 0;
10
- let currentClickListener = null;
11
- let adUiSet = false;
12
- async function handleSourceLoaded() {
13
- playerapi.off(PlayerEvent.SourceLoaded, handleSourceLoaded);
14
- const advertConfig = {
15
- tag: {
16
- url: String(prerollUrl),
17
- type: AdTagType.VAST
18
- },
19
- id: 'Ad',
20
- position: 'pre',
21
- };
22
- await playerapi.ads.schedule(advertConfig);
23
- }
24
- playerapi.on(PlayerEvent.SourceLoaded, handleSourceLoaded);
25
- async function handlePlay() {
26
- playerapi.off(PlayerEvent.Play, handlePlay);
27
- attemptSetAdUi();
28
- }
29
- playerapi.on(PlayerEvent.Play, handlePlay);
30
- function setAdUi() {
31
- let activeAdBreak = playerapi.ads.getActiveAdBreak();
32
- if (!activeAdBreak || !activeAdBreak.ads)
33
- return false;
34
- npoplayer.uiManager?.release();
35
- npoplayer.uiManager = null;
36
- npoplayer.createUIManager(playerapi, NpoPlayerUIVariants.AD);
37
- adUiSet = true;
38
- let adButton = npoplayer.uiComponents.adbutton;
39
- let currentAd = activeAdBreak.ads[0];
40
- adIndex = 1;
41
- totalAds = activeAdBreak.ads.length;
42
- adButton?.show();
43
- adClickHandler(currentAd, adButton);
44
- npoplayer.uiComponents.adlabel?.setText(`Advertentie 1 van ${activeAdBreak.ads.length}`);
45
- return true;
46
- }
47
- function attemptSetAdUi(attemptsLeft = 10) {
48
- if (attemptsLeft <= 0)
4
+ return new Promise((resolve) => {
5
+ if (streamObject.metadata.hasPreroll == 'false' || streamObject.assets.preroll == null) {
6
+ resolve();
49
7
  return;
50
- if (!adUiSet) {
51
- setAdUi();
52
- setTimeout(() => {
53
- attemptSetAdUi(attemptsLeft - 1);
54
- }, 200);
55
8
  }
56
- }
57
- function handleAdStarted() {
58
- playerapi.off(PlayerEvent.AdStarted, handleAdStarted);
59
- let activeAdBreak = playerapi.ads.getActiveAdBreak();
60
- if (!activeAdBreak || !activeAdBreak.ads) {
61
- console.error('No active ad break data found');
62
- return;
9
+ let prerollUrl = streamObject.assets.preroll;
10
+ let adIndex = 0;
11
+ let totalAds = 0;
12
+ let currentClickListener = null;
13
+ let adUiSet = false;
14
+ async function handleSourceLoaded() {
15
+ playerapi.off(PlayerEvent.SourceLoaded, handleSourceLoaded);
16
+ const advertConfig = {
17
+ tag: {
18
+ url: String(prerollUrl),
19
+ type: AdTagType.VAST
20
+ },
21
+ id: 'Ad',
22
+ position: 'pre',
23
+ };
24
+ await playerapi.ads.schedule(advertConfig);
63
25
  }
64
- if (!adUiSet)
26
+ playerapi.on(PlayerEvent.SourceLoaded, handleSourceLoaded);
27
+ async function handlePlay() {
28
+ playerapi.off(PlayerEvent.Play, handlePlay);
65
29
  attemptSetAdUi();
66
- npoplayer.adBreakActive = true;
67
- }
68
- playerapi.on(PlayerEvent.AdStarted, handleAdStarted);
69
- function adClickHandler(ad, button) {
70
- let clickThroughCallback;
71
- if (currentClickListener)
72
- button?.onClick.unsubscribe(currentClickListener);
73
- clickThroughCallback = ad.clickThroughUrlOpened;
74
- currentClickListener = () => {
75
- try {
76
- window.open(ad.clickThroughUrl, '_blank');
77
- playerapi.pause();
78
- if (clickThroughCallback)
79
- clickThroughCallback();
30
+ }
31
+ playerapi.on(PlayerEvent.Play, handlePlay);
32
+ function setAdUi() {
33
+ let activeAdBreak = playerapi.ads.getActiveAdBreak();
34
+ if (!activeAdBreak || !activeAdBreak.ads)
35
+ return false;
36
+ npoplayer.uiManager?.release();
37
+ npoplayer.uiManager = null;
38
+ npoplayer.createUIManager(playerapi, NpoPlayerUIVariants.AD);
39
+ adUiSet = true;
40
+ let adButton = npoplayer.uiComponents.adbutton;
41
+ let currentAd = activeAdBreak.ads[0];
42
+ adIndex = 1;
43
+ totalAds = activeAdBreak.ads.length;
44
+ adButton?.show();
45
+ adClickHandler(currentAd, adButton);
46
+ npoplayer.uiComponents.adlabel?.setText(`Advertentie 1 van ${activeAdBreak.ads.length}`);
47
+ return true;
48
+ }
49
+ function attemptSetAdUi(attemptsLeft = 10) {
50
+ if (attemptsLeft <= 0)
51
+ return;
52
+ if (!adUiSet) {
53
+ setAdUi();
54
+ setTimeout(() => {
55
+ attemptSetAdUi(attemptsLeft - 1);
56
+ }, 200);
80
57
  }
81
- catch (error) {
82
- console.log(error);
58
+ }
59
+ function handleAdStarted() {
60
+ playerapi.off(PlayerEvent.AdStarted, handleAdStarted);
61
+ let activeAdBreak = playerapi.ads.getActiveAdBreak();
62
+ if (!activeAdBreak || !activeAdBreak.ads) {
63
+ console.error('No active ad break data found');
64
+ return;
83
65
  }
84
- };
85
- button.onClick.subscribe(currentClickListener);
86
- }
87
- function handleAdFinished() {
88
- playerapi.off(PlayerEvent.AdFinished, handleAdFinished);
89
- let activeAdBreak = playerapi.ads.getActiveAdBreak();
90
- if (!activeAdBreak || !activeAdBreak.ads) {
91
- console.error('No active ad break data found');
92
- return;
66
+ if (!adUiSet)
67
+ attemptSetAdUi();
68
+ npoplayer.adBreakActive = true;
93
69
  }
94
- if (adIndex >= totalAds) {
95
- handleAdBreakFinished();
96
- return;
70
+ playerapi.on(PlayerEvent.AdStarted, handleAdStarted);
71
+ function adClickHandler(ad, button) {
72
+ let clickThroughCallback;
73
+ if (currentClickListener)
74
+ button?.onClick.unsubscribe(currentClickListener);
75
+ clickThroughCallback = ad.clickThroughUrlOpened;
76
+ currentClickListener = () => {
77
+ try {
78
+ window.open(ad.clickThroughUrl, '_blank');
79
+ playerapi.pause();
80
+ if (clickThroughCallback)
81
+ clickThroughCallback();
82
+ }
83
+ catch (error) {
84
+ console.log(error);
85
+ }
86
+ };
87
+ button.onClick.subscribe(currentClickListener);
88
+ }
89
+ function handleAdFinished() {
90
+ playerapi.off(PlayerEvent.AdFinished, handleAdFinished);
91
+ let activeAdBreak = playerapi.ads.getActiveAdBreak();
92
+ if (!activeAdBreak || !activeAdBreak.ads) {
93
+ console.error('No active ad break data found');
94
+ return;
95
+ }
96
+ if (adIndex >= totalAds) {
97
+ handleAdBreakFinished();
98
+ return;
99
+ }
100
+ let adButton = npoplayer.uiComponents.adbutton;
101
+ let nextAd = activeAdBreak.ads[adIndex];
102
+ adIndex += 1;
103
+ adButton?.show();
104
+ adClickHandler(nextAd, adButton);
105
+ npoplayer.uiComponents.adlabel?.setText(`Advertentie ${adIndex} van ${activeAdBreak.ads.length}`);
106
+ }
107
+ playerapi.on(PlayerEvent.AdFinished, handleAdFinished);
108
+ function handleAdBreakFinished() {
109
+ playerapi.off(PlayerEvent.AdBreakFinished, handleAdBreakFinished);
110
+ npoplayer.adBreakActive = false;
111
+ npoplayer.uiComponents.adbutton?.hide();
112
+ npoplayer.uiComponents.adlabel?.hide();
113
+ npoplayer.uiManager?.release();
114
+ npoplayer.uiManager = null;
115
+ npoplayer.createUIManager(playerapi, NpoPlayerUIVariants.DEFAULT);
116
+ adUiSet = false;
117
+ resolve();
97
118
  }
98
- let adButton = npoplayer.uiComponents.adbutton;
99
- let nextAd = activeAdBreak.ads[adIndex];
100
- adIndex += 1;
101
- adButton?.show();
102
- adClickHandler(nextAd, adButton);
103
- npoplayer.uiComponents.adlabel?.setText(`Advertentie ${adIndex} van ${activeAdBreak.ads.length}`);
104
- }
105
- playerapi.on(PlayerEvent.AdFinished, handleAdFinished);
106
- function handleAdBreakFinished() {
107
- playerapi.off(PlayerEvent.AdBreakFinished, handleAdBreakFinished);
108
- npoplayer.adBreakActive = false;
109
- npoplayer.uiComponents.adbutton?.hide();
110
- npoplayer.uiComponents.adlabel?.hide();
111
- npoplayer.uiManager?.release();
112
- npoplayer.uiManager = null;
113
- npoplayer.createUIManager(playerapi, NpoPlayerUIVariants.DEFAULT);
114
- adUiSet = false;
115
- }
116
- playerapi.on(PlayerEvent.AdBreakFinished, handleAdBreakFinished);
119
+ playerapi.on(PlayerEvent.AdBreakFinished, handleAdBreakFinished);
120
+ });
117
121
  }
package/lib/npoplayer.js CHANGED
@@ -109,7 +109,7 @@ export default class NpoPlayer {
109
109
  logEvent(this, 'load');
110
110
  startPlayerTracker(this, utility.validateStreamLength(_streamObject.metadata.duration, false), this.version, _streamObject.metadata.prid);
111
111
  if (this.variant !== NpoPlayerUIVariants.AUDIO) {
112
- handlePreRolls(this.player, _streamObject, this);
112
+ await handlePreRolls(this.player, _streamObject, this);
113
113
  }
114
114
  }
115
115
  else {
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npo/player",
3
- "version": "1.18.3",
3
+ "version": "1.18.4",
4
4
  "description": "NPO Player",
5
5
  "author": "Publieke Omroep <player@npo.nl>",
6
6
  "contributors": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npo/player",
3
- "version": "1.18.3",
3
+ "version": "1.18.4",
4
4
  "description": "NPO Player",
5
5
  "author": "Publieke Omroep <player@npo.nl>",
6
6
  "contributors": [