@behindthemusictree/app-kit 0.0.0-stage → 24.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/dist/app-error-B8IoFBhD.d.ts +45 -0
- package/dist/app-error-codes-D5eYg7xR.d.ts +49 -0
- package/dist/auth/index.cjs +479 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.ts +83 -0
- package/dist/auth/index.js +36 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/chunk-4MEK3CNF.js +246 -0
- package/dist/chunk-4MEK3CNF.js.map +1 -0
- package/dist/chunk-5NTNMBJP.js +25 -0
- package/dist/chunk-5NTNMBJP.js.map +1 -0
- package/dist/chunk-5YLNSX34.js +211 -0
- package/dist/chunk-5YLNSX34.js.map +1 -0
- package/dist/chunk-7EOS2K24.js +267 -0
- package/dist/chunk-7EOS2K24.js.map +1 -0
- package/dist/chunk-FYOLIMWU.js +25 -0
- package/dist/chunk-FYOLIMWU.js.map +1 -0
- package/dist/chunk-JMFEWI53.js +10 -0
- package/dist/chunk-JMFEWI53.js.map +1 -0
- package/dist/chunk-OGTDTTHJ.js +244 -0
- package/dist/chunk-OGTDTTHJ.js.map +1 -0
- package/dist/chunk-OIZPAN6I.js +356 -0
- package/dist/chunk-OIZPAN6I.js.map +1 -0
- package/dist/chunk-T5D5T52J.js +271 -0
- package/dist/chunk-T5D5T52J.js.map +1 -0
- package/dist/chunk-TCXWV62L.js +1 -0
- package/dist/chunk-TCXWV62L.js.map +1 -0
- package/dist/chunk-Y52MKNHR.js +1461 -0
- package/dist/chunk-Y52MKNHR.js.map +1 -0
- package/dist/genre-tree/index.cjs +2133 -0
- package/dist/genre-tree/index.cjs.map +1 -0
- package/dist/genre-tree/index.d.ts +3031 -0
- package/dist/genre-tree/index.js +179 -0
- package/dist/genre-tree/index.js.map +1 -0
- package/dist/genre-tree/testing.cjs +55 -0
- package/dist/genre-tree/testing.cjs.map +1 -0
- package/dist/genre-tree/testing.d.ts +7 -0
- package/dist/genre-tree/testing.js +27 -0
- package/dist/genre-tree/testing.js.map +1 -0
- package/dist/ids-D8XCErUS.d.ts +8 -0
- package/dist/index.cjs +3194 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +308 -0
- package/dist/index.js.map +1 -0
- package/dist/player/index.cjs +388 -0
- package/dist/player/index.cjs.map +1 -0
- package/dist/player/index.d.ts +108 -0
- package/dist/player/index.js +20 -0
- package/dist/player/index.js.map +1 -0
- package/dist/popup/index.cjs +403 -0
- package/dist/popup/index.cjs.map +1 -0
- package/dist/popup/index.d.ts +80 -0
- package/dist/popup/index.js +16 -0
- package/dist/popup/index.js.map +1 -0
- package/dist/scope-BoMVOHmz.d.ts +4 -0
- package/dist/track-noun/index.cjs +53 -0
- package/dist/track-noun/index.cjs.map +1 -0
- package/dist/track-noun/index.d.ts +15 -0
- package/dist/track-noun/index.js +11 -0
- package/dist/track-noun/index.js.map +1 -0
- package/dist/transport/index.cjs +773 -0
- package/dist/transport/index.cjs.map +1 -0
- package/dist/transport/index.d.ts +203 -0
- package/dist/transport/index.js +69 -0
- package/dist/transport/index.js.map +1 -0
- package/package.json +97 -4
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/player/index.ts","../../src/player/PlayStates.ts","../../src/player/PlayerContext.tsx","../../src/player/MediaController.ts","../../src/player/youtubeIframeApi.ts"],"sourcesContent":["export * from \"./PlayStates\";\nexport * from \"./PlayerContext\";\nexport * from \"./MediaController\";\n","export enum PlayStates {\n PLAYING = \"PLAYING\",\n PAUSED = \"PAUSED\",\n STOPPED = \"STOPPED\",\n LOADING = \"LOADING\",\n}\n","\"use client\";\n\n/**\n * Generalized from grow-the-music-tree-frontend's original `PlayerContext.tsx`, which was\n * hard-typed to `UploadedTrackDetailed` and imported grow's `useDownloadTrack`/\n * `useListUploadedTracks` data hooks directly. This version works with a generic `PlayerTrack`\n * shape and an injected async `loadTrack` loader, so both grow's and hear's uploaded-track\n * libraries (or any other track source) can drive it without this package depending on either\n * app's data-fetching hooks or domain types.\n *\n * Playback mechanics (play/pause, volume, duration, `currentTimeRef`) are unchanged from the\n * original. What changed: the \"how do we get from a track id to playable audio\" step is now the\n * caller's responsibility (`loadTrack`), and `loadTrackForPlayer` takes just a track id instead of\n * a full track object + scope — so a track's title/artists are only known once `loadTrack`\n * resolves, not immediately when playback starts (a deliberate simplification; the original showed\n * the track's title while its audio was still downloading).\n *\n * `PlayerTrack` is a discriminated union on `kind`: `\"audio\"` tracks play through a real\n * `HTMLAudioElement`, `\"youtube\"` tracks play through a YouTube IFrame player mounted into the\n * `PlayerVideoSurface` component. Both are driven through the same `MediaController` interface so\n * play/pause/seek/volume code never needs to branch on track kind.\n */\n\nimport { createContext, useContext, useState, ReactNode, useRef, useEffect, useCallback, useMemo } from \"react\";\nimport { PlayStates } from \"./PlayStates\";\nimport { MediaController, AudioMediaController, YoutubeMediaController } from \"./MediaController\";\nimport { loadYoutubeIframeApi } from \"./youtubeIframeApi\";\n\nexport interface PlayerTrackArtist {\n /** Lets consumers link the artist (e.g. to an artist page); absent for sources without artist ids. */\n uuid?: string;\n name: string;\n}\n\ninterface PlayerTrackBase {\n id: string;\n title: string;\n artists?: PlayerTrackArtist[];\n}\n\nexport interface AudioPlayerTrack extends PlayerTrackBase {\n kind: \"audio\";\n streamUrl: string;\n}\n\nexport interface YoutubePlayerTrack extends PlayerTrackBase {\n kind: \"youtube\";\n youtubeVideoId: string;\n /** Set when the video can't be embedded/played; next/previous navigation skips the track. */\n unplayableReason?: string | null;\n}\n\n/** Minimal shape the player needs to play a track and identify it. Extend as needed per app. */\nexport type PlayerTrack = AudioPlayerTrack | YoutubePlayerTrack;\n\nconst isPlayable = (track: PlayerTrack) => track.kind !== \"youtube\" || !track.unplayableReason;\n\nfunction youtubeErrorMessage(code: number): string {\n if (code === 100) return \"Video not found\";\n if (code === 101 || code === 150) return \"Embedding disabled by the video owner\";\n return `YouTube playback error (code ${code})`;\n}\n\ninterface PlayerTrackObject {\n track: PlayerTrack;\n mediaController?: MediaController;\n isReady: boolean;\n loadError?: string;\n}\n\ninterface PlayerContextType {\n playerTrackObject: PlayerTrackObject | null;\n isPlaying: boolean;\n setIsPlaying: (isPlaying: boolean) => void;\n currentTimeRef: React.MutableRefObject<number>;\n duration: number;\n setDuration: (duration: number) => void;\n volume: number;\n setVolume: (volume: number) => void;\n playState: PlayStates;\n setPlayState: (state: PlayStates) => void;\n handlePlayPauseAction: () => void;\n loadTrackForPlayer: (trackId: string) => void;\n isLoading: boolean;\n handleNextTrack: (\n trackList: PlayerTrack[],\n currentTrack: PlayerTrack,\n onTrackChange: (track: PlayerTrack) => void,\n ) => void;\n handlePreviousTrack: (\n trackList: PlayerTrack[],\n currentTrack: PlayerTrack,\n onTrackChange: (track: PlayerTrack) => void,\n ) => void;\n onTrackEnd: (() => void) | null;\n setOnTrackEnd: (callback: (() => void) | null) => void;\n /** Container the YouTube IFrame player mounts into. Render `<PlayerVideoSurface />` to attach it. */\n videoContainerRef: React.RefObject<HTMLDivElement>;\n}\n\nconst PlayerContext = createContext<PlayerContextType | undefined>(undefined);\n\ninterface PlayerProviderProps {\n children: ReactNode;\n /** Resolves a track id to a playable `PlayerTrack`. */\n loadTrack: (trackId: string) => Promise<PlayerTrack>;\n}\n\nexport function PlayerProvider({ children, loadTrack }: PlayerProviderProps) {\n const [playerTrackObject, setPlayerTrackObject] = useState<PlayerTrackObject | null>(null);\n const [isPlaying, setIsPlaying] = useState(false);\n const [duration, setDuration] = useState(0);\n const [volume, setVolume] = useState(50);\n const [playState, setPlayState] = useState<PlayStates>(PlayStates.STOPPED);\n const [isLoading, setIsLoading] = useState(false);\n const [onTrackEnd, setOnTrackEnd] = useState<(() => void) | null>(null);\n const audioElementRef = useRef<HTMLAudioElement | null>(null);\n const youtubePlayerRef = useRef<YT.Player | null>(null);\n const videoContainerRef = useRef<HTMLDivElement>(null);\n const currentTimeRef = useRef(0);\n const onTrackEndRef = useRef(onTrackEnd);\n useEffect(() => {\n onTrackEndRef.current = onTrackEnd;\n }, [onTrackEnd]);\n\n // Kick off the YouTube IFrame API script fetch as soon as the provider mounts, rather than on\n // the first youtube-track play click — that first click otherwise pays for both the script\n // fetch and the player iframe boot back-to-back, which is what makes it visibly slow.\n useEffect(() => {\n loadYoutubeIframeApi().catch(() => {\n // Swallowed: loadYoutubeTrack retries the same call and surfaces the error there.\n });\n }, []);\n\n // YouTube's IFrame API has no continuous timeupdate-style event, so poll it into the same\n // currentTimeRef audio tracks update via their \"timeupdate\" listener. Also doubles as the\n // duration source, since a video's duration isn't reliably known right after loadVideoById.\n useEffect(() => {\n const interval = setInterval(() => {\n const player = youtubePlayerRef.current;\n if (player) {\n currentTimeRef.current = player.getCurrentTime();\n setDuration(player.getDuration());\n }\n }, 250);\n return () => clearInterval(interval);\n }, []);\n\n const handleYoutubeStateChange = useCallback((event: YT.OnStateChangeEvent) => {\n if (event.data === window.YT.PlayerState.ENDED) {\n setPlayState(PlayStates.STOPPED);\n setIsPlaying(false);\n onTrackEndRef.current?.();\n }\n }, []);\n\n const loadAudioTrack = useCallback(\n (track: AudioPlayerTrack) => {\n const audio = new Audio(track.streamUrl);\n audio.volume = volume / 100;\n audioElementRef.current = audio;\n\n audio.addEventListener(\"loadedmetadata\", () => {\n setDuration(audio.duration);\n });\n\n audio.addEventListener(\"timeupdate\", () => {\n // Only update ref - no state updates to prevent re-renders\n currentTimeRef.current = audio.currentTime;\n });\n\n audio.addEventListener(\"ended\", () => {\n setPlayState(PlayStates.STOPPED);\n setIsPlaying(false);\n onTrackEndRef.current?.();\n });\n\n audio.addEventListener(\"error\", (e) => {\n console.error(\"Audio error event fired:\", e);\n });\n\n setPlayerTrackObject({ track, mediaController: new AudioMediaController(audio), isReady: true, loadError: undefined });\n setPlayState(PlayStates.PLAYING);\n setIsPlaying(true);\n audio.play().catch((error) => {\n console.error(\"Error auto-playing audio:\", error);\n });\n },\n [volume],\n );\n\n const loadYoutubeTrack = useCallback(\n async (track: YoutubePlayerTrack) => {\n if (youtubePlayerRef.current) {\n const player = youtubePlayerRef.current;\n player.loadVideoById(track.youtubeVideoId);\n setPlayerTrackObject({ track, mediaController: new YoutubeMediaController(player), isReady: true, loadError: undefined });\n setPlayState(PlayStates.PLAYING);\n setIsPlaying(true);\n player.playVideo();\n return;\n }\n\n const container = videoContainerRef.current;\n if (!container) {\n throw new Error(\"PlayerVideoSurface must be rendered before a YouTube track can be loaded\");\n }\n\n const YT = await loadYoutubeIframeApi();\n\n await new Promise<void>((resolve) => {\n const player = new YT.Player(container, {\n videoId: track.youtubeVideoId,\n playerVars: { autoplay: 1 },\n events: {\n onReady: () => {\n youtubePlayerRef.current = player;\n setPlayerTrackObject({ track, mediaController: new YoutubeMediaController(player), isReady: true, loadError: undefined });\n setPlayState(PlayStates.PLAYING);\n setIsPlaying(true);\n player.playVideo();\n resolve();\n },\n onStateChange: handleYoutubeStateChange,\n onError: (event: YT.OnErrorEvent) => {\n const loadError = youtubeErrorMessage(event.data);\n setPlayerTrackObject((prev) => (prev ? { ...prev, loadError } : prev));\n setPlayState(PlayStates.STOPPED);\n setIsPlaying(false);\n onTrackEndRef.current?.();\n },\n },\n });\n });\n },\n [handleYoutubeStateChange],\n );\n\n const loadTrackForPlayer = useCallback(\n (trackId: string) => {\n if (audioElementRef.current) {\n audioElementRef.current.pause();\n audioElementRef.current.currentTime = 0;\n audioElementRef.current = null;\n }\n if (youtubePlayerRef.current) {\n youtubePlayerRef.current.pauseVideo();\n }\n\n setPlayerTrackObject(null);\n setIsLoading(true);\n setPlayState(PlayStates.LOADING);\n\n loadTrack(trackId)\n .then((track) => (track.kind === \"youtube\" ? loadYoutubeTrack(track) : loadAudioTrack(track)))\n .catch((error) => {\n console.error(\"Error loading track:\", error);\n setPlayState(PlayStates.STOPPED);\n setPlayerTrackObject({\n track: { id: trackId, kind: \"audio\", streamUrl: \"\", title: \"\" },\n isReady: false,\n loadError: error?.message ?? \"Failed to load track\",\n });\n })\n .finally(() => {\n setIsLoading(false);\n });\n },\n [loadTrack, loadAudioTrack, loadYoutubeTrack],\n );\n\n const handleNextTrack = useCallback(\n (trackList: PlayerTrack[], currentTrack: PlayerTrack, onTrackChange: (track: PlayerTrack) => void) => {\n if (!trackList || !currentTrack) return;\n\n const currentIndex = trackList.findIndex((track) => track.id === currentTrack.id);\n if (currentIndex === -1) return;\n\n const nextTrack = trackList.slice(currentIndex + 1).find(isPlayable);\n if (nextTrack) {\n onTrackChange(nextTrack);\n loadTrackForPlayer(nextTrack.id);\n }\n },\n [loadTrackForPlayer],\n );\n\n const handlePreviousTrack = useCallback(\n (trackList: PlayerTrack[], currentTrack: PlayerTrack, onTrackChange: (track: PlayerTrack) => void) => {\n if (!trackList || !currentTrack) return;\n\n const currentIndex = trackList.findIndex((track) => track.id === currentTrack.id);\n if (currentIndex === -1) return;\n\n const previousTrack = trackList.slice(0, currentIndex).reverse().find(isPlayable);\n if (previousTrack) {\n onTrackChange(previousTrack);\n loadTrackForPlayer(previousTrack.id);\n }\n },\n [loadTrackForPlayer],\n );\n\n // Cleanup media on unmount\n useEffect(() => {\n return () => {\n if (audioElementRef.current) {\n audioElementRef.current.pause();\n audioElementRef.current = null;\n }\n if (youtubePlayerRef.current) {\n youtubePlayerRef.current.destroy();\n youtubePlayerRef.current = null;\n }\n };\n }, []);\n\n const handlePlayPauseAction = useCallback(() => {\n if (playState === PlayStates.LOADING) return;\n if (!playerTrackObject?.isReady) return;\n\n const mediaController = playerTrackObject.mediaController;\n if (!mediaController) return;\n\n if (playState === PlayStates.PLAYING) {\n mediaController.pause();\n setPlayState(PlayStates.PAUSED);\n setIsPlaying(false);\n } else {\n mediaController.play();\n setPlayState(PlayStates.PLAYING);\n setIsPlaying(true);\n }\n }, [playerTrackObject?.isReady, playerTrackObject?.mediaController, playState]);\n\n const contextValue = useMemo(\n () => ({\n playerTrackObject,\n isPlaying,\n setIsPlaying,\n currentTimeRef,\n duration,\n setDuration,\n volume,\n setVolume,\n playState,\n setPlayState,\n handlePlayPauseAction,\n loadTrackForPlayer,\n isLoading,\n handleNextTrack,\n handlePreviousTrack,\n onTrackEnd,\n setOnTrackEnd,\n videoContainerRef,\n }),\n [\n playerTrackObject,\n isPlaying,\n duration,\n volume,\n playState,\n isLoading,\n handlePlayPauseAction,\n loadTrackForPlayer,\n handleNextTrack,\n handlePreviousTrack,\n onTrackEnd,\n ],\n );\n\n return <PlayerContext.Provider value={contextValue}>{children}</PlayerContext.Provider>;\n}\n\nexport function usePlayer() {\n const context = useContext(PlayerContext);\n if (context === undefined) {\n throw new Error(\"usePlayer must be used within a PlayerProvider\");\n }\n return context;\n}\n\n/** Mounts the YouTube IFrame player. Only needed by apps that play `\"youtube\"`-kind tracks. */\nexport function PlayerVideoSurface({ className }: { className?: string }) {\n const { videoContainerRef } = usePlayer();\n return <div ref={videoContainerRef} className={className} />;\n}\n\n// Custom hook for components that need real-time currentTime updates\nexport function useCurrentTime() {\n const { currentTimeRef } = usePlayer();\n const [currentTime, setCurrentTime] = useState(0);\n\n useEffect(() => {\n const interval = setInterval(() => {\n setCurrentTime(currentTimeRef.current);\n }, 100); // Update every 100ms for smooth UI\n\n return () => clearInterval(interval);\n }, [currentTimeRef]);\n\n return currentTime;\n}\n","/**\n * Uniform playback interface so PlayerContext and its consumers never need to branch on whether\n * the underlying media is an `HTMLAudioElement` or a YouTube IFrame player. `currentTime` is in\n * seconds, `volume` is 0-100 (matching the UI's existing convention and the YouTube IFrame API's\n * native `getVolume`/`setVolume` scale).\n */\nexport interface MediaController {\n getCurrentTime(): number;\n setCurrentTime(time: number): void;\n getVolume(): number;\n setVolume(volume: number): void;\n play(): void;\n pause(): void;\n}\n\nexport class AudioMediaController implements MediaController {\n constructor(private readonly audio: HTMLAudioElement) {}\n\n getCurrentTime(): number {\n return this.audio.currentTime;\n }\n\n setCurrentTime(time: number): void {\n this.audio.currentTime = time;\n }\n\n getVolume(): number {\n return this.audio.volume * 100;\n }\n\n setVolume(volume: number): void {\n this.audio.volume = volume / 100;\n }\n\n play(): void {\n this.audio.play().catch((error) => {\n console.error(\"Error playing audio:\", error);\n });\n }\n\n pause(): void {\n this.audio.pause();\n }\n}\n\nexport class YoutubeMediaController implements MediaController {\n constructor(private readonly player: YT.Player) {}\n\n getCurrentTime(): number {\n return this.player.getCurrentTime();\n }\n\n setCurrentTime(time: number): void {\n this.player.seekTo(time, true);\n }\n\n getVolume(): number {\n return this.player.getVolume();\n }\n\n setVolume(volume: number): void {\n this.player.setVolume(volume);\n }\n\n play(): void {\n this.player.playVideo();\n }\n\n pause(): void {\n this.player.pauseVideo();\n }\n}\n","declare global {\n interface Window {\n onYouTubeIframeAPIReady?: () => void;\n }\n}\n\n/**\n * Loads the YouTube IFrame Player API script exactly once per page and resolves with the\n * `window.YT` namespace it installs. Safe to call repeatedly/concurrently — all callers share the\n * same in-flight/resolved promise.\n */\nlet apiPromise: Promise<typeof YT> | null = null;\n\nexport function loadYoutubeIframeApi(): Promise<typeof YT> {\n if (typeof window === \"undefined\") {\n return Promise.reject(new Error(\"YouTube IFrame API can only be loaded in the browser\"));\n }\n\n if (window.YT?.Player) {\n return Promise.resolve(window.YT);\n }\n\n if (apiPromise) {\n return apiPromise;\n }\n\n apiPromise = new Promise((resolve) => {\n const previousCallback = window.onYouTubeIframeAPIReady;\n window.onYouTubeIframeAPIReady = () => {\n previousCallback?.();\n resolve(window.YT);\n };\n\n const script = document.createElement(\"script\");\n script.src = \"https://www.youtube.com/iframe_api\";\n document.head.appendChild(script);\n });\n\n return apiPromise;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AAJA,SAA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SAAO,4CAAC,cAAc,UAAd,EAAuB,OAAO,cAAe,UAAS;AAChE;AAEO,SAAS,YAAY;AAC1B,QAAM,cAAU,yBAAW,aAAa;AACxC,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,SAAO;AACT;AAGO,SAAS,mBAAmB,EAAE,UAAU,GAA2B;AACxE,QAAM,EAAE,kBAAkB,IAAI,UAAU;AACxC,SAAO,4CAAC,SAAI,KAAK,mBAAmB,WAAsB;AAC5D;AAGO,SAAS,iBAAiB;AAC/B,QAAM,EAAE,eAAe,IAAI,UAAU;AACrC,QAAM,CAAC,aAAa,cAAc,QAAI,uBAAS,CAAC;AAEhD,8BAAU,MAAM;AACd,UAAM,WAAW,YAAY,MAAM;AACjC,qBAAe,eAAe,OAAO;AAAA,IACvC,GAAG,GAAG;AAEN,WAAO,MAAM,cAAc,QAAQ;AAAA,EACrC,GAAG,CAAC,cAAc,CAAC;AAEnB,SAAO;AACT;","names":["PlayStates"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
declare enum PlayStates {
|
|
5
|
+
PLAYING = "PLAYING",
|
|
6
|
+
PAUSED = "PAUSED",
|
|
7
|
+
STOPPED = "STOPPED",
|
|
8
|
+
LOADING = "LOADING"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Uniform playback interface so PlayerContext and its consumers never need to branch on whether
|
|
13
|
+
* the underlying media is an `HTMLAudioElement` or a YouTube IFrame player. `currentTime` is in
|
|
14
|
+
* seconds, `volume` is 0-100 (matching the UI's existing convention and the YouTube IFrame API's
|
|
15
|
+
* native `getVolume`/`setVolume` scale).
|
|
16
|
+
*/
|
|
17
|
+
interface MediaController {
|
|
18
|
+
getCurrentTime(): number;
|
|
19
|
+
setCurrentTime(time: number): void;
|
|
20
|
+
getVolume(): number;
|
|
21
|
+
setVolume(volume: number): void;
|
|
22
|
+
play(): void;
|
|
23
|
+
pause(): void;
|
|
24
|
+
}
|
|
25
|
+
declare class AudioMediaController implements MediaController {
|
|
26
|
+
private readonly audio;
|
|
27
|
+
constructor(audio: HTMLAudioElement);
|
|
28
|
+
getCurrentTime(): number;
|
|
29
|
+
setCurrentTime(time: number): void;
|
|
30
|
+
getVolume(): number;
|
|
31
|
+
setVolume(volume: number): void;
|
|
32
|
+
play(): void;
|
|
33
|
+
pause(): void;
|
|
34
|
+
}
|
|
35
|
+
declare class YoutubeMediaController implements MediaController {
|
|
36
|
+
private readonly player;
|
|
37
|
+
constructor(player: YT.Player);
|
|
38
|
+
getCurrentTime(): number;
|
|
39
|
+
setCurrentTime(time: number): void;
|
|
40
|
+
getVolume(): number;
|
|
41
|
+
setVolume(volume: number): void;
|
|
42
|
+
play(): void;
|
|
43
|
+
pause(): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PlayerTrackArtist {
|
|
47
|
+
/** Lets consumers link the artist (e.g. to an artist page); absent for sources without artist ids. */
|
|
48
|
+
uuid?: string;
|
|
49
|
+
name: string;
|
|
50
|
+
}
|
|
51
|
+
interface PlayerTrackBase {
|
|
52
|
+
id: string;
|
|
53
|
+
title: string;
|
|
54
|
+
artists?: PlayerTrackArtist[];
|
|
55
|
+
}
|
|
56
|
+
interface AudioPlayerTrack extends PlayerTrackBase {
|
|
57
|
+
kind: "audio";
|
|
58
|
+
streamUrl: string;
|
|
59
|
+
}
|
|
60
|
+
interface YoutubePlayerTrack extends PlayerTrackBase {
|
|
61
|
+
kind: "youtube";
|
|
62
|
+
youtubeVideoId: string;
|
|
63
|
+
/** Set when the video can't be embedded/played; next/previous navigation skips the track. */
|
|
64
|
+
unplayableReason?: string | null;
|
|
65
|
+
}
|
|
66
|
+
/** Minimal shape the player needs to play a track and identify it. Extend as needed per app. */
|
|
67
|
+
type PlayerTrack = AudioPlayerTrack | YoutubePlayerTrack;
|
|
68
|
+
interface PlayerTrackObject {
|
|
69
|
+
track: PlayerTrack;
|
|
70
|
+
mediaController?: MediaController;
|
|
71
|
+
isReady: boolean;
|
|
72
|
+
loadError?: string;
|
|
73
|
+
}
|
|
74
|
+
interface PlayerContextType {
|
|
75
|
+
playerTrackObject: PlayerTrackObject | null;
|
|
76
|
+
isPlaying: boolean;
|
|
77
|
+
setIsPlaying: (isPlaying: boolean) => void;
|
|
78
|
+
currentTimeRef: React.MutableRefObject<number>;
|
|
79
|
+
duration: number;
|
|
80
|
+
setDuration: (duration: number) => void;
|
|
81
|
+
volume: number;
|
|
82
|
+
setVolume: (volume: number) => void;
|
|
83
|
+
playState: PlayStates;
|
|
84
|
+
setPlayState: (state: PlayStates) => void;
|
|
85
|
+
handlePlayPauseAction: () => void;
|
|
86
|
+
loadTrackForPlayer: (trackId: string) => void;
|
|
87
|
+
isLoading: boolean;
|
|
88
|
+
handleNextTrack: (trackList: PlayerTrack[], currentTrack: PlayerTrack, onTrackChange: (track: PlayerTrack) => void) => void;
|
|
89
|
+
handlePreviousTrack: (trackList: PlayerTrack[], currentTrack: PlayerTrack, onTrackChange: (track: PlayerTrack) => void) => void;
|
|
90
|
+
onTrackEnd: (() => void) | null;
|
|
91
|
+
setOnTrackEnd: (callback: (() => void) | null) => void;
|
|
92
|
+
/** Container the YouTube IFrame player mounts into. Render `<PlayerVideoSurface />` to attach it. */
|
|
93
|
+
videoContainerRef: React.RefObject<HTMLDivElement>;
|
|
94
|
+
}
|
|
95
|
+
interface PlayerProviderProps {
|
|
96
|
+
children: ReactNode;
|
|
97
|
+
/** Resolves a track id to a playable `PlayerTrack`. */
|
|
98
|
+
loadTrack: (trackId: string) => Promise<PlayerTrack>;
|
|
99
|
+
}
|
|
100
|
+
declare function PlayerProvider({ children, loadTrack }: PlayerProviderProps): react.JSX.Element;
|
|
101
|
+
declare function usePlayer(): PlayerContextType;
|
|
102
|
+
/** Mounts the YouTube IFrame player. Only needed by apps that play `"youtube"`-kind tracks. */
|
|
103
|
+
declare function PlayerVideoSurface({ className }: {
|
|
104
|
+
className?: string;
|
|
105
|
+
}): react.JSX.Element;
|
|
106
|
+
declare function useCurrentTime(): number;
|
|
107
|
+
|
|
108
|
+
export { AudioMediaController, type AudioPlayerTrack, type MediaController, PlayStates, PlayerProvider, type PlayerTrack, type PlayerTrackArtist, PlayerVideoSurface, YoutubeMediaController, type YoutubePlayerTrack, useCurrentTime, usePlayer };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "../chunk-TCXWV62L.js";
|
|
2
|
+
import {
|
|
3
|
+
AudioMediaController,
|
|
4
|
+
PlayStates,
|
|
5
|
+
PlayerProvider,
|
|
6
|
+
PlayerVideoSurface,
|
|
7
|
+
YoutubeMediaController,
|
|
8
|
+
useCurrentTime,
|
|
9
|
+
usePlayer
|
|
10
|
+
} from "../chunk-OIZPAN6I.js";
|
|
11
|
+
export {
|
|
12
|
+
AudioMediaController,
|
|
13
|
+
PlayStates,
|
|
14
|
+
PlayerProvider,
|
|
15
|
+
PlayerVideoSurface,
|
|
16
|
+
YoutubeMediaController,
|
|
17
|
+
useCurrentTime,
|
|
18
|
+
usePlayer
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/popup/index.ts
|
|
21
|
+
var popup_exports = {};
|
|
22
|
+
__export(popup_exports, {
|
|
23
|
+
AUTH_POPUP_TYPE: () => AUTH_POPUP_TYPE,
|
|
24
|
+
PopupProvider: () => PopupProvider,
|
|
25
|
+
useConnectivityErrorPopup: () => useConnectivityErrorPopup,
|
|
26
|
+
usePopup: () => usePopup,
|
|
27
|
+
useTrackUpload: () => useTrackUpload
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(popup_exports);
|
|
30
|
+
|
|
31
|
+
// src/popup/PopupContext.tsx
|
|
32
|
+
var import_react = require("react");
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var AUTH_POPUP_TYPE = "auth";
|
|
35
|
+
var PopupContext = (0, import_react.createContext)(void 0);
|
|
36
|
+
function PopupProvider({ children }) {
|
|
37
|
+
const [state, setState] = (0, import_react.useState)({ content: null, type: null });
|
|
38
|
+
const activePopup = state.content;
|
|
39
|
+
const showPopup = (0, import_react.useCallback)((popup, type) => {
|
|
40
|
+
setState({ content: popup, type: type ?? null });
|
|
41
|
+
}, []);
|
|
42
|
+
const hidePopup = (0, import_react.useCallback)((options) => {
|
|
43
|
+
if (options?.onlyIfType !== void 0) {
|
|
44
|
+
setState((prev) => prev.type === options.onlyIfType ? { content: null, type: null } : prev);
|
|
45
|
+
} else {
|
|
46
|
+
setState({ content: null, type: null });
|
|
47
|
+
}
|
|
48
|
+
}, []);
|
|
49
|
+
const value = (0, import_react.useMemo)(() => ({ showPopup, hidePopup, activePopup }), [showPopup, hidePopup, activePopup]);
|
|
50
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopupContext.Provider, { value, children });
|
|
51
|
+
}
|
|
52
|
+
function usePopup() {
|
|
53
|
+
const context = (0, import_react.useContext)(PopupContext);
|
|
54
|
+
if (context === void 0) {
|
|
55
|
+
throw new Error("usePopup must be used within a PopupProvider");
|
|
56
|
+
}
|
|
57
|
+
return context;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/popup/useConnectivityErrorPopup.ts
|
|
61
|
+
var import_react3 = require("react");
|
|
62
|
+
|
|
63
|
+
// src/transport/app-errors/app-error-messages.ts
|
|
64
|
+
function getSpotifyAllowlistMessage() {
|
|
65
|
+
return "Your Spotify account is not yet authorized for this app.";
|
|
66
|
+
}
|
|
67
|
+
var ErrorMessages = {
|
|
68
|
+
// Network Errors
|
|
69
|
+
["NET1000" /* NETWORK_OFFLINE */]: "Network connection unavailable",
|
|
70
|
+
["NET1001" /* NETWORK_TIMEOUT */]: "Request timed out",
|
|
71
|
+
["NET1002" /* NETWORK_CONNECTION_REFUSED */]: "Connection refused",
|
|
72
|
+
["NET1003" /* NETWORK_NOT_FOUND */]: "Network not found",
|
|
73
|
+
["NET1004" /* NETWORK_ERROR */]: "Network error occurred",
|
|
74
|
+
["NET1005" /* NETWORK_FETCH_ERROR */]: "Failed to fetch data",
|
|
75
|
+
["NET1006" /* NETWORK_ABORT_ERROR */]: "Request aborted",
|
|
76
|
+
["NET1007" /* NETWORK_FAILED_TO_FETCH */]: "Failed to fetch",
|
|
77
|
+
["NET1008" /* NETWORK_UNKNOWN */]: "Unknown network error",
|
|
78
|
+
// Backend Errors
|
|
79
|
+
["BAC2000" /* BACKEND_UNAVAILABLE */]: "Service temporarily unavailable",
|
|
80
|
+
["BAC2001" /* BACKEND_RATE_LIMIT */]: "Too many requests, please try again later",
|
|
81
|
+
["BAC2002" /* BACKEND_AUTH_ERROR */]: "Authentication failed",
|
|
82
|
+
["BAC5000" /* BACKEND_INTERNAL_ERROR */]: "Internal server error",
|
|
83
|
+
["BAC2003" /* BACKEND_INVALID_RESPONSE */]: "Invalid response from server",
|
|
84
|
+
["BAC4000" /* BACKEND_BAD_REQUEST */]: "Bad request",
|
|
85
|
+
["BAC4010" /* BACKEND_UNAUTHORIZED */]: "Unauthorized",
|
|
86
|
+
["BAC4030" /* BACKEND_FORBIDDEN */]: "Forbidden",
|
|
87
|
+
["BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */]: "Connect Spotify to continue",
|
|
88
|
+
["BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
|
|
89
|
+
["BAC4017" /* BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
|
|
90
|
+
["BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */]: "Spotify sign-in is temporarily misconfigured. Please try again later or contact support.",
|
|
91
|
+
["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */]: getSpotifyAllowlistMessage(),
|
|
92
|
+
["BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */]: "Spotify authentication failed",
|
|
93
|
+
["BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */]: "Google authentication failed",
|
|
94
|
+
["BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */]: "Sign-in is temporarily misconfigured. Please try again later or contact support.",
|
|
95
|
+
["BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */]: "Google sign-in is temporarily unavailable. Please try again later or contact support.",
|
|
96
|
+
["BAC4040" /* BACKEND_NOT_FOUND */]: "Not found",
|
|
97
|
+
["BAC4050" /* BACKEND_METHOD_NOT_ALLOWED */]: "Method not allowed",
|
|
98
|
+
["BAC4080" /* BACKEND_REQUEST_TIMEOUT */]: "Request timeout",
|
|
99
|
+
["INP4220" /* BACKEND_INVALID_INPUT */]: "Invalid input",
|
|
100
|
+
// Session Errors
|
|
101
|
+
["SES4011" /* SESSION_EXPIRED */]: "Session expired",
|
|
102
|
+
["SES4012" /* SESSION_REQUIRED */]: "Session required",
|
|
103
|
+
// Client Errors
|
|
104
|
+
["CLI5001" /* CLIENT_UNKNOWN */]: "Unknown error",
|
|
105
|
+
["CLI4030" /* CLIENT_FORBIDDEN */]: "Forbidden",
|
|
106
|
+
["CLI4040" /* CLIENT_NOT_FOUND */]: "Not found",
|
|
107
|
+
["CLI4010" /* CLIENT_UNAUTHORIZED */]: "Unauthorized",
|
|
108
|
+
["CLI5000" /* CLIENT_INTERNAL_ERROR */]: "Internal client error",
|
|
109
|
+
// Service Errors
|
|
110
|
+
["SER4000" /* SERVICE_BAD_REQUEST */]: "Bad request",
|
|
111
|
+
["SER4010" /* SERVICE_UNAUTHORIZED */]: "Unauthorized",
|
|
112
|
+
["SER4030" /* SERVICE_FORBIDDEN */]: "Forbidden",
|
|
113
|
+
["SER4040" /* SERVICE_NOT_FOUND */]: "Not found",
|
|
114
|
+
["SER5000" /* SERVICE_INTERNAL_ERROR */]: "Internal server error",
|
|
115
|
+
["SER5001" /* SERVICE_UNKNOWN */]: "Unknown service error",
|
|
116
|
+
["SER4050" /* SERVICE_METHOD_NOT_ALLOWED */]: "Method not allowed",
|
|
117
|
+
["SER4080" /* SERVICE_REQUEST_TIMEOUT */]: "Request timeout"
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/transport/app-errors/app-error.ts
|
|
121
|
+
var AppError = class extends Error {
|
|
122
|
+
constructor(code) {
|
|
123
|
+
super(ErrorMessages[code]);
|
|
124
|
+
this.code = code;
|
|
125
|
+
this.name = "AppError";
|
|
126
|
+
}
|
|
127
|
+
code;
|
|
128
|
+
};
|
|
129
|
+
var ClientError = class extends AppError {
|
|
130
|
+
constructor(code) {
|
|
131
|
+
super(code);
|
|
132
|
+
this.name = "ClientError";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var InvalidInputError = class extends ClientError {
|
|
136
|
+
constructor(code, json) {
|
|
137
|
+
super(code);
|
|
138
|
+
this.json = json;
|
|
139
|
+
this.name = "InvalidInputError";
|
|
140
|
+
}
|
|
141
|
+
json;
|
|
142
|
+
toString() {
|
|
143
|
+
return `${super.toString()}
|
|
144
|
+
JSON: ${JSON.stringify(this.json, null, 2)}`;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var ConnectivityError = class extends AppError {
|
|
148
|
+
constructor(code) {
|
|
149
|
+
super(code);
|
|
150
|
+
this.name = "ConnectivityError";
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var BadRequestError = class extends ConnectivityError {
|
|
154
|
+
constructor(code) {
|
|
155
|
+
super(code);
|
|
156
|
+
this.name = "BadRequestError";
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var NetworkError = class extends ConnectivityError {
|
|
160
|
+
constructor(code) {
|
|
161
|
+
super(code);
|
|
162
|
+
this.name = "NetworkError";
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var BackendError = class extends ConnectivityError {
|
|
166
|
+
constructor(code, backendMessage) {
|
|
167
|
+
super(code);
|
|
168
|
+
this.backendMessage = backendMessage;
|
|
169
|
+
this.name = "BackendError";
|
|
170
|
+
if (backendMessage) {
|
|
171
|
+
this.message = backendMessage;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
backendMessage;
|
|
175
|
+
};
|
|
176
|
+
var AuthRequired = class extends ConnectivityError {
|
|
177
|
+
constructor(code) {
|
|
178
|
+
super(code);
|
|
179
|
+
this.name = "AuthRequired";
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var ServiceError = class extends ConnectivityError {
|
|
183
|
+
constructor(code) {
|
|
184
|
+
super(code);
|
|
185
|
+
this.name = "ServiceError";
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/transport/connectivity-error-context.tsx
|
|
190
|
+
var import_react2 = require("react");
|
|
191
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
192
|
+
var ConnectivityErrorContext = (0, import_react2.createContext)(void 0);
|
|
193
|
+
function useConnectivityError() {
|
|
194
|
+
const context = (0, import_react2.useContext)(ConnectivityErrorContext);
|
|
195
|
+
if (context === void 0) {
|
|
196
|
+
throw new Error("useConnectivityError must be used within a ConnectivityErrorProvider");
|
|
197
|
+
}
|
|
198
|
+
return context;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/popup/useConnectivityErrorPopup.ts
|
|
202
|
+
var ALWAYS_REDISPLAY_ON_REPEAT = [NetworkError, BackendError, ClientError, ServiceError, InvalidInputError];
|
|
203
|
+
function useConnectivityErrorPopup({
|
|
204
|
+
isAccountPage,
|
|
205
|
+
routeRequiresAuth,
|
|
206
|
+
routeRequiresSpotify,
|
|
207
|
+
renderers
|
|
208
|
+
}) {
|
|
209
|
+
const { showPopup, hidePopup } = usePopup();
|
|
210
|
+
const { connectivityError, clearConnectivityError } = useConnectivityError();
|
|
211
|
+
const currentConnectivityErrorRef = (0, import_react3.useRef)(null);
|
|
212
|
+
const renderersRef = (0, import_react3.useRef)(renderers);
|
|
213
|
+
renderersRef.current = renderers;
|
|
214
|
+
(0, import_react3.useEffect)(() => {
|
|
215
|
+
if (connectivityError === null) {
|
|
216
|
+
if (currentConnectivityErrorRef.current !== null) {
|
|
217
|
+
currentConnectivityErrorRef.current = null;
|
|
218
|
+
hidePopup();
|
|
219
|
+
}
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const error = connectivityError;
|
|
223
|
+
const isSpotifyAllowlistOrAuthError = error instanceof BackendError && ["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */, "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */].includes(
|
|
224
|
+
error.code
|
|
225
|
+
);
|
|
226
|
+
if (isSpotifyAllowlistOrAuthError && !routeRequiresSpotify) {
|
|
227
|
+
hidePopup();
|
|
228
|
+
clearConnectivityError();
|
|
229
|
+
currentConnectivityErrorRef.current = null;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (currentConnectivityErrorRef.current == null || !ALWAYS_REDISPLAY_ON_REPEAT.includes(currentConnectivityErrorRef.current) && !(connectivityError instanceof currentConnectivityErrorRef.current)) {
|
|
233
|
+
const renderer = renderersRef.current;
|
|
234
|
+
let popup = null;
|
|
235
|
+
let popupType = null;
|
|
236
|
+
if (!isAccountPage && routeRequiresAuth && error instanceof AuthRequired) {
|
|
237
|
+
popup = renderer.renderAuthPopup();
|
|
238
|
+
popupType = AUTH_POPUP_TYPE;
|
|
239
|
+
} else if (!isAccountPage && routeRequiresSpotify && error instanceof BackendError && error.code === "BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */) {
|
|
240
|
+
popup = renderer.renderSpotifyOnlyAuthPopup();
|
|
241
|
+
popupType = AUTH_POPUP_TYPE;
|
|
242
|
+
} else if (error instanceof InvalidInputError) {
|
|
243
|
+
console.error("[InvalidInputError]", error.code, error.json);
|
|
244
|
+
popup = renderer.renderInternalErrorPopup(error.code);
|
|
245
|
+
} else if (routeRequiresSpotify && error instanceof BackendError && ["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */, "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */].includes(
|
|
246
|
+
error.code
|
|
247
|
+
)) {
|
|
248
|
+
popup = renderer.renderSpotifyAuthErrorPopup({
|
|
249
|
+
message: error.message,
|
|
250
|
+
errorCode: error.code,
|
|
251
|
+
onClose: () => hidePopup()
|
|
252
|
+
});
|
|
253
|
+
} else if (error instanceof BackendError && [
|
|
254
|
+
"BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */,
|
|
255
|
+
"BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */,
|
|
256
|
+
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */
|
|
257
|
+
].includes(error.code)) {
|
|
258
|
+
popup = renderer.renderGoogleAuthErrorPopup({ message: error.message, onClose: () => hidePopup() });
|
|
259
|
+
} else if (error instanceof BadRequestError || error instanceof BackendError || error instanceof ServiceError || error instanceof AuthRequired) {
|
|
260
|
+
popup = renderer.renderInternalErrorPopup(error.code);
|
|
261
|
+
} else if (error instanceof NetworkError) {
|
|
262
|
+
popup = renderer.renderNetworkErrorPopup();
|
|
263
|
+
}
|
|
264
|
+
if (popup) {
|
|
265
|
+
showPopup(popup, popupType);
|
|
266
|
+
}
|
|
267
|
+
currentConnectivityErrorRef.current = error.constructor;
|
|
268
|
+
}
|
|
269
|
+
}, [
|
|
270
|
+
connectivityError,
|
|
271
|
+
showPopup,
|
|
272
|
+
hidePopup,
|
|
273
|
+
clearConnectivityError,
|
|
274
|
+
isAccountPage,
|
|
275
|
+
routeRequiresAuth,
|
|
276
|
+
routeRequiresSpotify
|
|
277
|
+
]);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/popup/useTrackUpload.ts
|
|
281
|
+
var import_react4 = require("react");
|
|
282
|
+
function useTrackUpload({
|
|
283
|
+
files,
|
|
284
|
+
genre,
|
|
285
|
+
onProcessFile,
|
|
286
|
+
onComplete,
|
|
287
|
+
uploadTimeoutMs
|
|
288
|
+
}) {
|
|
289
|
+
const [items, setItems] = (0, import_react4.useState)([]);
|
|
290
|
+
const [currentUploadIndex, setCurrentUploadIndex] = (0, import_react4.useState)(0);
|
|
291
|
+
const [isUploading, setIsUploading] = (0, import_react4.useState)(false);
|
|
292
|
+
const [allComplete, setAllComplete] = (0, import_react4.useState)(false);
|
|
293
|
+
const lastFilesKeyRef = (0, import_react4.useRef)(null);
|
|
294
|
+
const progressIntervalRef = (0, import_react4.useRef)(null);
|
|
295
|
+
const runRef = (0, import_react4.useRef)(0);
|
|
296
|
+
const completedRunRef = (0, import_react4.useRef)(null);
|
|
297
|
+
(0, import_react4.useEffect)(() => {
|
|
298
|
+
const filesKey = `${files.length}-${files.map((f) => `${f.name}:${f.size}`).join("|")}-${genre ?? ""}`;
|
|
299
|
+
if (lastFilesKeyRef.current === filesKey) return;
|
|
300
|
+
lastFilesKeyRef.current = filesKey;
|
|
301
|
+
runRef.current += 1;
|
|
302
|
+
if (progressIntervalRef.current) {
|
|
303
|
+
clearInterval(progressIntervalRef.current);
|
|
304
|
+
progressIntervalRef.current = null;
|
|
305
|
+
}
|
|
306
|
+
setItems(
|
|
307
|
+
files.map((file, index) => ({
|
|
308
|
+
id: `upload-${index}-${file.name}`,
|
|
309
|
+
file,
|
|
310
|
+
genre: genre ?? null,
|
|
311
|
+
status: "pending",
|
|
312
|
+
progress: 0
|
|
313
|
+
}))
|
|
314
|
+
);
|
|
315
|
+
setCurrentUploadIndex(0);
|
|
316
|
+
setIsUploading(false);
|
|
317
|
+
setAllComplete(false);
|
|
318
|
+
}, [files, genre]);
|
|
319
|
+
const startNextUpload = (0, import_react4.useCallback)(() => {
|
|
320
|
+
const currentItem = items[currentUploadIndex];
|
|
321
|
+
setIsUploading(true);
|
|
322
|
+
setItems(
|
|
323
|
+
(prev) => prev.map((item, index) => index === currentUploadIndex ? { ...item, status: "uploading", progress: 0 } : item)
|
|
324
|
+
);
|
|
325
|
+
if (progressIntervalRef.current) clearInterval(progressIntervalRef.current);
|
|
326
|
+
progressIntervalRef.current = setInterval(() => {
|
|
327
|
+
setItems(
|
|
328
|
+
(prev) => prev.map(
|
|
329
|
+
(item, index) => index === currentUploadIndex && item.status === "uploading" ? { ...item, progress: Math.min(item.progress + Math.random() * 8, 99) } : item
|
|
330
|
+
)
|
|
331
|
+
);
|
|
332
|
+
}, 800);
|
|
333
|
+
const uploadingIndex = currentUploadIndex;
|
|
334
|
+
const run = runRef.current;
|
|
335
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
336
|
+
setTimeout(() => reject(new Error("Upload timed out. The server took too long to respond.")), uploadTimeoutMs);
|
|
337
|
+
});
|
|
338
|
+
Promise.race([onProcessFile(currentItem.file, currentItem.genre), timeoutPromise]).then((data) => {
|
|
339
|
+
if (run !== runRef.current) return;
|
|
340
|
+
if (progressIntervalRef.current) {
|
|
341
|
+
clearInterval(progressIntervalRef.current);
|
|
342
|
+
progressIntervalRef.current = null;
|
|
343
|
+
}
|
|
344
|
+
setItems(
|
|
345
|
+
(prev) => prev.map(
|
|
346
|
+
(item, index) => index === uploadingIndex ? { ...item, status: "success", progress: 100, uploadedTrack: data } : item
|
|
347
|
+
)
|
|
348
|
+
);
|
|
349
|
+
setIsUploading(false);
|
|
350
|
+
setCurrentUploadIndex((prev) => prev + 1);
|
|
351
|
+
}).catch((error) => {
|
|
352
|
+
if (run !== runRef.current) return;
|
|
353
|
+
if (progressIntervalRef.current) {
|
|
354
|
+
clearInterval(progressIntervalRef.current);
|
|
355
|
+
progressIntervalRef.current = null;
|
|
356
|
+
}
|
|
357
|
+
setItems(
|
|
358
|
+
(prev) => prev.map((item, index) => index === uploadingIndex ? { ...item, status: "error", error } : item)
|
|
359
|
+
);
|
|
360
|
+
setIsUploading(false);
|
|
361
|
+
setCurrentUploadIndex((prev) => prev + 1);
|
|
362
|
+
});
|
|
363
|
+
}, [items, currentUploadIndex, onProcessFile, uploadTimeoutMs]);
|
|
364
|
+
(0, import_react4.useEffect)(() => {
|
|
365
|
+
return () => {
|
|
366
|
+
if (progressIntervalRef.current) {
|
|
367
|
+
clearInterval(progressIntervalRef.current);
|
|
368
|
+
progressIntervalRef.current = null;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}, []);
|
|
372
|
+
(0, import_react4.useEffect)(() => {
|
|
373
|
+
const shouldStart = items.length > 0 && !isUploading && currentUploadIndex < items.length;
|
|
374
|
+
if (shouldStart) {
|
|
375
|
+
startNextUpload();
|
|
376
|
+
}
|
|
377
|
+
}, [items, currentUploadIndex, isUploading, startNextUpload]);
|
|
378
|
+
(0, import_react4.useEffect)(() => {
|
|
379
|
+
if (items.length > 0 && currentUploadIndex >= items.length && !isUploading) {
|
|
380
|
+
if (completedRunRef.current === runRef.current) return;
|
|
381
|
+
completedRunRef.current = runRef.current;
|
|
382
|
+
setAllComplete(true);
|
|
383
|
+
const successfulTracks = items.filter((item) => item.status === "success" && item.uploadedTrack).map((item) => item.uploadedTrack);
|
|
384
|
+
onComplete?.(successfulTracks);
|
|
385
|
+
}
|
|
386
|
+
}, [items, currentUploadIndex, isUploading, onComplete]);
|
|
387
|
+
return {
|
|
388
|
+
items,
|
|
389
|
+
isUploading,
|
|
390
|
+
allComplete,
|
|
391
|
+
successfulCount: items.filter((item) => item.status === "success").length,
|
|
392
|
+
errorCount: items.filter((item) => item.status === "error").length
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
396
|
+
0 && (module.exports = {
|
|
397
|
+
AUTH_POPUP_TYPE,
|
|
398
|
+
PopupProvider,
|
|
399
|
+
useConnectivityErrorPopup,
|
|
400
|
+
usePopup,
|
|
401
|
+
useTrackUpload
|
|
402
|
+
});
|
|
403
|
+
//# sourceMappingURL=index.cjs.map
|