@npo/player 1.27.6 → 1.27.8
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/npoplayer.js +19 -9
- package/lib/package.json +1 -1
- package/lib/services/npoPlayerAPI/npoPlayerAPI.js +1 -0
- package/lib/services/streamoptionsHandlers/streamOptionsHandler.js +2 -1
- package/lib/services/streamoptionsHandlers/streamOptionsHandler.test.js +1 -1
- package/lib/services/trackingHandlers/playerTrackerStart.js +1 -1
- package/lib/services/trackingHandlers/playerTrackerStart.test.js +29 -12
- package/lib/src/types/interfaces.d.ts +2 -2
- package/lib/types/interfaces.d.ts +2 -2
- package/package.json +1 -1
package/lib/npoplayer.js
CHANGED
|
@@ -114,12 +114,12 @@ export default class NpoPlayer {
|
|
|
114
114
|
customData5: this.version
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
+
this.npoPlayerServices.handleStreamOptions(this.playerContext);
|
|
117
118
|
void this.playerContext.player.createUIManager(this.playerContext, this.variant);
|
|
118
119
|
await this.playerContext.player?.load(this.sourceConfig);
|
|
119
120
|
this.npoPlayerServices.startPlayerTracker({
|
|
120
121
|
playerContext: this.playerContext,
|
|
121
|
-
source: source
|
|
122
|
-
duration: undefined
|
|
122
|
+
source: source
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
else if (sourceIsJWTToken) {
|
|
@@ -158,26 +158,37 @@ export default class NpoPlayer {
|
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
this.sourceConfig = await playerAction.processSourceConfig(this.npoPlayerServices, source, options.sourceConfig ?? {}, this.streamObject, drmType && drmType.length > 0 ? profile.drm : undefined, this.streamOptions, this.version, this.npoTag?.npoTagInstance);
|
|
161
|
+
this.npoPlayerServices.handleStreamOptions(this.playerContext);
|
|
161
162
|
await this.npoPlayerServices.verifyDRM(this.playerContext, payload);
|
|
162
|
-
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
await this.npoPlayerServices.handleError(this.playerContext, 500);
|
|
166
|
+
}
|
|
167
|
+
const streamDuration = this.streamObject.metadata.duration;
|
|
168
|
+
const initAndStartTracker = () => {
|
|
169
|
+
if (!this.playerContext || !this.player)
|
|
170
|
+
return;
|
|
171
|
+
this.player?.off(PlayerEvent.AdBreakFinished, initAndStartTracker);
|
|
172
|
+
this.player?.off(PlayerEvent.AdError, initAndStartTracker);
|
|
163
173
|
this.npoPlayerServices.startPlayerTracker({
|
|
164
174
|
playerContext: this.playerContext,
|
|
165
175
|
source: source,
|
|
166
176
|
duration: streamDuration ? Number(streamDuration) : undefined
|
|
167
177
|
});
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
await this.npoPlayerServices.handleError(this.playerContext, 500);
|
|
171
|
-
}
|
|
172
|
-
this.npoPlayerServices.handleStreamOptions(this.playerContext);
|
|
178
|
+
};
|
|
173
179
|
this.npoPlayerServices.setupNicamKijkwijzerIcons(this.playerContext);
|
|
174
180
|
setupMediaSessionActionHandlers(this.player, this.sourceConfig, this.streamObject);
|
|
175
181
|
this.hidePlayNextScreen();
|
|
176
182
|
if (this.variant === NpoPlayerUIVariants.DEFAULT &&
|
|
177
183
|
this.streamObject.metadata.hasPreroll === 'true' &&
|
|
178
184
|
this.streamObject.assets.preroll) {
|
|
185
|
+
this.player.on(PlayerEvent.AdBreakFinished, initAndStartTracker);
|
|
186
|
+
this.player.on(PlayerEvent.AdError, initAndStartTracker);
|
|
179
187
|
await this.npoPlayerServices.schedulePreRolls(this.playerContext);
|
|
180
188
|
}
|
|
189
|
+
else {
|
|
190
|
+
initAndStartTracker();
|
|
191
|
+
}
|
|
181
192
|
if (this.variant === NpoPlayerUIVariants.VERTICAL) {
|
|
182
193
|
this.npoPlayerServices.handleVerticalVideoControls(this.playerContext);
|
|
183
194
|
this.npoPlayerServices.handleVerticalVideoSettings(this.playerContext);
|
|
@@ -327,7 +338,6 @@ export default class NpoPlayer {
|
|
|
327
338
|
if (this.npoTag != undefined) {
|
|
328
339
|
clearInterval(this.npoTag.heartbeatInterval);
|
|
329
340
|
}
|
|
330
|
-
this.pause();
|
|
331
341
|
if (this.playerContext) {
|
|
332
342
|
this.npoPlayerServices.removeEventListeners(this.playerContext);
|
|
333
343
|
this.npoPlayerServices.discardAdBreak(this.playerContext);
|
package/lib/package.json
CHANGED
|
@@ -172,6 +172,7 @@ export class NpoPlayerAPI {
|
|
|
172
172
|
playerContext.npoPlayer.uiManager = uiManager;
|
|
173
173
|
playerContext.npoPlayer.variant = variant;
|
|
174
174
|
npoPlayerServices.addUivisiblityHandlers(playerContext);
|
|
175
|
+
npoPlayerServices.setupNicamKijkwijzerIcons(playerContext);
|
|
175
176
|
npoPlayerServices.showNicamAfterUiDelay(playerContext);
|
|
176
177
|
}
|
|
177
178
|
}
|
|
@@ -70,7 +70,8 @@ export function setupAutoplay(playerContext) {
|
|
|
70
70
|
};
|
|
71
71
|
const doAutoPlay = async () => {
|
|
72
72
|
player.off(NpoPlayerEvent.Ready, handleAutoPlay);
|
|
73
|
+
player.off(NpoPlayerEvent.SourceLoaded, handleAutoPlay);
|
|
73
74
|
await player.play();
|
|
74
75
|
};
|
|
75
|
-
player.on(NpoPlayerEvent.
|
|
76
|
+
player.on(NpoPlayerEvent.SourceLoaded, handleAutoPlay);
|
|
76
77
|
}
|
|
@@ -178,7 +178,7 @@ describe('handleStreamOptions', () => {
|
|
|
178
178
|
player: mockNpoPlayerAPI
|
|
179
179
|
});
|
|
180
180
|
setupAutoplay(playerContextMock);
|
|
181
|
-
expect(playerContextMock.player.on).toHaveBeenCalledWith(NpoPlayerEvent.
|
|
181
|
+
expect(playerContextMock.player.on).toHaveBeenCalledWith(NpoPlayerEvent.SourceLoaded, expect.any(Function));
|
|
182
182
|
const handleAutoPlay = playerContextMock.player.on.mock.calls[0][1];
|
|
183
183
|
await handleAutoPlay();
|
|
184
184
|
expect(playerContextMock.player.play).toHaveBeenCalled();
|
|
@@ -17,7 +17,7 @@ export const startPlayerTracker = function ({ playerContext, source, duration })
|
|
|
17
17
|
}) || 'unknown';
|
|
18
18
|
npoPlayer.streamTracker = initStreamTracker({
|
|
19
19
|
playerContext: playerContext,
|
|
20
|
-
duration: getStreamDurationInSeconds({ duration: playerDuration }),
|
|
20
|
+
duration: getStreamDurationInSeconds({ duration: playerDuration, durationIsInMs: !!duration }),
|
|
21
21
|
source: analyticsPrid
|
|
22
22
|
});
|
|
23
23
|
bindPlayerEvents(playerContext);
|
|
@@ -22,31 +22,32 @@ jest.mock('./eventLogging', () => ({
|
|
|
22
22
|
}));
|
|
23
23
|
describe('startPlayerTracker', () => {
|
|
24
24
|
let playerContextMock;
|
|
25
|
+
let playerMock;
|
|
25
26
|
beforeEach(() => {
|
|
27
|
+
playerMock = { getDuration: jest.fn().mockReturnValue(200) };
|
|
26
28
|
playerContextMock = createPlayerContextMock({
|
|
27
29
|
npoPlayer: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
npoTagPageTracker: undefined
|
|
30
|
+
player: playerMock,
|
|
31
|
+
sourceConfig: {},
|
|
32
|
+
streamObject: {}
|
|
32
33
|
}
|
|
33
34
|
});
|
|
34
35
|
jest.clearAllMocks();
|
|
35
36
|
});
|
|
36
|
-
it('should initialize the stream tracker with
|
|
37
|
+
it('should initialize the stream tracker with the provided duration', () => {
|
|
37
38
|
const source = 'some-source';
|
|
38
39
|
const duration = 150;
|
|
39
40
|
getAnalyticsPrid.mockReturnValue('some-prid');
|
|
40
41
|
getStreamDurationInSeconds.mockReturnValue(duration);
|
|
41
|
-
startPlayerTracker({
|
|
42
|
-
playerContext: playerContextMock,
|
|
43
|
-
source,
|
|
44
|
-
duration
|
|
45
|
-
});
|
|
42
|
+
startPlayerTracker({ playerContext: playerContextMock, source, duration });
|
|
46
43
|
expect(getAnalyticsPrid).toHaveBeenCalledWith({
|
|
47
44
|
source,
|
|
48
|
-
sourceConfig:
|
|
49
|
-
streamObject:
|
|
45
|
+
sourceConfig: {},
|
|
46
|
+
streamObject: {}
|
|
47
|
+
});
|
|
48
|
+
expect(getStreamDurationInSeconds).toHaveBeenCalledWith({
|
|
49
|
+
duration,
|
|
50
|
+
durationIsInMs: true
|
|
50
51
|
});
|
|
51
52
|
expect(initStreamTracker).toHaveBeenCalledWith({
|
|
52
53
|
playerContext: playerContextMock,
|
|
@@ -56,4 +57,20 @@ describe('startPlayerTracker', () => {
|
|
|
56
57
|
expect(bindPlayerEvents).toHaveBeenCalledWith(playerContextMock);
|
|
57
58
|
expect(logEvent).toHaveBeenCalledWith({ playerContext: playerContextMock, event: 'load' });
|
|
58
59
|
});
|
|
60
|
+
it('should fallback to player.getDuration() if duration is not provided', () => {
|
|
61
|
+
const source = 'some-source';
|
|
62
|
+
const fallbackDuration = 200;
|
|
63
|
+
getAnalyticsPrid.mockReturnValue('some-prid');
|
|
64
|
+
getStreamDurationInSeconds.mockReturnValue(fallbackDuration);
|
|
65
|
+
startPlayerTracker({ playerContext: playerContextMock, source });
|
|
66
|
+
expect(getStreamDurationInSeconds).toHaveBeenCalledWith({
|
|
67
|
+
duration: fallbackDuration,
|
|
68
|
+
durationIsInMs: false
|
|
69
|
+
});
|
|
70
|
+
expect(initStreamTracker).toHaveBeenCalledWith({
|
|
71
|
+
playerContext: playerContextMock,
|
|
72
|
+
duration: fallbackDuration,
|
|
73
|
+
source: 'some-prid'
|
|
74
|
+
});
|
|
75
|
+
});
|
|
59
76
|
});
|
|
@@ -234,8 +234,8 @@ export type LocalStorageData = Partial<Record<LocalStorageValues, string | numbe
|
|
|
234
234
|
export type NPOGoogleCastRemoteControlConfig = GoogleCastRemoteControlConfig;
|
|
235
235
|
export interface PlayerTrackerParams {
|
|
236
236
|
playerContext: PlayerContext;
|
|
237
|
-
duration
|
|
238
|
-
source
|
|
237
|
+
duration?: number;
|
|
238
|
+
source?: string;
|
|
239
239
|
}
|
|
240
240
|
export interface LogEventParams {
|
|
241
241
|
playerContext: PlayerContext;
|
|
@@ -234,8 +234,8 @@ export type LocalStorageData = Partial<Record<LocalStorageValues, string | numbe
|
|
|
234
234
|
export type NPOGoogleCastRemoteControlConfig = GoogleCastRemoteControlConfig;
|
|
235
235
|
export interface PlayerTrackerParams {
|
|
236
236
|
playerContext: PlayerContext;
|
|
237
|
-
duration
|
|
238
|
-
source
|
|
237
|
+
duration?: number;
|
|
238
|
+
source?: string;
|
|
239
239
|
}
|
|
240
240
|
export interface LogEventParams {
|
|
241
241
|
playerContext: PlayerContext;
|