@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.
- package/lib/js/ads/ster.js +109 -105
- package/lib/npoplayer.js +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
package/lib/js/ads/ster.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
26
|
+
playerapi.on(PlayerEvent.SourceLoaded, handleSourceLoaded);
|
|
27
|
+
async function handlePlay() {
|
|
28
|
+
playerapi.off(PlayerEvent.Play, handlePlay);
|
|
65
29
|
attemptSetAdUi();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
82
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
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