@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,46 @@
|
|
|
1
|
+
import { HarvestScheduler } from "./harvestScheduler";
|
|
2
|
+
import { NrVideoEventAggregator } from "../eventAggregator";
|
|
3
|
+
import { EventAttributes, Harvester } from "../utils/eventBuilder";
|
|
4
|
+
/**
|
|
5
|
+
* Enhanced video analytics agent with HarvestScheduler only.
|
|
6
|
+
*/
|
|
7
|
+
declare class VideoAnalyticsAgent implements Harvester {
|
|
8
|
+
isInitialized: boolean;
|
|
9
|
+
harvestScheduler: HarvestScheduler | null;
|
|
10
|
+
eventBuffer: NrVideoEventAggregator | null;
|
|
11
|
+
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Initializes the video analytics agent with enhanced HarvestScheduler.
|
|
14
|
+
*/
|
|
15
|
+
initialize(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Adds an event to the harvesting system.
|
|
18
|
+
* @param {object} eventObject - Event to add
|
|
19
|
+
* @returns {boolean} True if event was added successfully
|
|
20
|
+
*/
|
|
21
|
+
addEvent(eventObject: EventAttributes): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the harvest interval for the scheduler.
|
|
24
|
+
* @param {number} interval - The harvest interval in milliseconds.
|
|
25
|
+
*/
|
|
26
|
+
setHarvestInterval(interval: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* Forces the next harvest cycle to include QOE_AGGREGATE events.
|
|
29
|
+
* Called at CONTENT_END to ensure final QoE is sent.
|
|
30
|
+
*/
|
|
31
|
+
forceNextQoeCycle(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Sets a callback to be called before each drain to refresh QoE KPIs.
|
|
34
|
+
* @param {Function|null} callback - Function that refreshes QoE data in the buffer, or null to clear
|
|
35
|
+
*/
|
|
36
|
+
setBeforeDrainCallback(callback: (() => void) | null): void;
|
|
37
|
+
/**
|
|
38
|
+
* Updates QoE KPI fields on the existing QOE_AGGREGATE event in the buffer.
|
|
39
|
+
* Scoped to a specific viewId to support multiple players on the same page.
|
|
40
|
+
* @param {object} freshKpis - Object with latest KPI values
|
|
41
|
+
* @param {string} [viewId] - The viewId of the player whose QoE event to update
|
|
42
|
+
*/
|
|
43
|
+
refreshQoeKpis(freshKpis: EventAttributes, viewId?: string): void;
|
|
44
|
+
}
|
|
45
|
+
export declare const videoAnalyticsHarvester: VideoAnalyticsAgent;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { NrVideoEventAggregator } from "../eventAggregator";
|
|
2
|
+
import { RetryQueueHandler } from "../retryQueueHandler";
|
|
3
|
+
import { OptimizedHttpClient } from "../optimizedHttpClient";
|
|
4
|
+
import { HarvestTimer } from "../utils/harvestTimer";
|
|
5
|
+
import { EventAttributes } from "../utils/eventBuilder";
|
|
6
|
+
interface HarvestOptions {
|
|
7
|
+
isFinalHarvest?: boolean;
|
|
8
|
+
force?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface HarvestResult {
|
|
11
|
+
success: boolean;
|
|
12
|
+
reason?: string;
|
|
13
|
+
totalChunks?: number;
|
|
14
|
+
results?: any[];
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Enhanced harvest scheduler that orchestrates the video analytics data collection,
|
|
19
|
+
* processing, and transmission with smart harvesting and performance monitoring.
|
|
20
|
+
*/
|
|
21
|
+
export declare class HarvestScheduler {
|
|
22
|
+
eventBuffer: NrVideoEventAggregator;
|
|
23
|
+
retryQueueHandler: RetryQueueHandler;
|
|
24
|
+
httpClient: OptimizedHttpClient;
|
|
25
|
+
fallBackUrl: string;
|
|
26
|
+
retryCount: number;
|
|
27
|
+
harvestCycle: number;
|
|
28
|
+
isHarvesting: boolean;
|
|
29
|
+
qoeCycleCount: number;
|
|
30
|
+
forceNextQoeCycle: boolean;
|
|
31
|
+
beforeDrainCallback: (() => void) | null;
|
|
32
|
+
_lastSentQoeKpis: Record<string, any>;
|
|
33
|
+
timer: HarvestTimer;
|
|
34
|
+
constructor(eventAggregator: NrVideoEventAggregator);
|
|
35
|
+
/**
|
|
36
|
+
* Whether the scheduler is currently running. Backed by the shared timer.
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
get isStarted(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Starts the harvest scheduler.
|
|
42
|
+
*/
|
|
43
|
+
startScheduler(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Stops the harvest scheduler.
|
|
46
|
+
*/
|
|
47
|
+
stopScheduler(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Triggers a smart harvest when buffer reaches threshold capacity.
|
|
50
|
+
* @param {string} type - Type of harvest trigger ('smart' or 'overflow')
|
|
51
|
+
* @param {number} threshold - Threshold percentage that triggered the harvest (60 or 90)
|
|
52
|
+
*/
|
|
53
|
+
triggerSmartHarvest(type: string, threshold: number): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Periodic-tick callback. Invoked by the shared harvest timer on each cycle.
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
onHarvestInterval(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Triggers a harvest cycle with comprehensive error handling and monitoring.
|
|
61
|
+
* @param {object} options - Harvest options
|
|
62
|
+
* @param {boolean} options.isFinalHarvest - Whether this is a final harvest on page unload
|
|
63
|
+
* @param {boolean} options.force - Force harvest even if buffer is empty
|
|
64
|
+
* @returns {Promise<object>} Harvest result
|
|
65
|
+
*/
|
|
66
|
+
triggerHarvest(options?: HarvestOptions): Promise<HarvestResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Trims events to fit within a specified size limit for beacon harvests.
|
|
69
|
+
* Keeps the most recent events and discards older ones.
|
|
70
|
+
* @param {Array} events - Events to trim
|
|
71
|
+
* @param {number} maxSize - Maximum payload size in bytes
|
|
72
|
+
* @returns {Array} Trimmed events that fit within size limit
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
trimEventsToFit(events: EventAttributes[], maxSize: number): EventAttributes[];
|
|
76
|
+
/**
|
|
77
|
+
* Drains events from the event buffer and optionally includes retry queue data.
|
|
78
|
+
* Uses fresh-events-first approach with payload limits.
|
|
79
|
+
* Filters out QOE_AGGREGATE events based on the harvest interval multiplier,
|
|
80
|
+
* always including them on the first and final harvest cycles.
|
|
81
|
+
* @param {object} options - Harvest options
|
|
82
|
+
* @returns {Array} Drained events
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
drainEvents(options?: HarvestOptions): EventAttributes[];
|
|
86
|
+
/**
|
|
87
|
+
* Sends a chunk of events using the optimized HTTP client.
|
|
88
|
+
* @param {Array} chunk - Events to send
|
|
89
|
+
* @param {object} options - Harvest options
|
|
90
|
+
* @param {boolean} isLastChunk - Whether this is the last chunk
|
|
91
|
+
* @returns {Promise<object>} Send result
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
sendChunk(chunk: EventAttributes[], options: HarvestOptions, isLastChunk: boolean): Promise<{
|
|
95
|
+
success: boolean;
|
|
96
|
+
status: number;
|
|
97
|
+
error?: string;
|
|
98
|
+
chunk: EventAttributes[];
|
|
99
|
+
eventCount: number;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Handles request failure and implements failover logic for US region.
|
|
103
|
+
* @param {Array} chunk - Failed chunk to add to retry queue
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
handleRequestFailure(chunk: EventAttributes[]): void;
|
|
107
|
+
/**
|
|
108
|
+
* Handles harvest failure scenarios.
|
|
109
|
+
* @param {Error} error - Harvest error
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
handleHarvestFailure(error: Error): void;
|
|
113
|
+
/**
|
|
114
|
+
* Updates the harvest interval and restarts the scheduler to apply the new interval.
|
|
115
|
+
* @param {number} newInterval - The new harvest interval in milliseconds
|
|
116
|
+
* @returns {boolean} - True if interval was updated successfully, false otherwise
|
|
117
|
+
*/
|
|
118
|
+
updateHarvestInterval(newInterval: number): void;
|
|
119
|
+
/**
|
|
120
|
+
* Sets up page lifecycle event handlers.
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
setupPageLifecycleHandlers(): void;
|
|
124
|
+
}
|
|
125
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
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 "./harvestScheduler";
|
|
13
|
+
import { videoAnalyticsHarvester } from "./agent";
|
|
14
|
+
import { getRegisteredHarvester } from "../recordEvent";
|
|
15
|
+
import { recordEvent } from "../recordEvent";
|
|
16
|
+
import { version } from "../../package.json";
|
|
17
|
+
declare const nrvideo: {
|
|
18
|
+
Constants: typeof Constants;
|
|
19
|
+
Chrono: typeof Chrono;
|
|
20
|
+
Log: typeof Log;
|
|
21
|
+
Emitter: typeof Emitter;
|
|
22
|
+
Tracker: typeof Tracker;
|
|
23
|
+
VideoTracker: typeof VideoTracker;
|
|
24
|
+
VideoTrackerState: typeof VideoTrackerState;
|
|
25
|
+
Core: typeof Core;
|
|
26
|
+
version: string;
|
|
27
|
+
NrVideoEventAggregator: typeof NrVideoEventAggregator;
|
|
28
|
+
RetryQueueHandler: typeof RetryQueueHandler;
|
|
29
|
+
OptimizedHttpClient: typeof OptimizedHttpClient;
|
|
30
|
+
HarvestScheduler: typeof HarvestScheduler;
|
|
31
|
+
recordEvent: typeof recordEvent;
|
|
32
|
+
};
|
|
33
|
+
export { Core, Constants, Chrono, Log, Emitter, Tracker, VideoTracker, VideoTrackerState, NrVideoEventAggregator, RetryQueueHandler, OptimizedHttpClient, HarvestScheduler, videoAnalyticsHarvester, getRegisteredHarvester, recordEvent, version, };
|
|
34
|
+
export default nrvideo;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This class calculates time lapses between two points on time.
|
|
3
|
+
*/
|
|
4
|
+
declare class Chrono {
|
|
5
|
+
/** Start time */
|
|
6
|
+
startTime: number;
|
|
7
|
+
/** Stop time */
|
|
8
|
+
stopTime: number;
|
|
9
|
+
/** accumulation of all the start and stop intervals */
|
|
10
|
+
accumulator: number;
|
|
11
|
+
/**
|
|
12
|
+
* If you set an offset in a chrono, its value will be added getDeltaTime and stop.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* let chrono = new Chrono()
|
|
16
|
+
* chrono.offset = 500
|
|
17
|
+
* chrono.start()
|
|
18
|
+
* process.sleep(500)
|
|
19
|
+
* chrono.stop() // Will return 1000
|
|
20
|
+
*
|
|
21
|
+
* @type {number}
|
|
22
|
+
*/
|
|
23
|
+
offset: number;
|
|
24
|
+
/**
|
|
25
|
+
* Constructor
|
|
26
|
+
*/
|
|
27
|
+
constructor();
|
|
28
|
+
/** Reset chrono values. */
|
|
29
|
+
reset(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the time between start() and the last stop() in ms. Returns null if start wasn't
|
|
32
|
+
* called.
|
|
33
|
+
* @return {(number|null)} Time lapse in ms.
|
|
34
|
+
*/
|
|
35
|
+
getDeltaTime(): number | null;
|
|
36
|
+
/**
|
|
37
|
+
* Starts the chrono.
|
|
38
|
+
*/
|
|
39
|
+
start(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Stops the timer and returns delta time.
|
|
42
|
+
* @return {(number|null)} Returns the delta time
|
|
43
|
+
*/
|
|
44
|
+
stop(): number | null;
|
|
45
|
+
getDuration(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a copy of the chrono.
|
|
48
|
+
* @returns {Chrono} Cloned chrono
|
|
49
|
+
*/
|
|
50
|
+
clone(): Chrono;
|
|
51
|
+
}
|
|
52
|
+
export default Chrono;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import ConnectedDeviceHarvester from "./connectedDeviceHarvester";
|
|
2
|
+
import { EventAttributes, Harvester } from "../utils/eventBuilder";
|
|
3
|
+
/**
|
|
4
|
+
* Vega-side analytics agent. Mirror of `VideoAnalyticsAgent` in `agent.js`.
|
|
5
|
+
*/
|
|
6
|
+
declare class ConnectedDeviceAnalyticsAgent implements Harvester {
|
|
7
|
+
isInitialized: boolean;
|
|
8
|
+
harvester: ConnectedDeviceHarvester | null;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Lazy initialization. Reads `info` from `globalThis.__NRVIDEO_CD__` and
|
|
12
|
+
* constructs the wrapped `ConnectedDeviceHarvester`. If `info` is not yet populated,
|
|
13
|
+
* returns without flipping `isInitialized` so the next `addEvent` retries.
|
|
14
|
+
*/
|
|
15
|
+
initialize(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Buffers an event for the wrapped ConnectedDeviceHarvester. Triggers lazy init on
|
|
18
|
+
* the first call. Drops events silently if init has not yet succeeded
|
|
19
|
+
* (defensive — under normal flow, `setVideoConfig` runs synchronously
|
|
20
|
+
* inside `super()` before any player event can fire).
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* @param {object} eventObject
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
addEvent(eventObject: EventAttributes): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Forwards to the underlying ConnectedDeviceHarvester. No-op if not yet initialized.
|
|
29
|
+
* @see ConnectedDeviceHarvester#forceQoeNextHarvest
|
|
30
|
+
*/
|
|
31
|
+
forceQoeNextHarvest(): void;
|
|
32
|
+
/**
|
|
33
|
+
* API-parity alias for `forceQoeNextHarvest`. Lets `videotracker.js` call a
|
|
34
|
+
* single method name on whichever harvester `getHarvester()` returns —
|
|
35
|
+
* Browser exposes `forceNextQoeCycle`, Vega exposes both names.
|
|
36
|
+
*/
|
|
37
|
+
forceNextQoeCycle(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Forwards to the underlying ConnectedDeviceHarvester. No-op if not yet initialized.
|
|
40
|
+
* @see ConnectedDeviceHarvester#setBeforeDrainCallback
|
|
41
|
+
* @param {Function|null} cb
|
|
42
|
+
*/
|
|
43
|
+
setBeforeDrainCallback(cb: (() => void) | null): void;
|
|
44
|
+
/**
|
|
45
|
+
* Forwards to the underlying ConnectedDeviceHarvester. Triggers lazy init so
|
|
46
|
+
* `videotracker.js`'s drain callback (registered in sendStart) can refresh
|
|
47
|
+
* QoE on the buffered event before send.
|
|
48
|
+
*
|
|
49
|
+
* @param {object} freshKpis
|
|
50
|
+
* @param {string} [viewId]
|
|
51
|
+
*/
|
|
52
|
+
refreshQoeKpis(freshKpis: EventAttributes, viewId?: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Forwards to the underlying ConnectedDeviceHarvester. Triggers lazy init so
|
|
55
|
+
* `tracker.setHarvestInterval(...)` works for VegaTracker the same way it
|
|
56
|
+
* does for other trackers.
|
|
57
|
+
*
|
|
58
|
+
* @param {number} interval
|
|
59
|
+
*/
|
|
60
|
+
setHarvestInterval(interval: number): void;
|
|
61
|
+
}
|
|
62
|
+
export declare const connectedDeviceAnalyticsHarvester: ConnectedDeviceAnalyticsAgent;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type VegaEndpoint = "us" | "eu" | "staging" | "gov" | "jp";
|
|
2
|
+
/**
|
|
3
|
+
* Maps region key (lowercase) directly to the regional mobile collector base URL.
|
|
4
|
+
* Accepts global.region.key values: us, eu, gov, jp, staging.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ENDPOINT_URL: Record<VegaEndpoint, string>;
|
|
7
|
+
/** Default harvest cadence in ms. */
|
|
8
|
+
export declare const DEFAULT_HARVEST_TIME = 60000;
|
|
9
|
+
/** Default in-memory event-buffer cap (informational; aggregator enforces
|
|
10
|
+
* MAX_EVENTS_PER_BATCH / MAX_PAYLOAD_SIZE). */
|
|
11
|
+
export declare const DEFAULT_BUFFER_SIZE = 100;
|
|
12
|
+
/** Maximum number of /v5/connect attempts before giving up. */
|
|
13
|
+
export declare const CD_CONNECT_MAX_ATTEMPTS = 3;
|
|
14
|
+
/** Fixed delay between /v5/connect retry attempts in ms.
|
|
15
|
+
* 10s gives the device network stack enough time to recover after
|
|
16
|
+
* wake-from-sleep before the next attempt fires. */
|
|
17
|
+
export declare const CD_CONNECT_RETRY_DELAY_MS = 10000;
|
|
18
|
+
/** Hard timeout for POST /v5/connect. A hung connect holds _isFetchingToken=true
|
|
19
|
+
* forever, blocking all future reconnect attempts. */
|
|
20
|
+
export declare const CD_CONNECT_TIMEOUT_MS = 10000;
|
|
21
|
+
/** Hard timeout for POST /v3/data. A hung data send holds isHarvesting=true,
|
|
22
|
+
* freezing the chained harvest timer until the fetch resolves. */
|
|
23
|
+
export declare const CD_DATA_TIMEOUT_MS = 30000;
|
|
24
|
+
/**
|
|
25
|
+
* Positional 2-tuple sent as the body of `POST /v5/connect`.
|
|
26
|
+
* [
|
|
27
|
+
* appInfo[3] = [appName, appVersion, bundleId],
|
|
28
|
+
* deviceInfo[10] = [osName, osVersion, deviceModel, agentName,
|
|
29
|
+
* agentVersion, deviceUuid, "", "",
|
|
30
|
+
* manufacturer, sizeMeta]
|
|
31
|
+
* ]
|
|
32
|
+
*
|
|
33
|
+
* DATA_TOKENS_PAYLOAD shape — empty strings are rejected with a 401,
|
|
34
|
+
* every slot must carry a non-empty token. Uses `osName='Android'` +
|
|
35
|
+
* `agentName='AndroidAgent'` for collector auth; the real device identity
|
|
36
|
+
* is recorded in slot [1] / slot [8] of `/v3/data`.
|
|
37
|
+
*/
|
|
38
|
+
export declare const CD_DATA_TOKENS_PAYLOAD: any[];
|
|
39
|
+
/**
|
|
40
|
+
* Slot [1] of the `POST /v3/data` 10-tuple. Real device identity tuple
|
|
41
|
+
* (Vega + Amazon by default). Customer-supplied `info.deviceInfo` overrides
|
|
42
|
+
* the runtime fields; static slots (osName, agentName, etc.) stay fixed.
|
|
43
|
+
*/
|
|
44
|
+
export declare const CD_DEVICE_INFO: any[];
|
|
45
|
+
export declare const CD_METADATA: {
|
|
46
|
+
osBuild: string;
|
|
47
|
+
osName: string;
|
|
48
|
+
platform: string;
|
|
49
|
+
appBuild: string;
|
|
50
|
+
architecture: string;
|
|
51
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { NrVideoEventAggregator } from "../eventAggregator";
|
|
2
|
+
import { VegaEndpoint } from "./connectedDeviceConstants";
|
|
3
|
+
import { HarvestTimer } from "../utils/harvestTimer";
|
|
4
|
+
import { EventAttributes } from "../utils/eventBuilder";
|
|
5
|
+
export interface ConnectedDeviceHarvesterOptions {
|
|
6
|
+
accountId?: string;
|
|
7
|
+
applicationToken: string;
|
|
8
|
+
endpoint: string;
|
|
9
|
+
deviceInfo?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
interface DeviceInfo {
|
|
12
|
+
uuid: any;
|
|
13
|
+
osVersion: any;
|
|
14
|
+
deviceModel: any;
|
|
15
|
+
deviceManufacturer: any;
|
|
16
|
+
osBuild: any;
|
|
17
|
+
appBuild: any;
|
|
18
|
+
architecture: any;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generic NR mobile-collector harvester for the connected-device pipeline
|
|
22
|
+
* (`/v5/connect` + `/v3/data`).
|
|
23
|
+
*
|
|
24
|
+
* The class is **not Vega-specific** — it owns the HTTP client, dataToken,
|
|
25
|
+
* harvest setInterval, and event buffer for any consumer that needs to ship
|
|
26
|
+
* to NR's mobile collector. Vega-specific routing/lifecycle is provided by
|
|
27
|
+
* the wrapper `ConnectedDeviceAnalyticsAgent` in `connectedDeviceAgent.js`.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export default class ConnectedDeviceHarvester {
|
|
31
|
+
accountId?: string;
|
|
32
|
+
applicationToken: string;
|
|
33
|
+
endpoint: VegaEndpoint;
|
|
34
|
+
harvestInterval: number;
|
|
35
|
+
maxBufferSize: number;
|
|
36
|
+
deviceInfo: DeviceInfo;
|
|
37
|
+
eventBuffer: NrVideoEventAggregator;
|
|
38
|
+
dataToken: string | null;
|
|
39
|
+
isHarvesting: boolean;
|
|
40
|
+
isDisposed: boolean;
|
|
41
|
+
_isFetchingToken: boolean;
|
|
42
|
+
timer: HarvestTimer;
|
|
43
|
+
qoeCycleCount: number;
|
|
44
|
+
forceQoeNextCycle: boolean;
|
|
45
|
+
beforeDrainCallback: (() => void) | null;
|
|
46
|
+
_lastSentQoeKpis: Record<string, any>;
|
|
47
|
+
_connectAttempt: number;
|
|
48
|
+
/**
|
|
49
|
+
* @param {object} opts
|
|
50
|
+
* @param {string} [opts.accountId] Captured for parity with CAF; not transmitted.
|
|
51
|
+
* @param {string} opts.applicationToken Sent as `X-App-License-Key` header.
|
|
52
|
+
* @param {string} opts.endpoint One of `US`, `EU`, `staging`.
|
|
53
|
+
* @param {object} [opts.deviceInfo] Customer-collected device identity. Any of:
|
|
54
|
+
* uuid, osVersion, deviceModel, deviceManufacturer, osBuild, appBuild, architecture.
|
|
55
|
+
* Each field optional — missing values fall back to placeholders from
|
|
56
|
+
* `connectedDeviceConstants.js`. Extra fields are ignored. The customer is
|
|
57
|
+
* expected to source these from a platform device-info library (e.g.
|
|
58
|
+
* `@amazon-devices/react-native-device-info` on Kepler) and pass the
|
|
59
|
+
* resulting object once at construction. `osBuild` is the OS image build
|
|
60
|
+
* (e.g., `getBuildIdSync()`); `appBuild` is the consumer app's build
|
|
61
|
+
* number (e.g., `getBuildNumber()`).
|
|
62
|
+
*/
|
|
63
|
+
constructor({ accountId, applicationToken, endpoint, deviceInfo, }?: Partial<ConnectedDeviceHarvesterOptions>);
|
|
64
|
+
/**
|
|
65
|
+
* Returns the regional mobile collector base URL for the configured endpoint.
|
|
66
|
+
* Each region routes to its own datacenter — EU events terminate on EU
|
|
67
|
+
* infrastructure rather than transiting through the US host.
|
|
68
|
+
*
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
getEndpointBaseUrl(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Two-phase init: fetch dataToken, then start harvest interval.
|
|
74
|
+
* @returns {Promise<void>}
|
|
75
|
+
*/
|
|
76
|
+
initialise(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* POST `/v5/connect` to obtain a dataToken. Retries up to
|
|
79
|
+
* CD_CONNECT_MAX_ATTEMPTS times with a fixed CD_CONNECT_RETRY_DELAY_MS
|
|
80
|
+
* wait between attempts.
|
|
81
|
+
*
|
|
82
|
+
* Iterative loop keeps the call stack flat across all attempts.
|
|
83
|
+
* `_isFetchingToken` guard ensures only one connect sequence runs at a
|
|
84
|
+
* time — if `initialise()` (startup) and the 401-refresh path in
|
|
85
|
+
* `sendBufferedEvents` both call this concurrently, the second call
|
|
86
|
+
* returns immediately without issuing a duplicate POST.
|
|
87
|
+
*
|
|
88
|
+
* @returns {Promise<void>}
|
|
89
|
+
*/
|
|
90
|
+
fetchDataTokens(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Starts the periodic harvest timer.
|
|
93
|
+
* Idempotent — safe to call repeatedly.
|
|
94
|
+
*/
|
|
95
|
+
startHarvestInterval(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Smart-harvest handler. Invoked by `NrVideoEventAggregator` when the buffer
|
|
98
|
+
* crosses 60% (`type='smart'`) or 90% (`type='overflow'`) of capacity, before
|
|
99
|
+
* `makeRoom()` would start FIFO-evicting events. Drains the buffer immediately
|
|
100
|
+
* and resets the periodic clock so the next scheduled tick fires
|
|
101
|
+
* `harvestInterval` after this drain completes.
|
|
102
|
+
*
|
|
103
|
+
* @param {'smart'|'overflow'} type
|
|
104
|
+
* @param {number} threshold - The threshold percentage that triggered the harvest (60 or 90).
|
|
105
|
+
* @returns {Promise<void>}
|
|
106
|
+
*/
|
|
107
|
+
triggerSmartHarvest(type: string, threshold: number): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Buffers an event for the next harvest cycle.
|
|
110
|
+
*
|
|
111
|
+
* @param {object} eventObject
|
|
112
|
+
* @returns {boolean}
|
|
113
|
+
*/
|
|
114
|
+
addEvent(eventObject: EventAttributes): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Forces the next harvest cycle to ship QOE_AGGREGATE regardless of cycle
|
|
117
|
+
* multiplier or dirty check. Used at CONTENT_END for final QoE flush.
|
|
118
|
+
*/
|
|
119
|
+
forceQoeNextHarvest(): void;
|
|
120
|
+
/**
|
|
121
|
+
* Registers a callback invoked at the start of every send cycle, before
|
|
122
|
+
* the buffer is drained. Lets the tracker refresh QoE KPIs in the buffer
|
|
123
|
+
* before they ship.
|
|
124
|
+
* @param {Function|null} cb
|
|
125
|
+
*/
|
|
126
|
+
setBeforeDrainCallback(cb: (() => void) | null): void;
|
|
127
|
+
/**
|
|
128
|
+
* Updates QoE KPI fields on the existing QOE_AGGREGATE event in the buffer.
|
|
129
|
+
* Mirror of `VideoAnalyticsAgent#refreshQoeKpis` (`agent.js`) so VegaTracker's
|
|
130
|
+
* QoE drain wiring can route here through `getHarvester()`.
|
|
131
|
+
*
|
|
132
|
+
* @param {object} freshKpis - Object with latest KPI values
|
|
133
|
+
* @param {string} [viewId] - The viewId of the player whose QoE event to update
|
|
134
|
+
*/
|
|
135
|
+
refreshQoeKpis(freshKpis: EventAttributes, viewId?: string): void;
|
|
136
|
+
/**
|
|
137
|
+
* Updates the harvest cadence at runtime. If the periodic timer is already
|
|
138
|
+
* running, it is cleared and restarted with the new interval. Mirror of
|
|
139
|
+
* `VideoAnalyticsAgent#setHarvestInterval` (`agent.js`).
|
|
140
|
+
*
|
|
141
|
+
* @param {number} interval - New cadence in ms.
|
|
142
|
+
*/
|
|
143
|
+
setHarvestInterval(interval: number): void;
|
|
144
|
+
/**
|
|
145
|
+
* Drains the buffer and POSTs to `/v3/data`. Applies the QoE cycle filter
|
|
146
|
+
* and cross-cycle dirty check before send.
|
|
147
|
+
*
|
|
148
|
+
* Mirror of `harvestScheduler.js` drain + send logic, adapted for the CAF
|
|
149
|
+
* 10-tuple wire format and plain `fetch` transport.
|
|
150
|
+
*
|
|
151
|
+
*
|
|
152
|
+
* @returns {Promise<void>}
|
|
153
|
+
*/
|
|
154
|
+
sendBufferedEvents(): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Build slot [1] of /v3/data — the 10-element device-info tuple. Customer-
|
|
157
|
+
* supplied fields override the static defaults from CD_DEVICE_INFO; missing
|
|
158
|
+
* or empty fields fall through to the placeholders that ship in
|
|
159
|
+
* connectedDeviceConstants.js.
|
|
160
|
+
* @returns {Array}
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
_buildDeviceInfo(): any[];
|
|
164
|
+
/**
|
|
165
|
+
* Build slot [8] of /v3/data — the session-metadata object. Spreads the
|
|
166
|
+
* static `CD_METADATA` defaults (`osName`, `platform`, `appBuild`) and
|
|
167
|
+
* overrides only `osBuild` and `architecture` from the customer-supplied
|
|
168
|
+
* deviceInfo. Device-identity fields (osVersion, deviceModel,
|
|
169
|
+
* deviceManufacturer, osMajorVersion, platformVersion) live in slot [1]
|
|
170
|
+
* (`CD_DEVICE_INFO`) and are intentionally not duplicated here.
|
|
171
|
+
* @returns {object}
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
_buildMetadata(): Record<string, any>;
|
|
175
|
+
/**
|
|
176
|
+
* Wraps `fetch` with an AbortController deadline. If no response arrives
|
|
177
|
+
* within `timeoutMs`, the controller aborts the request and the returned
|
|
178
|
+
* Promise rejects with an AbortError. The caller's existing `catch` block
|
|
179
|
+
* handles it identically to any other network failure — connect retries for
|
|
180
|
+
* /v5/connect, event re-queue for /v3/data.
|
|
181
|
+
*
|
|
182
|
+
* `clearTimeout` in `.finally()` cancels the pending abort when the fetch
|
|
183
|
+
* completes before the deadline, so the abort never fires spuriously.
|
|
184
|
+
*
|
|
185
|
+
* @param {string} url
|
|
186
|
+
* @param {RequestInit} options
|
|
187
|
+
* @param {number} timeoutMs
|
|
188
|
+
* @returns {Promise<Response>}
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
_fetchWithTimeout(url: string, options: RequestInit, timeoutMs: number): Promise<Response>;
|
|
192
|
+
/**
|
|
193
|
+
* Stops the harvest interval and attempts one final best-effort send.
|
|
194
|
+
* @returns {Promise<void>}
|
|
195
|
+
*/
|
|
196
|
+
dispose(): Promise<void>;
|
|
197
|
+
}
|
|
198
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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 ConnectedDeviceHarvester from "./connectedDeviceHarvester";
|
|
11
|
+
import { connectedDeviceAnalyticsHarvester } from "./connectedDeviceAgent";
|
|
12
|
+
import { getRegisteredHarvester } from "../recordEvent";
|
|
13
|
+
import { recordEvent } from "../recordEvent";
|
|
14
|
+
import { version } from "../../package.json";
|
|
15
|
+
declare const nrvideo: {
|
|
16
|
+
Constants: typeof Constants;
|
|
17
|
+
Chrono: typeof Chrono;
|
|
18
|
+
Log: typeof Log;
|
|
19
|
+
Emitter: typeof Emitter;
|
|
20
|
+
Tracker: typeof Tracker;
|
|
21
|
+
VideoTracker: typeof VideoTracker;
|
|
22
|
+
VideoTrackerState: typeof VideoTrackerState;
|
|
23
|
+
Core: typeof Core;
|
|
24
|
+
version: string;
|
|
25
|
+
NrVideoEventAggregator: typeof NrVideoEventAggregator;
|
|
26
|
+
ConnectedDeviceHarvester: typeof ConnectedDeviceHarvester;
|
|
27
|
+
recordEvent: typeof recordEvent;
|
|
28
|
+
};
|
|
29
|
+
export { Core, Constants, Chrono, Log, Emitter, Tracker, VideoTracker, VideoTrackerState, NrVideoEventAggregator, ConnectedDeviceHarvester, connectedDeviceAnalyticsHarvester, getRegisteredHarvester, recordEvent, version, };
|
|
30
|
+
export default nrvideo;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for the library.
|
|
3
|
+
* @class Constants
|
|
4
|
+
* @static
|
|
5
|
+
*/
|
|
6
|
+
declare class Constants {
|
|
7
|
+
/**
|
|
8
|
+
* Enum for types/positions of ads.
|
|
9
|
+
* @example var type = Constants.AdPositions.PRE
|
|
10
|
+
* @enum {String}
|
|
11
|
+
*/
|
|
12
|
+
static AdPositions: {
|
|
13
|
+
/** For ads shown before the content. */
|
|
14
|
+
PRE: string;
|
|
15
|
+
/** For ads shown during the content. */
|
|
16
|
+
MID: string;
|
|
17
|
+
/** For ads shown after the content. */
|
|
18
|
+
POST: string;
|
|
19
|
+
};
|
|
20
|
+
static COLLECTOR: Record<string, string | string[]>;
|
|
21
|
+
static VALID_EVENT_TYPES: string[];
|
|
22
|
+
static MAX_PAYLOAD_SIZE: number;
|
|
23
|
+
static MAX_BEACON_SIZE: number;
|
|
24
|
+
static MAX_EVENTS_PER_BATCH: number;
|
|
25
|
+
static INTERVAL: number;
|
|
26
|
+
static DEFAULT_QOE_INTERVAL_FACTOR: number;
|
|
27
|
+
static QOE_KPI_KEYS: string[];
|
|
28
|
+
static QOE_AGGREGATE_KEYS: string[];
|
|
29
|
+
}
|
|
30
|
+
export default Constants;
|