diff --git a/src/index.ts b/src/index.ts index e0e4000..89c10f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,5 +8,10 @@ export { disableDebug, AudioProxyDebugger, } from './debugger'; +export { + AudioProxyServer, + createProxyServer, + startProxyServer, +} from './server-impl'; export * from './types'; export { createAudioClient } from './client'; diff --git a/src/react.ts b/src/react.ts index 693c6b8..f905b9c 100644 --- a/src/react.ts +++ b/src/react.ts @@ -313,6 +313,30 @@ export function useAudioMetadata(filePath: string | null) { }; } +/** + * Simple hook for getting a playable/proxied URL for audio or video + */ +export function useAudioUrl(url: string | null, options?: AudioProxyOptions) { + const { audioUrl, isLoading, error, streamInfo, retry, client } = + useAudioProxy(url, options); + + const normalizedError = useMemo(() => { + if (!error) { + return null; + } + return new Error(error); + }, [error]); + + return { + playableUrl: audioUrl, + loading: isLoading, + error: normalizedError, + streamInfo, + retry, + client, + }; +} + /** * Context provider for global audio proxy configuration */