From 8684ce1ad8ba8afeaadaa394e71306f697c13311 Mon Sep 17 00:00:00 2001 From: Chase Adams Date: Fri, 19 Apr 2024 11:07:11 -0700 Subject: [PATCH] fix: resolve issue with onError (#535) --- .changeset/neat-wasps-fold.md | 8 ++++++ packages/core-react/package.json | 19 +++---------- packages/core-web/package.json | 39 ++++++-------------------- packages/core-web/src/media/metrics.ts | 13 ++++++++- packages/core/package.json | 39 ++++++-------------------- packages/core/src/version.ts | 4 +-- packages/react/package.json | 36 ++++++------------------ 7 files changed, 52 insertions(+), 106 deletions(-) create mode 100644 .changeset/neat-wasps-fold.md diff --git a/.changeset/neat-wasps-fold.md b/.changeset/neat-wasps-fold.md new file mode 100644 index 00000000..f4c0e311 --- /dev/null +++ b/.changeset/neat-wasps-fold.md @@ -0,0 +1,8 @@ +--- +"@livepeer/core-react": patch +"@livepeer/core-web": patch +"@livepeer/react": patch +"@livepeer/core": patch +--- + +**Fix:** fixed an issue where `onError` gets called with `null` in the `addMediaMetrics` plugin, when there is no error. diff --git a/packages/core-react/package.json b/packages/core-react/package.json index b5b2409d..1db9124f 100644 --- a/packages/core-react/package.json +++ b/packages/core-react/package.json @@ -13,9 +13,7 @@ "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", - "files": [ - "dist" - ], + "files": ["dist"], "exports": { "./package.json": "./package.json", ".": { @@ -31,12 +29,8 @@ }, "typesVersions": { "*": { - "crypto": [ - "./dist/crypto/index.d.ts" - ], - "*": [ - "./dist/index.d.ts" - ] + "crypto": ["./dist/crypto/index.d.ts"], + "*": ["./dist/index.d.ts"] } }, "scripts": { @@ -61,10 +55,5 @@ "react": "^18.2.0", "react-dom": "^18.2.0" }, - "keywords": [ - "livepeer", - "video", - "streaming", - "livestream" - ] + "keywords": ["livepeer", "video", "streaming", "livestream"] } diff --git a/packages/core-web/package.json b/packages/core-web/package.json index d2efbb93..52b23275 100644 --- a/packages/core-web/package.json +++ b/packages/core-web/package.json @@ -13,9 +13,7 @@ "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", - "files": [ - "dist" - ], + "files": ["dist"], "exports": { "./package.json": "./package.json", ".": { @@ -56,27 +54,13 @@ }, "typesVersions": { "*": { - "broadcast": [ - "./dist/broadcast/index.d.ts" - ], - "browser": [ - "./dist/browser/index.d.ts" - ], - "external": [ - "./dist/external/index.d.ts" - ], - "hls": [ - "./dist/hls/index.d.ts" - ], - "media": [ - "./dist/media/index.d.ts" - ], - "webrtc": [ - "./dist/webrtc/index.d.ts" - ], - "*": [ - "./dist/index.d.ts" - ] + "broadcast": ["./dist/broadcast/index.d.ts"], + "browser": ["./dist/browser/index.d.ts"], + "external": ["./dist/external/index.d.ts"], + "hls": ["./dist/hls/index.d.ts"], + "media": ["./dist/media/index.d.ts"], + "webrtc": ["./dist/webrtc/index.d.ts"], + "*": ["./dist/index.d.ts"] } }, "scripts": { @@ -90,10 +74,5 @@ "hls.js": "^1.5.2", "zustand": "^4.5.0" }, - "keywords": [ - "livepeer", - "video", - "streaming", - "livestream" - ] + "keywords": ["livepeer", "video", "streaming", "livestream"] } diff --git a/packages/core-web/src/media/metrics.ts b/packages/core-web/src/media/metrics.ts index 5500dfa0..f78b3a70 100644 --- a/packages/core-web/src/media/metrics.ts +++ b/packages/core-web/src/media/metrics.ts @@ -1,6 +1,7 @@ import { type InitialProps, type MediaMetrics, + type PlaybackError, addMediaMetricsToStore, createControllerStore, } from "@livepeer/core/media"; @@ -8,7 +9,7 @@ import { createStorage, noopStorage } from "@livepeer/core/storage"; import { version } from "@livepeer/core/version"; import { addEventListeners, getDeviceInfo } from "./controls"; -export type MediaMetricsOptions = Pick & { +export type MediaMetricsOptions = Pick & { /** * 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. @@ -26,6 +27,11 @@ export type MediaMetricsOptions = Pick & { * Disables the `progress` event listener, which is used to monitor when media is in a "playing" state. */ disableProgressListener?: boolean; + + /** + * Callback called when there is an error. + */ + onError?: ((error: PlaybackError) => any) | null | undefined; }; /** @@ -62,6 +68,11 @@ export function addMediaMetrics( hotkeys: false, posterLiveUpdate: 0, ...opts, + onError(error) { + if (error) { + opts?.onError?.(error); + } + }, }, }); diff --git a/packages/core/package.json b/packages/core/package.json index bb7fb354..6edbca1d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,9 +13,7 @@ "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", - "files": [ - "dist" - ], + "files": ["dist"], "exports": { "./package.json": "./package.json", ".": { @@ -56,27 +54,13 @@ }, "typesVersions": { "*": { - "crypto": [ - "./dist/crypto/index.d.ts" - ], - "errors": [ - "./dist/errors/index.d.ts" - ], - "media": [ - "./dist/media/index.d.ts" - ], - "storage": [ - "./dist/storage/index.d.ts" - ], - "utils": [ - "./dist/utils/index.d.ts" - ], - "version": [ - "./dist/version/index.d.ts" - ], - "*": [ - "./dist/index.d.ts" - ] + "crypto": ["./dist/crypto/index.d.ts"], + "errors": ["./dist/errors/index.d.ts"], + "media": ["./dist/media/index.d.ts"], + "storage": ["./dist/storage/index.d.ts"], + "utils": ["./dist/utils/index.d.ts"], + "version": ["./dist/version/index.d.ts"], + "*": ["./dist/index.d.ts"] } }, "scripts": { @@ -92,10 +76,5 @@ "devDependencies": { "jose": "^5.2.3" }, - "keywords": [ - "livepeer", - "video", - "streaming", - "livestream" - ] + "keywords": ["livepeer", "video", "streaming", "livestream"] } diff --git a/packages/core/src/version.ts b/packages/core/src/version.ts index 9550753f..33a589c1 100644 --- a/packages/core/src/version.ts +++ b/packages/core/src/version.ts @@ -1,5 +1,5 @@ -const core = "@livepeer/core@3.1.15"; -const react = "@livepeer/react@4.1.15"; +const core = "@livepeer/core@3.1.16"; +const react = "@livepeer/react@4.1.16"; export const version = { core, diff --git a/packages/react/package.json b/packages/react/package.json index bae4cfac..9388c81a 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -13,9 +13,7 @@ "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", - "files": [ - "dist" - ], + "files": ["dist"], "exports": { "./package.json": "./package.json", ".": { @@ -51,24 +49,12 @@ }, "typesVersions": { "*": { - "assets": [ - "./dist/assets/index.d.ts" - ], - "broadcast": [ - "./dist/broadcast/index.d.ts" - ], - "crypto": [ - "./dist/crypto/index.d.ts" - ], - "external": [ - "./dist/external/index.d.ts" - ], - "player": [ - "./dist/player/index.d.ts" - ], - "*": [ - "./dist/index.d.ts" - ] + "assets": ["./dist/assets/index.d.ts"], + "broadcast": ["./dist/broadcast/index.d.ts"], + "crypto": ["./dist/crypto/index.d.ts"], + "external": ["./dist/external/index.d.ts"], + "player": ["./dist/player/index.d.ts"], + "*": ["./dist/index.d.ts"] } }, "scripts": { @@ -114,11 +100,5 @@ "react": "^18.2.0", "react-dom": "^18.2.0" }, - "keywords": [ - "livepeer", - "react", - "video", - "streaming", - "livestream" - ] + "keywords": ["livepeer", "react", "video", "streaming", "livestream"] }