@livepeer/core-web
Advanced tools
Comparing version 4.2.0-next.4 to 4.2.0-next.5
import * as _livepeer_core_media from '@livepeer/core/media'; | ||
import { MediaControllerStore, DeviceInformation, InitialProps, Src } from '@livepeer/core/media'; | ||
import { MediaControllerStore, DeviceInformation, InitialProps, PlaybackError, Src } from '@livepeer/core/media'; | ||
import { HlsConfig as HlsConfig$1 } from 'hls.js'; | ||
@@ -12,3 +12,3 @@ | ||
type MediaMetricsOptions = Pick<InitialProps, "onError" | "viewerId"> & { | ||
type MediaMetricsOptions = Pick<InitialProps, "viewerId"> & { | ||
/** | ||
@@ -33,2 +33,6 @@ * Sets a custom source URL for playback, such as `https://livepeercdn.studio/hls/{playbackId}/index.m3u8`. | ||
interval?: number; | ||
/** | ||
* Callback called when there is an error. | ||
*/ | ||
onError?: ((error: PlaybackError) => any) | null | undefined; | ||
}; | ||
@@ -35,0 +39,0 @@ /** |
@@ -352,3 +352,6 @@ // src/media/controls/controller.ts | ||
}); | ||
peerConnection.ontrack = async (event) => { | ||
peerConnection.ontrack = (event) => { | ||
if (destroyed) { | ||
return; | ||
} | ||
try { | ||
@@ -385,19 +388,22 @@ if (stream) { | ||
}; | ||
peerConnection.addEventListener( | ||
"connectionstatechange", | ||
async (_ev) => { | ||
try { | ||
if (peerConnection?.connectionState === "failed") { | ||
throw new Error("Failed to connect to peer."); | ||
} | ||
if (peerConnection?.connectionState === "connected" && !element.srcObject) { | ||
element.srcObject = stream; | ||
callbacks?.onConnected?.(); | ||
} | ||
} catch (e) { | ||
errorComposed(e); | ||
peerConnection.addEventListener("connectionstatechange", (_ev) => { | ||
if (destroyed) { | ||
return; | ||
} | ||
try { | ||
if (peerConnection?.connectionState === "failed") { | ||
throw new Error("Failed to connect to peer."); | ||
} | ||
if (peerConnection?.connectionState === "connected" && !element.srcObject) { | ||
element.srcObject = stream; | ||
callbacks?.onConnected?.(); | ||
} | ||
} catch (e) { | ||
errorComposed(e); | ||
} | ||
); | ||
}); | ||
peerConnection.addEventListener("negotiationneeded", async (_ev) => { | ||
if (destroyed) { | ||
return; | ||
} | ||
try { | ||
@@ -408,2 +414,5 @@ const ofr = await constructClientOffer( | ||
); | ||
if (destroyed) { | ||
return; | ||
} | ||
const response = await negotiateConnectionWithClientOffer( | ||
@@ -417,2 +426,5 @@ peerConnection, | ||
); | ||
if (destroyed) { | ||
return; | ||
} | ||
const currentDate = Date.now(); | ||
@@ -434,6 +446,6 @@ if (response && currentDate) { | ||
abortController?.abort?.(); | ||
peerConnection?.close?.(); | ||
if (element) { | ||
element.srcObject = null; | ||
} | ||
peerConnection?.close?.(); | ||
element?.removeAttribute?.(VIDEO_WEBRTC_INITIALIZED_ATTRIBUTE); | ||
@@ -887,2 +899,3 @@ } | ||
element.addEventListener("play", onPlay); | ||
element.addEventListener("playing", onPlay); | ||
element.addEventListener("pause", onPause); | ||
@@ -934,2 +947,3 @@ element.addEventListener("durationchange", onDurationChange); | ||
element?.removeEventListener?.("play", onPlay); | ||
element?.removeEventListener?.("playing", onPlay); | ||
element?.removeEventListener?.("pause", onPause); | ||
@@ -1062,6 +1076,6 @@ element?.removeEventListener?.("durationchange", onDurationChange); | ||
cleanupSource = () => { | ||
unmounted = true; | ||
clearTimeout(id); | ||
unmounted = true; | ||
destroy?.(); | ||
unsubscribeBframes?.(); | ||
destroy?.(); | ||
}; | ||
@@ -1142,3 +1156,9 @@ return; | ||
{ | ||
equalityFn: (a, b) => a.errorCount === b.errorCount && a.source?.src === b.source?.src && a.mounted === b.mounted | ||
equalityFn: (a, b) => { | ||
const errorCountChanged = a.errorCount !== b.errorCount && b.errorCount !== 0; | ||
const sourceChanged = a.source?.src !== b.source?.src; | ||
const mountedChanged = a.mounted !== b.mounted; | ||
const shouldReRender = errorCountChanged || sourceChanged || mountedChanged; | ||
return !shouldReRender; | ||
} | ||
} | ||
@@ -1399,3 +1419,8 @@ ); | ||
posterLiveUpdate: 0, | ||
...opts | ||
...opts, | ||
onError(error) { | ||
if (error) { | ||
opts?.onError?.(error); | ||
} | ||
} | ||
} | ||
@@ -1402,0 +1427,0 @@ }); |
@@ -25,8 +25,8 @@ import { ErrorData, HlsConfig } from 'hls.js'; | ||
callbacks: { | ||
onLive?: ((v: boolean) => void) | undefined; | ||
onPlaybackOffsetUpdated?: ((d: number) => void) | undefined; | ||
onDuration?: ((v: number) => void) | undefined; | ||
onCanPlay?: (() => void) | undefined; | ||
onError?: ((data: HlsError) => void) | undefined; | ||
onRedirect?: ((url: string | null) => void) | undefined; | ||
onLive?: (v: boolean) => void; | ||
onPlaybackOffsetUpdated?: (d: number) => void; | ||
onDuration?: (v: number) => void; | ||
onCanPlay?: () => void; | ||
onError?: (data: HlsError) => void; | ||
onRedirect?: (url: string | null) => void; | ||
}; | ||
@@ -33,0 +33,0 @@ config: HlsVideoConfig; |
@@ -12,6 +12,6 @@ import { AccessControlParams } from '@livepeer/core/media'; | ||
callbacks: { | ||
onConnected?: (() => void) | undefined; | ||
onPlaybackOffsetUpdated?: ((d: number) => void) | undefined; | ||
onError?: ((data: Error) => void) | undefined; | ||
onRedirect?: ((url: string | null) => void) | undefined; | ||
onConnected?: () => void; | ||
onPlaybackOffsetUpdated?: (d: number) => void; | ||
onError?: (data: Error) => void; | ||
onRedirect?: (url: string | null) => void; | ||
}; | ||
@@ -38,5 +38,5 @@ accessControl: AccessControlParams; | ||
callbacks: { | ||
onRTCPeerConnection?: ((payload: RTCPeerConnection) => void) | undefined; | ||
onConnected?: (() => void) | undefined; | ||
onError?: ((data: Error) => void) | undefined; | ||
onRTCPeerConnection?: (payload: RTCPeerConnection) => void; | ||
onConnected?: () => void; | ||
onError?: (data: Error) => void; | ||
}; | ||
@@ -43,0 +43,0 @@ sdpTimeout: number | null; |
@@ -191,3 +191,6 @@ // src/webrtc/shared.ts | ||
}); | ||
peerConnection.ontrack = async (event) => { | ||
peerConnection.ontrack = (event) => { | ||
if (destroyed) { | ||
return; | ||
} | ||
try { | ||
@@ -224,19 +227,22 @@ if (stream) { | ||
}; | ||
peerConnection.addEventListener( | ||
"connectionstatechange", | ||
async (_ev) => { | ||
try { | ||
if (peerConnection?.connectionState === "failed") { | ||
throw new Error("Failed to connect to peer."); | ||
} | ||
if (peerConnection?.connectionState === "connected" && !element.srcObject) { | ||
element.srcObject = stream; | ||
callbacks?.onConnected?.(); | ||
} | ||
} catch (e) { | ||
errorComposed(e); | ||
peerConnection.addEventListener("connectionstatechange", (_ev) => { | ||
if (destroyed) { | ||
return; | ||
} | ||
try { | ||
if (peerConnection?.connectionState === "failed") { | ||
throw new Error("Failed to connect to peer."); | ||
} | ||
if (peerConnection?.connectionState === "connected" && !element.srcObject) { | ||
element.srcObject = stream; | ||
callbacks?.onConnected?.(); | ||
} | ||
} catch (e) { | ||
errorComposed(e); | ||
} | ||
); | ||
}); | ||
peerConnection.addEventListener("negotiationneeded", async (_ev) => { | ||
if (destroyed) { | ||
return; | ||
} | ||
try { | ||
@@ -247,2 +253,5 @@ const ofr = await constructClientOffer( | ||
); | ||
if (destroyed) { | ||
return; | ||
} | ||
const response = await negotiateConnectionWithClientOffer( | ||
@@ -256,2 +265,5 @@ peerConnection, | ||
); | ||
if (destroyed) { | ||
return; | ||
} | ||
const currentDate = Date.now(); | ||
@@ -273,6 +285,6 @@ if (response && currentDate) { | ||
abortController?.abort?.(); | ||
peerConnection?.close?.(); | ||
if (element) { | ||
element.srcObject = null; | ||
} | ||
peerConnection?.close?.(); | ||
element?.removeAttribute?.(VIDEO_WEBRTC_INITIALIZED_ATTRIBUTE); | ||
@@ -279,0 +291,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "4.2.0-next.4", | ||
"version": "4.2.0-next.5", | ||
"type": "module", | ||
@@ -84,5 +84,5 @@ "repository": { | ||
"dependencies": { | ||
"hls.js": "^1.5.2", | ||
"zustand": "^4.5.0", | ||
"@livepeer/core": "3.2.0-next.4" | ||
"hls.js": "^1.5.8", | ||
"zustand": "^4.5.2", | ||
"@livepeer/core": "3.2.0-next.5" | ||
}, | ||
@@ -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
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
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
752881
6709
+ Added@livepeer/core@3.2.0-next.5(transitive)
- Removed@livepeer/core@3.2.0-next.4(transitive)
Updated@livepeer/core@3.2.0-next.5
Updatedhls.js@^1.5.8
Updatedzustand@^4.5.2