@livepeer/core-web
Advanced tools
Comparing version 4.1.3 to 4.1.4
@@ -1,2 +0,2 @@ | ||
import { MediaControllerStore, DeviceInformation, MediaMetrics, Src } from '@livepeer/core/media'; | ||
import { MediaControllerStore, DeviceInformation, MediaMetrics, InitialProps, Src } from '@livepeer/core/media'; | ||
import { HlsConfig as HlsConfig$1 } from 'hls.js'; | ||
@@ -11,14 +11,25 @@ | ||
type MediaMetricsOptions = Pick<InitialProps, "onError" | "viewerId"> & { | ||
/** | ||
* Sets a custom source URL for playback, such as `https://livepeercdn.studio/hls/{playbackId}/index.m3u8`. | ||
* If not specified, the function defaults to using the `src` attribute of the HTMLMediaElement. | ||
* Note: For custom players that do not set the `src` attribute of the `video` element, opting instead for formats like `blob:<src>` or omitting `src` altogether, metrics collection may not function correctly. | ||
*/ | ||
src?: string; | ||
}; | ||
/** | ||
* Gather playback metrics from a generic HTML5 video/audio element and | ||
* report them to a websocket. Automatically handles a redirect to get the | ||
* metrics endpoint. | ||
* Initializes media playback metrics collection for a video or audio element. | ||
* This adds event listeners to the media element with a store that updates on events and send them to a websocket. | ||
* Returns a `destroy` function which must be called when the video element is removed from the DOM. | ||
* | ||
* @param element Element to capture playback metrics from. | ||
* @param sourceUrl Source URL for the player. | ||
* @param onError Callback when an error with metrics occurs. | ||
* @param opts Options for the metrics reporting. | ||
* @returns A callback for destroying the store and metrics. | ||
* @param {HTMLMediaElement | undefined | null} element The media element from which to capture playback metrics. | ||
* @param {Partial<MediaMetricsOptions>} opts Optional configuration options including: | ||
* - `src`: Overrides the `src` URL for playback - defaults to the `src` attribute of the HTMLMediaElement. Use this with custom players that do not set the `src` attribute of the `video` element. | ||
* - `onError`: A callback function that is called when an error occurs in the metrics collection process. | ||
* - `viewerId`: An identifier for the viewer to associate metrics with a specific user or session. | ||
* | ||
* @returns {MediaMetrics} An object containing a `destroy` function to clean up resources. | ||
* The `destroy` function must be used to remove event listeners and perform other cleanup actions on unmount. | ||
*/ | ||
declare function addMediaMetrics(element: HTMLMediaElement | undefined | null, onError?: (error: unknown) => void): MediaMetrics; | ||
declare function addMediaMetrics(element: HTMLMediaElement | undefined | null, opts?: Partial<MediaMetricsOptions>): MediaMetrics; | ||
@@ -25,0 +36,0 @@ /** |
@@ -1372,14 +1372,11 @@ // src/media/controls/controller.ts | ||
} from "@livepeer/core/media"; | ||
import { createStorage } from "@livepeer/core/storage"; | ||
import { createStorage, noopStorage } from "@livepeer/core/storage"; | ||
import { version } from "@livepeer/core/version"; | ||
function addMediaMetrics(element, onError) { | ||
function addMediaMetrics(element, opts = {}) { | ||
if (element) { | ||
const source = opts.src ?? element?.src ?? null; | ||
const { store, destroy } = createControllerStore({ | ||
src: element?.src ?? null, | ||
src: source, | ||
device: getDeviceInfo(version.core), | ||
storage: createStorage( | ||
typeof window !== "undefined" ? { | ||
storage: window.localStorage | ||
} : {} | ||
), | ||
storage: createStorage({ storage: noopStorage }), | ||
initialProps: { | ||
@@ -1389,5 +1386,6 @@ autoPlay: Boolean(element?.autoplay), | ||
preload: element?.preload === "" ? "auto" : element?.preload, | ||
viewerId: null, | ||
playbackRate: element?.playbackRate, | ||
onError | ||
hotkeys: false, | ||
posterLiveUpdate: 0, | ||
...opts | ||
} | ||
@@ -1397,2 +1395,3 @@ }); | ||
const { metrics, destroy: destroyMetrics } = addMediaMetricsToStore(store); | ||
store.getState().__controlsFunctions.onFinalUrl(source); | ||
return { | ||
@@ -1399,0 +1398,0 @@ metrics, |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "4.1.3", | ||
"version": "4.1.4", | ||
"type": "module", | ||
@@ -86,3 +86,3 @@ "repository": { | ||
"zustand": "^4.5.0", | ||
"@livepeer/core": "3.1.3" | ||
"@livepeer/core": "3.1.4" | ||
}, | ||
@@ -89,0 +89,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
734116
6547
+ Added@livepeer/core@3.1.4(transitive)
- Removed@livepeer/core@3.1.3(transitive)
Updated@livepeer/core@3.1.4