@npo/player 1.18.2 → 1.18.3
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 +105 -109
- package/lib/js/tracking/handlers/eventlogging.js +1 -1
- package/lib/npoplayer.js +2 -2
- package/lib/package.json +1 -1
- package/package.json +1 -1
package/lib/js/ads/ster.js
CHANGED
|
@@ -1,121 +1,117 @@
|
|
|
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
|
-
|
|
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)
|
|
7
49
|
return;
|
|
50
|
+
if (!adUiSet) {
|
|
51
|
+
setAdUi();
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
attemptSetAdUi(attemptsLeft - 1);
|
|
54
|
+
}, 200);
|
|
8
55
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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);
|
|
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;
|
|
25
63
|
}
|
|
26
|
-
|
|
27
|
-
async function handlePlay() {
|
|
28
|
-
playerapi.off(PlayerEvent.Play, handlePlay);
|
|
64
|
+
if (!adUiSet)
|
|
29
65
|
attemptSetAdUi();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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);
|
|
57
|
-
}
|
|
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;
|
|
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();
|
|
65
80
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
npoplayer.adBreakActive = true;
|
|
69
|
-
}
|
|
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;
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.log(error);
|
|
99
83
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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;
|
|
106
93
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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();
|
|
94
|
+
if (adIndex >= totalAds) {
|
|
95
|
+
handleAdBreakFinished();
|
|
96
|
+
return;
|
|
118
97
|
}
|
|
119
|
-
|
|
120
|
-
|
|
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);
|
|
121
117
|
}
|
package/lib/npoplayer.js
CHANGED
|
@@ -107,10 +107,10 @@ export default class NpoPlayer {
|
|
|
107
107
|
await drm.verifyDRM(this, this.player, payload);
|
|
108
108
|
setupMediaSessionActionHandlers(this.player, this.sourceConfig, _streamObject);
|
|
109
109
|
logEvent(this, 'load');
|
|
110
|
+
startPlayerTracker(this, utility.validateStreamLength(_streamObject.metadata.duration, false), this.version, _streamObject.metadata.prid);
|
|
110
111
|
if (this.variant !== NpoPlayerUIVariants.AUDIO) {
|
|
111
|
-
|
|
112
|
+
handlePreRolls(this.player, _streamObject, this);
|
|
112
113
|
}
|
|
113
|
-
startPlayerTracker(this, utility.validateStreamLength(_streamObject.metadata.duration, false), this.version, _streamObject.metadata.prid);
|
|
114
114
|
}
|
|
115
115
|
else {
|
|
116
116
|
this.doError(`Het is niet gelukt de stream op te halen: \n Input is geen valide token of media object.`, 500);
|
package/lib/package.json
CHANGED