Skip to content

Commit

Permalink
fix: resolve issue with onError (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Apr 19, 2024
1 parent 36d95bb commit 8684ce1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 106 deletions.
8 changes: 8 additions & 0 deletions .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.
19 changes: 4 additions & 15 deletions packages/core-react/package.json
Expand Up @@ -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",
".": {
Expand All @@ -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": {
Expand All @@ -61,10 +55,5 @@
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"keywords": [
"livepeer",
"video",
"streaming",
"livestream"
]
"keywords": ["livepeer", "video", "streaming", "livestream"]
}
39 changes: 9 additions & 30 deletions packages/core-web/package.json
Expand Up @@ -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",
".": {
Expand Down Expand Up @@ -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": {
Expand All @@ -90,10 +74,5 @@
"hls.js": "^1.5.2",
"zustand": "^4.5.0"
},
"keywords": [
"livepeer",
"video",
"streaming",
"livestream"
]
"keywords": ["livepeer", "video", "streaming", "livestream"]
}
13 changes: 12 additions & 1 deletion packages/core-web/src/media/metrics.ts
@@ -1,14 +1,15 @@
import {
type InitialProps,
type MediaMetrics,
type PlaybackError,
addMediaMetricsToStore,
createControllerStore,
} from "@livepeer/core/media";
import { createStorage, noopStorage } from "@livepeer/core/storage";
import { version } from "@livepeer/core/version";
import { addEventListeners, getDeviceInfo } from "./controls";

export type MediaMetricsOptions = Pick<InitialProps, "onError" | "viewerId"> & {
export type MediaMetricsOptions = Pick<InitialProps, "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.
Expand All @@ -26,6 +27,11 @@ export type MediaMetricsOptions = Pick<InitialProps, "onError" | "viewerId"> & {
* 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;
};

/**
Expand Down Expand Up @@ -62,6 +68,11 @@ export function addMediaMetrics(
hotkeys: false,
posterLiveUpdate: 0,
...opts,
onError(error) {
if (error) {
opts?.onError?.(error);
}
},
},
});

Expand Down
39 changes: 9 additions & 30 deletions packages/core/package.json
Expand Up @@ -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",
".": {
Expand Down Expand Up @@ -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": {
Expand All @@ -92,10 +76,5 @@
"devDependencies": {
"jose": "^5.2.3"
},
"keywords": [
"livepeer",
"video",
"streaming",
"livestream"
]
"keywords": ["livepeer", "video", "streaming", "livestream"]
}
4 changes: 2 additions & 2 deletions 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,
Expand Down
36 changes: 8 additions & 28 deletions packages/react/package.json
Expand Up @@ -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",
".": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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"]
}

0 comments on commit 8684ce1

Please sign in to comment.