@newrelic/video-core 5.0.2 → 5.1.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 +11 -0
- package/README.md +13 -0
- package/dist/cjs/browser/index.js +1 -1
- package/dist/cjs/browser/index.js.LICENSE.txt +1 -1
- package/dist/cjs/browser/index.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.LICENSE.txt +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/vega/index.js +1 -1
- package/dist/cjs/vega/index.js.LICENSE.txt +1 -1
- package/dist/cjs/vega/index.js.map +1 -1
- package/dist/esm/browser/index.js +1 -1
- package/dist/esm/browser/index.js.LICENSE.txt +1 -1
- package/dist/esm/browser/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.LICENSE.txt +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/vega/index.js +1 -1
- package/dist/esm/vega/index.js.LICENSE.txt +1 -1
- package/dist/esm/vega/index.js.map +1 -1
- package/dist/types/browser/agent.d.ts +46 -0
- package/dist/types/browser/harvestScheduler.d.ts +125 -0
- package/dist/types/browser/index.d.ts +34 -0
- package/dist/types/chrono.d.ts +52 -0
- package/dist/types/connectedDevice/connectedDeviceAgent.d.ts +63 -0
- package/dist/types/connectedDevice/connectedDeviceConstants.d.ts +51 -0
- package/dist/types/connectedDevice/connectedDeviceHarvester.d.ts +198 -0
- package/dist/types/connectedDevice/index.d.ts +30 -0
- package/dist/types/constants.d.ts +30 -0
- package/dist/types/core.d.ts +54 -0
- package/dist/types/emitter.d.ts +42 -0
- package/dist/types/eventAggregator.d.ts +97 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/log.d.ts +61 -0
- package/dist/types/obfuscate.d.ts +13 -0
- package/dist/types/optimizedHttpClient.d.ts +83 -0
- package/dist/types/recordEvent.d.ts +30 -0
- package/dist/types/retryQueueHandler.d.ts +46 -0
- package/dist/types/tracker.d.ts +176 -0
- package/dist/types/utils/eventBuilder.d.ts +69 -0
- package/dist/types/utils/harvestTimer.d.ts +45 -0
- package/dist/types/utils/index.d.ts +38 -0
- package/dist/types/utils/qoeFilters.d.ts +88 -0
- package/dist/types/videoConfiguration.d.ts +90 -0
- package/dist/types/videotracker.d.ts +366 -0
- package/dist/types/videotrackerstate.d.ts +228 -0
- package/dist/umd/nrvideo.min.js +1 -1
- package/dist/umd/nrvideo.min.js.LICENSE.txt +1 -1
- package/dist/umd/nrvideo.min.js.map +1 -1
- package/package.json +14 -2
- package/src/browser/{agent.js → agent.ts} +21 -16
- package/src/browser/{harvestScheduler.js → harvestScheduler.ts} +51 -24
- package/src/{chrono.js → chrono.ts} +29 -24
- package/src/connectedDevice/{connectedDeviceAgent.js → connectedDeviceAgent.ts} +14 -10
- package/src/connectedDevice/{connectedDeviceConstants.js → connectedDeviceConstants.ts} +5 -3
- package/src/connectedDevice/{connectedDeviceHarvester.js → connectedDeviceHarvester.ts} +71 -34
- package/src/constants.ts +62 -0
- package/src/{core.js → core.ts} +31 -18
- package/src/{emitter.js → emitter.ts} +16 -5
- package/src/{eventAggregator.js → eventAggregator.ts} +33 -19
- package/src/global.d.ts +25 -0
- package/src/{log.js → log.ts} +23 -17
- package/src/{obfuscate.js → obfuscate.ts} +6 -1
- package/src/{optimizedHttpClient.js → optimizedHttpClient.ts} +37 -13
- package/src/{recordEvent.js → recordEvent.ts} +11 -9
- package/src/{retryQueueHandler.js → retryQueueHandler.ts} +17 -12
- package/src/{tracker.js → tracker.ts} +56 -23
- package/src/utils/{eventBuilder.js → eventBuilder.ts} +31 -14
- package/src/utils/{harvestTimer.js → harvestTimer.ts} +21 -4
- package/src/utils/{index.js → index.ts} +14 -14
- package/src/utils/{qoeFilters.js → qoeFilters.ts} +19 -8
- package/src/{videoConfiguration.js → videoConfiguration.ts} +44 -10
- package/src/{videotracker.js → videotracker.ts} +119 -78
- package/src/{videotrackerstate.js → videotrackerstate.ts} +113 -49
- package/src/constants.js +0 -63
- /package/src/browser/{index.js → index.ts} +0 -0
- /package/src/connectedDevice/{index.js → index.ts} +0 -0
- /package/src/{index.js → index.ts} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RawVideoConfigInfo, RawVideoConfigOptions } from "./videoConfiguration";
|
|
2
|
+
import Emitter from "./emitter";
|
|
3
|
+
/** Structural contract Core needs from anything passed to addTracker/removeTracker. */
|
|
4
|
+
export interface TrackerLike extends Emitter {
|
|
5
|
+
dispose(): void;
|
|
6
|
+
trackerInit?(): void;
|
|
7
|
+
}
|
|
8
|
+
export interface CoreAddTrackerOptions {
|
|
9
|
+
info?: RawVideoConfigInfo;
|
|
10
|
+
config?: RawVideoConfigOptions;
|
|
11
|
+
src?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Static class that sums up core functionalities of the library.
|
|
15
|
+
* @static
|
|
16
|
+
*/
|
|
17
|
+
declare class Core {
|
|
18
|
+
/**
|
|
19
|
+
* Add a tracker to the system. Trackers added will start reporting its events to the video analytics backend.
|
|
20
|
+
*
|
|
21
|
+
* @param {(Emitter|Tracker)} tracker Tracker instance to add.
|
|
22
|
+
* @param {object} options Configuration options including video analytics settings.
|
|
23
|
+
*/
|
|
24
|
+
static addTracker(tracker: TrackerLike, options?: CoreAddTrackerOptions): void;
|
|
25
|
+
/**
|
|
26
|
+
* Disposes and remove given tracker. Removes its listeners.
|
|
27
|
+
*
|
|
28
|
+
* @param {Tracker} tracker Tracker to remove.
|
|
29
|
+
*/
|
|
30
|
+
static removeTracker(tracker: TrackerLike): void;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the array of trackers.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Tracker[]} Array of trackers.
|
|
35
|
+
*/
|
|
36
|
+
static getTrackers(): TrackerLike[];
|
|
37
|
+
/**
|
|
38
|
+
* Enhanced send method with performance timing.
|
|
39
|
+
* @param {string} eventType - Type of event
|
|
40
|
+
* @param {string} actionName - Action name
|
|
41
|
+
* @param {object} data - Event data
|
|
42
|
+
*/
|
|
43
|
+
static send(eventType: string, actionName: string, data?: Record<string, any>): boolean | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Sends an error event.
|
|
46
|
+
* This may be used for external errors launched by the app, the network or
|
|
47
|
+
* any external factor. Note that errors within the player are normally reported with
|
|
48
|
+
* tracker.sendError, so this method should not be used to report those.
|
|
49
|
+
*
|
|
50
|
+
* @param {object} att attributes to be sent along the error.
|
|
51
|
+
*/
|
|
52
|
+
static sendError(att?: Record<string, any>): boolean | undefined;
|
|
53
|
+
}
|
|
54
|
+
export default Core;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface TrackerEventPayload {
|
|
2
|
+
eventType: string;
|
|
3
|
+
type: string;
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
target: Emitter;
|
|
6
|
+
}
|
|
7
|
+
export type ListenerCallback = (payload: TrackerEventPayload) => void;
|
|
8
|
+
/**
|
|
9
|
+
* This base class implements a basic behavior of listeners and events. Extend this object to have
|
|
10
|
+
* this feature built-in inside your classes.
|
|
11
|
+
*
|
|
12
|
+
* @class Emitter
|
|
13
|
+
*/
|
|
14
|
+
declare class Emitter {
|
|
15
|
+
_listeners?: Record<string, ListenerCallback[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Sets a listener to a given event. Use {@link emit} to trigger those events.
|
|
18
|
+
* Pass '*' to listen ALL events.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} event Name of the event.
|
|
21
|
+
* @param {function} callback Callback of the event. Receives event and data.
|
|
22
|
+
* @return this
|
|
23
|
+
*/
|
|
24
|
+
on(event: string, callback: ListenerCallback): this | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Removes given callback from the listeners of this object.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} event Name of the event.
|
|
29
|
+
* @param {function} callback Callback of the event.
|
|
30
|
+
* @return this
|
|
31
|
+
*/
|
|
32
|
+
off(event: string, callback: ListenerCallback): this;
|
|
33
|
+
/**
|
|
34
|
+
* Emits given event, triggering all the associated callbacks.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} event Name of the event.
|
|
37
|
+
* @param {object} [data] Custom data to be sent to the callbacks.
|
|
38
|
+
* @return this
|
|
39
|
+
*/
|
|
40
|
+
emit(eventType: string, event: string, data?: Record<string, unknown>): this;
|
|
41
|
+
}
|
|
42
|
+
export default Emitter;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { EventAttributes } from "./utils/eventBuilder";
|
|
2
|
+
export type SmartHarvestCallback = (reason: "overflow" | "smart", percentage: number) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Enhanced event buffer that manages video events with unified priority handling
|
|
5
|
+
* and automatic size management. All events are treated with equal priority
|
|
6
|
+
* unless explicitly specified otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare class NrVideoEventAggregator {
|
|
9
|
+
buffer: EventAttributes[];
|
|
10
|
+
maxPayloadSize: number;
|
|
11
|
+
maxEventsPerBatch: number;
|
|
12
|
+
currentPayloadSize: number;
|
|
13
|
+
totalEvents: number;
|
|
14
|
+
smartHarvestPayloadThreshold: number;
|
|
15
|
+
overflowPayloadThreshold: number;
|
|
16
|
+
smartHarvestEventThreshold: number;
|
|
17
|
+
overflowEventThreshold: number;
|
|
18
|
+
onSmartHarvestTrigger: SmartHarvestCallback | null;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* If an event with the specified actionName already exists in the buffer, it will be replaced.
|
|
22
|
+
* Otherwise, the event will be added as a new entry.
|
|
23
|
+
* @param {string} actionName - The actionName to search for in the buffer
|
|
24
|
+
* @param {object} eventObject - The event object to add or use as replacement. Should contain an actionName property.
|
|
25
|
+
* @returns {boolean} True if the operation succeeded, false if an error occurred
|
|
26
|
+
*/
|
|
27
|
+
addOrReplaceByActionName(actionName: string, eventObject: EventAttributes): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* If an event with the specified actionName and viewId already exists in the buffer, it will be replaced.
|
|
30
|
+
* Otherwise, the event will be added as a new entry.
|
|
31
|
+
* @param {string} actionName - The actionName to search for in the buffer
|
|
32
|
+
* @param {string} viewId - The viewId to scope the lookup to
|
|
33
|
+
* @param {object} eventObject - The event object to add or use as replacement.
|
|
34
|
+
* @returns {boolean} True if the operation succeeded, false if an error occurred
|
|
35
|
+
*/
|
|
36
|
+
addOrReplaceByActionNameAndViewId(actionName: string, viewId: string, eventObject: EventAttributes): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the existing event in buffer matching the given actionName and viewId, or null.
|
|
39
|
+
* @param {string} actionName
|
|
40
|
+
* @param {string} viewId
|
|
41
|
+
* @returns {object|null}
|
|
42
|
+
*/
|
|
43
|
+
findByActionNameAndViewId(actionName: string, viewId: string): EventAttributes | null;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the existing event in buffer matching the given actionName, or null.
|
|
46
|
+
* @param {string} actionName
|
|
47
|
+
* @returns {object|null}
|
|
48
|
+
*/
|
|
49
|
+
findByActionName(actionName: string): EventAttributes | null;
|
|
50
|
+
/**
|
|
51
|
+
* Adds an event to the unified buffer.
|
|
52
|
+
* All events are treated equally in FIFO order.
|
|
53
|
+
* @param {object} eventObject - The event to add
|
|
54
|
+
* @param {number} index - index at which the event should be replaced with
|
|
55
|
+
*/
|
|
56
|
+
add(eventObject: EventAttributes, index?: number): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Checks if smart harvest should be triggered based on dual threshold system.
|
|
59
|
+
* Triggers when EITHER condition is met first:
|
|
60
|
+
* - 60% of payload size (600KB) OR 60% of event count (600 events)
|
|
61
|
+
* - 90% of payload size (900KB) OR 90% of event count (900 events)
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
checkSmartHarvestTrigger(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the callback function for smart harvest triggers.
|
|
67
|
+
* @param {Function} callback - Function to call when smart harvest is triggered
|
|
68
|
+
*/
|
|
69
|
+
setSmartHarvestCallback(callback: SmartHarvestCallback): void;
|
|
70
|
+
/**
|
|
71
|
+
* Drains all events from the buffer in FIFO order (first in, first out).
|
|
72
|
+
* No limits needed since buffer already manages size via makeRoom() and smart harvest triggers.
|
|
73
|
+
* @returns {Array} Array of events in order they were added
|
|
74
|
+
*/
|
|
75
|
+
drain(): EventAttributes[];
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the buffer is empty.
|
|
78
|
+
* @returns {boolean} True if all buffers are empty
|
|
79
|
+
*/
|
|
80
|
+
isEmpty(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the total number of events across all buffers.
|
|
83
|
+
* @returns {number} Total event count
|
|
84
|
+
*/
|
|
85
|
+
size(): number;
|
|
86
|
+
/**
|
|
87
|
+
* Clears the entire buffer.
|
|
88
|
+
*/
|
|
89
|
+
clear(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Makes room in the buffer by removing the oldest event.
|
|
92
|
+
* Uses FIFO approach - removes the first (oldest) event.
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
95
|
+
makeRoom(newEventSize: number): void;
|
|
96
|
+
}
|
|
97
|
+
export default NrVideoEventAggregator;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Core from "./core";
|
|
2
|
+
import Constants from "./constants";
|
|
3
|
+
import Chrono from "./chrono";
|
|
4
|
+
import Log from "./log";
|
|
5
|
+
import Emitter from "./emitter";
|
|
6
|
+
import Tracker from "./tracker";
|
|
7
|
+
import VideoTracker from "./videotracker";
|
|
8
|
+
import VideoTrackerState from "./videotrackerstate";
|
|
9
|
+
import { NrVideoEventAggregator } from "./eventAggregator";
|
|
10
|
+
import { RetryQueueHandler } from "./retryQueueHandler";
|
|
11
|
+
import { OptimizedHttpClient } from "./optimizedHttpClient";
|
|
12
|
+
import { HarvestScheduler } from "./browser/harvestScheduler";
|
|
13
|
+
import { recordEvent } from "./recordEvent";
|
|
14
|
+
declare const nrvideo: {
|
|
15
|
+
Constants: typeof Constants;
|
|
16
|
+
Chrono: typeof Chrono;
|
|
17
|
+
Log: typeof Log;
|
|
18
|
+
Emitter: typeof Emitter;
|
|
19
|
+
Tracker: typeof Tracker;
|
|
20
|
+
VideoTracker: typeof VideoTracker;
|
|
21
|
+
VideoTrackerState: typeof VideoTrackerState;
|
|
22
|
+
Core: typeof Core;
|
|
23
|
+
version: string;
|
|
24
|
+
NrVideoEventAggregator: typeof NrVideoEventAggregator;
|
|
25
|
+
RetryQueueHandler: typeof RetryQueueHandler;
|
|
26
|
+
OptimizedHttpClient: typeof OptimizedHttpClient;
|
|
27
|
+
HarvestScheduler: typeof HarvestScheduler;
|
|
28
|
+
recordEvent: typeof recordEvent;
|
|
29
|
+
};
|
|
30
|
+
export { videoAnalyticsHarvester } from "./browser/agent";
|
|
31
|
+
export { connectedDeviceAnalyticsHarvester } from "./connectedDevice/connectedDeviceAgent";
|
|
32
|
+
export { getRegisteredHarvester } from "./recordEvent";
|
|
33
|
+
export default nrvideo;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static Log class
|
|
3
|
+
*
|
|
4
|
+
* @class
|
|
5
|
+
* @static
|
|
6
|
+
*/
|
|
7
|
+
declare class Log {
|
|
8
|
+
static Levels: Record<string, number>;
|
|
9
|
+
static level: number | string;
|
|
10
|
+
static colorful: boolean;
|
|
11
|
+
static includeTime: boolean;
|
|
12
|
+
static prefix: string;
|
|
13
|
+
/**
|
|
14
|
+
* Sends an error console log.
|
|
15
|
+
* @param {...any} [msg] Message to show
|
|
16
|
+
* @static
|
|
17
|
+
*/
|
|
18
|
+
static error(...msg: any[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Sends a warning console log.
|
|
21
|
+
* @method Log.warn
|
|
22
|
+
* @static
|
|
23
|
+
* @param {...any} msg Message to show
|
|
24
|
+
*/
|
|
25
|
+
static warn(...msg: any[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Sends a notice console log.
|
|
28
|
+
* @method Log.notice
|
|
29
|
+
* @static
|
|
30
|
+
* @param {...any} msg Message to show
|
|
31
|
+
*/
|
|
32
|
+
static notice(...msg: any[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Sends a debug message to console.
|
|
35
|
+
* @method Log.debug
|
|
36
|
+
* @static
|
|
37
|
+
* @param {...any} msg Message to show
|
|
38
|
+
*/
|
|
39
|
+
static debug(...msg: any[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* This utility method will add most of the HTML5 common event listeners to the player sent.
|
|
42
|
+
* Events will be reported as DEBUG level messages.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Already included events:
|
|
46
|
+
* ['canplay', 'buffering', 'waiting', 'ended', 'play', 'playing', 'pause', 'resume', 'error',
|
|
47
|
+
* 'abort', 'seek', 'seeking', 'seeked', 'stalled', 'dispose', 'loadeddata', 'loadstart',
|
|
48
|
+
* 'loadedmetadata']
|
|
49
|
+
*
|
|
50
|
+
* @method Log.debugCommonVideoEvents
|
|
51
|
+
* @static
|
|
52
|
+
* @param {object|function} o Object to attach the events.
|
|
53
|
+
* @param {array} [extraEvents]
|
|
54
|
+
* An array of extra events to watch. ie: ['timeupdate', 'progress'].
|
|
55
|
+
* If the first item is null, no common events will be added.
|
|
56
|
+
* @param {function} [report] Callback function called to report events.
|
|
57
|
+
* Default calls Log.debug()
|
|
58
|
+
*/
|
|
59
|
+
static debugCommonVideoEvents(o: any, extraEvents?: any[], report?: (e: any) => void): void;
|
|
60
|
+
}
|
|
61
|
+
export default Log;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ObfuscationRule {
|
|
2
|
+
regex: string | RegExp;
|
|
3
|
+
replacement: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Applies obfuscation rules to a JSON string before sending to the collector.
|
|
7
|
+
* Each rule replaces matches of `regex` with `replacement` in the string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} jsonString - Serialized JSON payload
|
|
10
|
+
* @param {Array<{regex: string|RegExp, replacement: string}>} rules - Obfuscation rules
|
|
11
|
+
* @returns {string} Obfuscated string
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyObfuscationRules(jsonString: string, rules?: ObfuscationRule[]): string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface HttpRequestOptions {
|
|
2
|
+
url: string;
|
|
3
|
+
payload: {
|
|
4
|
+
body: any;
|
|
5
|
+
};
|
|
6
|
+
options?: {
|
|
7
|
+
isFinalHarvest?: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface HttpResultCallback {
|
|
11
|
+
(result: {
|
|
12
|
+
retry?: boolean;
|
|
13
|
+
status: number;
|
|
14
|
+
statusText?: string;
|
|
15
|
+
error?: string;
|
|
16
|
+
}): void;
|
|
17
|
+
}
|
|
18
|
+
interface InternalRequest {
|
|
19
|
+
url: string;
|
|
20
|
+
payload: {
|
|
21
|
+
body: any;
|
|
22
|
+
};
|
|
23
|
+
options: {
|
|
24
|
+
isFinalHarvest?: boolean;
|
|
25
|
+
};
|
|
26
|
+
callback: HttpResultCallback;
|
|
27
|
+
}
|
|
28
|
+
interface RequestResult {
|
|
29
|
+
success: boolean;
|
|
30
|
+
status: number;
|
|
31
|
+
statusText?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Optimized HTTP client for video analytics data transmission with
|
|
36
|
+
* performance monitoring and efficient request handling.
|
|
37
|
+
*/
|
|
38
|
+
export declare class OptimizedHttpClient {
|
|
39
|
+
/**
|
|
40
|
+
* Sends data to the specified URL with performance monitoring.
|
|
41
|
+
* @param {object} requestOptions - Request configuration
|
|
42
|
+
* @param {string} requestOptions.url - Target URL
|
|
43
|
+
* @param {object} requestOptions.payload - Request payload
|
|
44
|
+
* @param {object} requestOptions.options - Additional options
|
|
45
|
+
* @param {Function} callback - Callback function for handling response
|
|
46
|
+
* @returns {Promise<void>}
|
|
47
|
+
*/
|
|
48
|
+
send(requestOptions: HttpRequestOptions, callback: HttpResultCallback): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Executes an HTTP request with timeout and error handling.
|
|
51
|
+
* @param {object} request - Request object
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
executeRequest(request: InternalRequest): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Handles request completion.
|
|
57
|
+
* @param {object} request - Request object
|
|
58
|
+
* @param {object} result - Request result
|
|
59
|
+
* @param {number} startTime - Request start timestamp
|
|
60
|
+
* @param {string} endpoint - The endpoint that was used for the request
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
handleRequestComplete(request: InternalRequest, result: RequestResult, startTime?: number): void;
|
|
64
|
+
/**
|
|
65
|
+
* Sends data using navigator.sendBeacon for final harvests.
|
|
66
|
+
* @param {string} url - Target URL
|
|
67
|
+
* @param {string} body - Request body
|
|
68
|
+
* @returns {Promise<boolean>} True if successful
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
sendWithBeacon(url: string, body: string): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Fetch with timeout implementation.
|
|
74
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortController|MDN AbortController}
|
|
75
|
+
* @param {string} url - Target URL
|
|
76
|
+
* @param {object} options - Fetch options
|
|
77
|
+
* @param {number} timeout - Timeout in milliseconds
|
|
78
|
+
* @returns {Promise<Response>} Fetch response
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
fetchWithTimeout(url: string, options: RequestInit, timeout: number): Promise<Response>;
|
|
82
|
+
}
|
|
83
|
+
export default OptimizedHttpClient;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EventAttributes, Harvester } from "./utils/eventBuilder";
|
|
2
|
+
export type { EventAttributes, Harvester };
|
|
3
|
+
/**
|
|
4
|
+
* Register a harvester implementation under a routing key.
|
|
5
|
+
* Called by `agent.js` (key `'Browser'`) and `connectedDeviceAgent.js`
|
|
6
|
+
* (key `'Vega'`) at module load time.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} key Routing key matching `attributes.src`.
|
|
9
|
+
* @param {{ addEvent: function }} harvester
|
|
10
|
+
*/
|
|
11
|
+
export declare function registerHarvester(key: string, harvester: Harvester): void;
|
|
12
|
+
/**
|
|
13
|
+
* Look up a harvester registered under a routing key. Returns `undefined` if
|
|
14
|
+
* no module has registered for that key in this build (e.g. on the `/browser`
|
|
15
|
+
* subpath, the 'Vega' key is never registered because `connectedDeviceAgent.js`
|
|
16
|
+
* is unreachable from that entry's import graph).
|
|
17
|
+
*
|
|
18
|
+
* Trackers use this getter — instead of importing the harvester binding by
|
|
19
|
+
* name — so the same `tracker.js` / `vegaTracker.js` source files compile
|
|
20
|
+
* unchanged across all three core entry points (main, /browser, /vega) when
|
|
21
|
+
* the html5 webpack build aliases `@newrelic/video-core` to a specific
|
|
22
|
+
* subpath. Without this, parent-class file `tracker.js` would carry an
|
|
23
|
+
* unconditional `import { videoAnalyticsHarvester }` that fails to resolve
|
|
24
|
+
* against the `/vega` subpath.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} key
|
|
27
|
+
* @returns {{ addEvent: function }|undefined}
|
|
28
|
+
*/
|
|
29
|
+
export declare function getRegisteredHarvester(key: string): Harvester | undefined;
|
|
30
|
+
export declare function recordEvent(eventType: string, attributes?: EventAttributes): boolean | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EventAttributes } from "./utils/eventBuilder";
|
|
2
|
+
/**
|
|
3
|
+
* Retry Queue Handler for managing failed events with retry logic,
|
|
4
|
+
* backoff strategies, and persistent storage capabilities.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RetryQueueHandler {
|
|
7
|
+
retryQueue: EventAttributes[];
|
|
8
|
+
maxQueueSize: number;
|
|
9
|
+
maxQueueSizeBytes: number;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Adds failed events to the retry queue for retry processing.
|
|
13
|
+
* @param {Array|object} events - Failed event(s) to add to retry queue
|
|
14
|
+
*/
|
|
15
|
+
addFailedEvents(events: EventAttributes | EventAttributes[]): void;
|
|
16
|
+
/**
|
|
17
|
+
* Discards an event that cannot be retried.
|
|
18
|
+
* @param {object} event - Event to discard
|
|
19
|
+
* @param {string} reason - Reason for discarding
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
discardEvent(event: EventAttributes, reason: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Evicts the oldest event from the queue to make room.
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
evictOldestEvent(): void;
|
|
28
|
+
/**
|
|
29
|
+
* For unified harvesting - get retry events that fit within payload limits
|
|
30
|
+
* Removes the selected events from the retry queue since they're being retried
|
|
31
|
+
* @param {number} availableSpace - Available payload space in bytes
|
|
32
|
+
* @param {number} availableEventCount - Available event count
|
|
33
|
+
* @returns {Array} Array of events that fit within limits
|
|
34
|
+
*/
|
|
35
|
+
getRetryEventsToFit(availableSpace: number, availableEventCount: number): EventAttributes[];
|
|
36
|
+
/**
|
|
37
|
+
* Gets the current retry queue size.
|
|
38
|
+
* @returns {number} Queue size
|
|
39
|
+
*/
|
|
40
|
+
getQueueSize(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Clears the retry queue.
|
|
43
|
+
*/
|
|
44
|
+
clear(): void;
|
|
45
|
+
}
|
|
46
|
+
export default RetryQueueHandler;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import Emitter from "./emitter";
|
|
2
|
+
import Chrono from "./chrono";
|
|
3
|
+
import { Harvester } from "./utils/eventBuilder";
|
|
4
|
+
export interface TrackerOptions {
|
|
5
|
+
heartbeat?: number;
|
|
6
|
+
customData?: Record<string, any>;
|
|
7
|
+
parentTracker?: Tracker;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tracker class provides the basic logic to extend Newrelic's Browser Agent capabilities.
|
|
11
|
+
* Trackers are designed to listen third party elements (like video tags, banners, etc.) and send
|
|
12
|
+
* information over to Browser Agent. Extend this class to create your own tracker, override
|
|
13
|
+
* registerListeners and unregisterListeners for full coverage!
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* Tracker instances should be added to Core library to start sending data:
|
|
17
|
+
* nrvideo.Core.addTracker(new Tracker())
|
|
18
|
+
*
|
|
19
|
+
* @extends Emitter
|
|
20
|
+
*/
|
|
21
|
+
declare class Tracker extends Emitter {
|
|
22
|
+
static Events: Record<string, string>;
|
|
23
|
+
customData: Record<string, any>;
|
|
24
|
+
heartbeat: number | null;
|
|
25
|
+
parentTracker: Tracker | null;
|
|
26
|
+
/**
|
|
27
|
+
* Set externally by subclasses (VideoTracker, which assigns a real
|
|
28
|
+
* VideoTrackerState instance) / tests (which assign plain `{ _isAd }`
|
|
29
|
+
* objects) before any method that reads `this.state._isAd` is invoked.
|
|
30
|
+
* Not initialized in the base constructor. Loosely typed (`any`) since
|
|
31
|
+
* both shapes need to be assignable here without a circular import of
|
|
32
|
+
* VideoTrackerState into the base Tracker.
|
|
33
|
+
*/
|
|
34
|
+
state?: any;
|
|
35
|
+
_trackerReadyChrono: Chrono;
|
|
36
|
+
_actionTable: any;
|
|
37
|
+
_actionAdTable: any;
|
|
38
|
+
_heartbeatInterval?: ReturnType<typeof setInterval>;
|
|
39
|
+
/**
|
|
40
|
+
* Constructor, receives options. You should call {@see registerListeners} after this.
|
|
41
|
+
*
|
|
42
|
+
* @param {Object} [options] Options for the tracker. See {@link setOptions}.
|
|
43
|
+
*/
|
|
44
|
+
constructor(options?: TrackerOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Set options for the Tracker.
|
|
47
|
+
*
|
|
48
|
+
* @param {Object} [options] Options for the tracker.
|
|
49
|
+
* @param {number} [options.heartbeat] Set time between heartbeats. See {@link heartbeat}.
|
|
50
|
+
* @param {Object} [options.customData] Set custom data. See {@link customData}.
|
|
51
|
+
* @param {Tracker} [options.parentTracker] Set parent tracker. See {@link parentTracker}.
|
|
52
|
+
*/
|
|
53
|
+
setOptions(options?: TrackerOptions): void;
|
|
54
|
+
/**
|
|
55
|
+
* Prepares tracker to dispose. Calls {@see unregisterListeners} and drops references.
|
|
56
|
+
*/
|
|
57
|
+
dispose(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Override this method to register listeners to third party elements.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* class SpecificTracker extends Tracker {
|
|
63
|
+
* registerListeners() {
|
|
64
|
+
* this.player.on('play', () => this.playHandler)
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* playHandler() {
|
|
68
|
+
* this.emit(Tracker.Events.REQUESTED)
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
registerListeners(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Override this method to unregister listeners to third party elements created with
|
|
75
|
+
* {@see registerListeners}.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* class SpecificTracker extends Tracker {
|
|
79
|
+
* registerListeners() {
|
|
80
|
+
* this.player.on('play', () => this.playHandler)
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* unregisterListeners() {
|
|
84
|
+
* this.player.off('play', () => this.playHandler)
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* playHandler() {
|
|
88
|
+
* this.emit(Tracker.Events.REQUESTED)
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
*/
|
|
92
|
+
unregisterListeners(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Returns heartbeat time interval. 30000 (30s) if not set. See {@link setOptions}.
|
|
95
|
+
* @return {number} Heartbeat interval in ms.
|
|
96
|
+
* @final
|
|
97
|
+
*/
|
|
98
|
+
getHeartbeat(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Starts heartbeating. Interval period set by options.heartbeat. Min 2000 ms.
|
|
101
|
+
* This method is automaticaly called by the tracker once sendRequest is called.
|
|
102
|
+
*/
|
|
103
|
+
startHeartbeat(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Stops heartbeating. This method is automaticaly called by the tracker.
|
|
106
|
+
*/
|
|
107
|
+
stopHeartbeat(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Heartbeating allows you to call this function each X milliseconds, defined by
|
|
110
|
+
* {@link getHeartbeat}. This is useful to send regular events to track changes.
|
|
111
|
+
*
|
|
112
|
+
* By default it will send {@link Tracker.Events.HEARTBEAT}.
|
|
113
|
+
* To start heartbeating use {@link startHeartbeat} and to stop them use {@link stopHeartbeat}.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* Override this method to define your own Heartbeat reporting.
|
|
117
|
+
*
|
|
118
|
+
* class TrackerChild extends Tracker {
|
|
119
|
+
* sendHeartbeat (att) {
|
|
120
|
+
* this.send('MY_HEARBEAT_EVENT')
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* @param {Object} [att] Collection of key:value attributes to send with the request.
|
|
125
|
+
*/
|
|
126
|
+
sendHeartbeat(att?: Record<string, any>): void;
|
|
127
|
+
/**
|
|
128
|
+
* Override this method to return attributes for actions.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* class SpecificTracker extends Tracker {
|
|
132
|
+
* getAttributes(att) {
|
|
133
|
+
* att = att || {}
|
|
134
|
+
* att.information = 'something'
|
|
135
|
+
* return att
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
*
|
|
139
|
+
* @param {object} [att] Collection of key value attributes
|
|
140
|
+
* @return {object} Filled attributes
|
|
141
|
+
* @final
|
|
142
|
+
*/
|
|
143
|
+
getAttributes(att?: Record<string, any>, eventType?: string): Record<string, any>;
|
|
144
|
+
/** Override to change of the Version of tracker. ie: '1.0.1' */
|
|
145
|
+
getTrackerVersion(): string;
|
|
146
|
+
/** Override to change of the Name of the tracker. ie: 'custom-html5' */
|
|
147
|
+
getTrackerName(): string;
|
|
148
|
+
/**
|
|
149
|
+
* Send given event. Will automatically call {@see getAttributes} to fill information.
|
|
150
|
+
* Internally, this will call {@see Emitter#emit}, so you could listen any event fired.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* tracker.sendVideoAction('BANNER_CLICK', { url: 'http....' })
|
|
154
|
+
*
|
|
155
|
+
* @param {string} event Event name
|
|
156
|
+
* @param {object} [att] Key:value dictionary filled with attributes.
|
|
157
|
+
*/
|
|
158
|
+
sendVideoAction(event: string, att?: Record<string, any>): void;
|
|
159
|
+
sendVideoAdAction(event: string, att?: Record<string, any>): void;
|
|
160
|
+
sendVideoErrorAction(event: string, att?: Record<string, any>): void;
|
|
161
|
+
sendVideoCustomAction(event: string, att?: Record<string, any>): void;
|
|
162
|
+
/**
|
|
163
|
+
* Sets the harvest interval for video tracking.
|
|
164
|
+
* @param {*} interval - The interval in milliseconds.
|
|
165
|
+
* @returns {void}
|
|
166
|
+
*/
|
|
167
|
+
setHarvestInterval(interval: number): void;
|
|
168
|
+
/**
|
|
169
|
+
* Default harvester accessor. Subclasses (Html5Tracker, VegaTracker, etc.)
|
|
170
|
+
* override this to point to their specific harvester. Returning `null` here
|
|
171
|
+
* means a tracker that doesn't override `getHarvester()` will silently no-op
|
|
172
|
+
* on harvester-bound calls (setHarvestInterval, QoE drain wiring).
|
|
173
|
+
*/
|
|
174
|
+
getHarvester(): Harvester | null;
|
|
175
|
+
}
|
|
176
|
+
export default Tracker;
|