@newrelic/video-videojs 3.1.0 → 3.2.0-beta-0
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/CHANGELOG.md +10 -3
- package/LICENSE.txt +1 -1
- package/README.md +54 -14
- package/THIRD_PARTY_NOTICES.md +5 -33
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.LICENSE.txt +4 -2
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.LICENSE.txt +4 -2
- package/dist/esm/index.js.map +1 -0
- package/dist/umd/newrelic-video-videojs.min.js +3 -1
- package/dist/umd/newrelic-video-videojs.min.js.LICENSE.txt +4 -2
- package/dist/umd/newrelic-video-videojs.min.js.map +1 -0
- package/package.json +9 -8
- package/src/ads/brightcove-ima.js +90 -0
- package/src/ads/freewheel.js +70 -0
- package/src/ads/ima.js +248 -0
- package/src/ads/videojs-ads.js +145 -0
- package/src/index.js +2 -0
- package/src/register-plugin.js +19 -0
- package/src/techs/contrib-hls.js +45 -0
- package/src/techs/hls-js.js +45 -0
- package/src/techs/shaka.js +49 -0
- package/src/tracker.js +335 -0
package/src/tracker.js
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import nrvideo from '@newrelic/video-core';
|
|
2
|
+
import pkg from '../package.json';
|
|
3
|
+
import ContribHlsTech from './techs/contrib-hls';
|
|
4
|
+
import HlsJsTech from './techs/hls-js';
|
|
5
|
+
import ShakaTech from './techs/shaka';
|
|
6
|
+
import VideojsAdsTracker from './ads/videojs-ads';
|
|
7
|
+
import ImaAdsTracker from './ads/ima';
|
|
8
|
+
import BrightcoveImaAdsTracker from './ads/brightcove-ima';
|
|
9
|
+
import FreewheelAdsTracker from './ads/freewheel';
|
|
10
|
+
|
|
11
|
+
export default class VideojsTracker extends nrvideo.VideoTracker {
|
|
12
|
+
constructor(player, options) {
|
|
13
|
+
super(player, options);
|
|
14
|
+
this.isContentEnd = false;
|
|
15
|
+
this.imaAdCuePoints = '';
|
|
16
|
+
nrvideo.Core.addTracker(this, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getTech() {
|
|
20
|
+
let tech = this.player.tech({ IWillNotUseThisInPlugins: true });
|
|
21
|
+
|
|
22
|
+
if (tech) {
|
|
23
|
+
if (ContribHlsTech.isUsing(tech)) {
|
|
24
|
+
return new ContribHlsTech(tech);
|
|
25
|
+
} else if (HlsJsTech.isUsing(tech)) {
|
|
26
|
+
return new HlsJsTech(tech);
|
|
27
|
+
} else if (ShakaTech.isUsing(tech)) {
|
|
28
|
+
return new ShakaTech(tech);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getTrackerName() {
|
|
34
|
+
return 'videojs';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getInstrumentationProvider() {
|
|
38
|
+
return 'New Relic';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getInstrumentationName() {
|
|
42
|
+
return this.getPlayerName();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getInstrumentationVersion() {
|
|
46
|
+
return this.getPlayerVersion();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getTrackerVersion() {
|
|
50
|
+
return pkg.version;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getPlayhead() {
|
|
54
|
+
if (
|
|
55
|
+
this.player.ads &&
|
|
56
|
+
this.player.ads.state === 'ads-playback' &&
|
|
57
|
+
this.player.ads.snapshot &&
|
|
58
|
+
this.player.ads.snapshot.currentTime
|
|
59
|
+
) {
|
|
60
|
+
return this.player.ads.snapshot.currentTime * 1000;
|
|
61
|
+
} else if (this.player.absoluteTime) {
|
|
62
|
+
return this.player.absoluteTime() * 1000;
|
|
63
|
+
} else {
|
|
64
|
+
return this.player.currentTime() * 1000;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getDuration() {
|
|
69
|
+
if (
|
|
70
|
+
this.player.mediainfo &&
|
|
71
|
+
typeof this.player.mediainfo.duration !== 'undefined'
|
|
72
|
+
) {
|
|
73
|
+
return this.player.mediainfo.duration * 1000; // Brightcove
|
|
74
|
+
} else {
|
|
75
|
+
return this.player.duration() * 1000;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getTitle() {
|
|
80
|
+
return this.player?.mediainfo?.name; // Brightcove
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getId() {
|
|
84
|
+
return this.player?.mediainfo?.id; // Brightcove
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getLanguage() {
|
|
88
|
+
return this.player?.language();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getSrc() {
|
|
92
|
+
let tech = this.getTech();
|
|
93
|
+
if (tech && tech.getSrc) {
|
|
94
|
+
return tech.getSrc();
|
|
95
|
+
} else {
|
|
96
|
+
return this.player.currentSrc();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getPlayerName() {
|
|
101
|
+
return this.player?.name() || 'videojs';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getPlayerVersion() {
|
|
105
|
+
return this.player?.version;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
isMuted() {
|
|
109
|
+
return this.player.muted();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getBitrate() {
|
|
113
|
+
let tech = this.getTech();
|
|
114
|
+
return tech?.tech?.stats?.bandwidth;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getRenditionName() {
|
|
118
|
+
let tech = this.getTech();
|
|
119
|
+
if (tech && tech.getRenditionName) {
|
|
120
|
+
return tech.getRenditionName();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
getRenditionBitrate() {
|
|
125
|
+
let tech = this.getTech();
|
|
126
|
+
|
|
127
|
+
if (tech && tech.getRenditionBitrate) {
|
|
128
|
+
return tech.getRenditionBitrate();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
getRenditionHeight() {
|
|
133
|
+
let tech = this.getTech();
|
|
134
|
+
|
|
135
|
+
if (tech && tech.getRenditionHeight) {
|
|
136
|
+
return tech.getRenditionHeight();
|
|
137
|
+
}
|
|
138
|
+
return this.player.videoHeight();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getRenditionWidth() {
|
|
142
|
+
let tech = this.getTech();
|
|
143
|
+
if (tech && tech.getRenditionWidth) {
|
|
144
|
+
return tech.getRenditionWidth();
|
|
145
|
+
}
|
|
146
|
+
return this.player.videoWidth();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getPlayrate() {
|
|
150
|
+
return this.player.playbackRate();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
isAutoplayed() {
|
|
154
|
+
return this.player.autoplay();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
isFullscreen() {
|
|
158
|
+
return this.player.isFullscreen();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
getPreload() {
|
|
162
|
+
return this.player.preload();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
registerListeners() {
|
|
166
|
+
nrvideo.Log.debugCommonVideoEvents(this.player, [
|
|
167
|
+
'adstart',
|
|
168
|
+
'adend',
|
|
169
|
+
'adskip',
|
|
170
|
+
'adsready',
|
|
171
|
+
'adserror',
|
|
172
|
+
'dispose',
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
this.player.on('loadstart', this.onDownload.bind(this));
|
|
176
|
+
this.player.on('loadeddata', this.onDownload.bind(this));
|
|
177
|
+
this.player.on('loadedmetadata', this.onDownload.bind(this));
|
|
178
|
+
this.player.on('adsready', this.onAdsready.bind(this));
|
|
179
|
+
this.player.on('adstart', this.onAdStart.bind(this));
|
|
180
|
+
this.player.on('adend', this.onAdEnd.bind(this));
|
|
181
|
+
this.player.on('play', this.onPlay.bind(this));
|
|
182
|
+
this.player.on('pause', this.onPause.bind(this));
|
|
183
|
+
this.player.on('playing', this.onPlaying.bind(this));
|
|
184
|
+
this.player.on('abort', this.onAbort.bind(this));
|
|
185
|
+
this.player.on('ended', this.onEnded.bind(this));
|
|
186
|
+
this.player.on('dispose', this.onDispose.bind(this));
|
|
187
|
+
this.player.on('seeking', this.onSeeking.bind(this));
|
|
188
|
+
this.player.on('seeked', this.onSeeked.bind(this));
|
|
189
|
+
this.player.on('error', this.onError.bind(this));
|
|
190
|
+
this.player.on('waiting', this.onWaiting.bind(this));
|
|
191
|
+
this.player.on('timeupdate', this.onTimeupdate.bind(this));
|
|
192
|
+
this.player.on(
|
|
193
|
+
'ads-allpods-completed',
|
|
194
|
+
this.OnAdsAllpodsCompleted.bind(this)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
unregisterListeners() {
|
|
199
|
+
this.player.off('loadstart', this.onDownload);
|
|
200
|
+
this.player.off('loadeddata', this.onDownload);
|
|
201
|
+
this.player.off('loadedmetadata', this.onDownload);
|
|
202
|
+
this.player.off('adsready', this.onAdsready);
|
|
203
|
+
this.player.off('adstart', this.onAdStart);
|
|
204
|
+
this.player.off('adend', this.onAdEnd);
|
|
205
|
+
this.player.off('play', this.onPlay);
|
|
206
|
+
this.player.off('pause', this.onPause);
|
|
207
|
+
this.player.off('playing', this.onPlaying);
|
|
208
|
+
this.player.off('abort', this.onAbort);
|
|
209
|
+
this.player.off('ended', this.onEnded);
|
|
210
|
+
this.player.off('dispose', this.onDispose);
|
|
211
|
+
this.player.off('seeking', this.onSeeking);
|
|
212
|
+
this.player.off('seeked', this.onSeeked);
|
|
213
|
+
this.player.off('error', this.onError);
|
|
214
|
+
this.player.off('waiting', this.onWaiting);
|
|
215
|
+
this.player.off('timeupdate', this.onTimeupdate);
|
|
216
|
+
this.player.off(
|
|
217
|
+
'ads-allpods-completed',
|
|
218
|
+
this.OnAdsAllpodsCompleted.bind(this)
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
onDownload(e) {
|
|
223
|
+
this.sendDownload({ state: e.type });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
onAdsready() {
|
|
227
|
+
if (!this.adsTracker) {
|
|
228
|
+
if (BrightcoveImaAdsTracker.isUsing(this.player)) {
|
|
229
|
+
// BC IMA
|
|
230
|
+
this.setAdsTracker(new BrightcoveImaAdsTracker(this.player));
|
|
231
|
+
} else if (ImaAdsTracker.isUsing(this.player)) {
|
|
232
|
+
// IMA
|
|
233
|
+
this.setAdsTracker(new ImaAdsTracker(this.player));
|
|
234
|
+
} else if (FreewheelAdsTracker.isUsing(this.player)) {
|
|
235
|
+
// FW
|
|
236
|
+
|
|
237
|
+
this.setAdsTracker(new FreewheelAdsTracker(this.player));
|
|
238
|
+
// } else if (OnceAdsTracker.isUsing(this)) { // Once
|
|
239
|
+
} else {
|
|
240
|
+
// Generic
|
|
241
|
+
this.setAdsTracker(new VideojsAdsTracker(this.player));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
onAdStart() {
|
|
247
|
+
this.currentAdPlaying = true;
|
|
248
|
+
|
|
249
|
+
/* get the array with all the cue points which will be played */
|
|
250
|
+
if (!this.imaAdCuePoints) {
|
|
251
|
+
this.imaAdCuePoints = this.player?.ima?.getAdsManager().getCuePoints();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
onAdEnd() {
|
|
255
|
+
if (this.isContentEnd) {
|
|
256
|
+
this.sendEnd();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
OnAdsAllpodsCompleted() {
|
|
261
|
+
this.onEnded.bind(this);
|
|
262
|
+
this.FreewheelAdsCompleted = true;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
onPlay() {
|
|
266
|
+
this.sendRequest();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
onPause() {
|
|
270
|
+
this.sendPause();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
onPlaying() {
|
|
274
|
+
this.sendResume();
|
|
275
|
+
this.sendBufferEnd();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
onAbort() {
|
|
279
|
+
this.sendEnd();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
onEnded() {
|
|
283
|
+
if (this.adsTracker) {
|
|
284
|
+
this.isContentEnd = true;
|
|
285
|
+
if (this.imaAdCuePoints && !this.imaAdCuePoints.includes(-1)) {
|
|
286
|
+
this.sendEnd();
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
this.sendEnd();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
onDispose() {
|
|
294
|
+
this.sendEnd();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
onSeeking() {
|
|
298
|
+
this.sendSeekStart();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
onSeeked() {
|
|
302
|
+
this.sendSeekEnd();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
onError() {
|
|
306
|
+
const error = this.player.error();
|
|
307
|
+
|
|
308
|
+
const errorCode = error.code;
|
|
309
|
+
const errorMessage = error.message;
|
|
310
|
+
if (this.player.error && this.player.error()) {
|
|
311
|
+
this.sendError({ errorCode, errorMessage });
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
onWaiting(e) {
|
|
316
|
+
this.sendBufferStart();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
onTimeupdate(e) {
|
|
320
|
+
if (this.getPlayhead() > 0.1) {
|
|
321
|
+
this.sendStart();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Static members
|
|
327
|
+
export {
|
|
328
|
+
HlsJsTech,
|
|
329
|
+
ContribHlsTech,
|
|
330
|
+
ShakaTech,
|
|
331
|
+
VideojsAdsTracker,
|
|
332
|
+
ImaAdsTracker,
|
|
333
|
+
BrightcoveImaAdsTracker,
|
|
334
|
+
FreewheelAdsTracker,
|
|
335
|
+
};
|