officerdev/src/MusicPlayer/ → plugins/music/web/. Engine, state, bar, favourites, lyrics toggle and the library vocabulary — ten files. The barrel stops exporting a player it no longer has, and DashboardLayout stops rendering one. The reasoning that kept it was removed rather than refuted. It stayed because the dashboard widget imported useMusicPlayer from officerdev and the platform cannot import from a plugin, so the state had to stay whatever was decided about the UI. The owner moved the widget into the plugin in the previous commit, and the constraint went with it: the whole remaining dependency became one line, DashboardLayout.tsx:66. MusicPlayerHost is mounted inside the MusicDetail panel. That reads odd until you notice it already returned null on /music — the mini bar is the transport there, and the host existed purely to own the GaplessEngine. In the panel it does exactly that, and the bar code stays intact for whenever there is a slot. [phase 2] Leaving /music unmounts the host and playback stops. Deferred on the owner's call; the bar was "navigating away must not break the application", and that holds: seekPlayer is optional-chained so a call with no host registered is a no-op, registerPlayerSeek clears only its own registration, the host's cleanup destroys the engine and nulls its ref, and the queue is global state so returning to /music remounts and reloads. Solving it properly needs either a shell slot a plugin can contribute to — which reopens "there is no way to export a component" — or the engine hoisted to module scope, which keeps the rule and loses only the off-route controls. Also: the parked widget now imports the player as a sibling rather than through officerdev, and shared.ts stopped being a re-export shim now that the real file is in the plugin. Verified: tsgo clean, 797 tests / 787 pass / same 7. Server restarts, mounts /example /music /offscale, / and /music both 200, and the player is in the built bundle (music.volume, music:lyrics, now-playing?device=web all present — GaplessEngine is a class name and the production build is minified, so grepping for it proves nothing). Not verified by me: what it looks like in a browser. That needs your eyes.
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
/**
|
||
* Playback position, published outside React.
|
||
*
|
||
* The lyrics pane no longer lives in the player's subtree — it renders in a panel of the /music
|
||
* workspace — so the position has to cross the tree. It cannot cross as state: the engine reports a new
|
||
* position every animation frame, and a shared state channel would re-render every consumer 60× a
|
||
* second. Instead the host pushes into this module and subscribers decide for themselves what is worth
|
||
* a render (the lyrics pane only re-renders when the ACTIVE LINE changes, roughly once a line).
|
||
*
|
||
* Seek travels the other way for the same reason: the engine is the host's, but a click on a lyric line
|
||
* has to reach it.
|
||
*/
|
||
let position = 0;
|
||
let duration = 0;
|
||
const subscribers = new Set<(sec: number, dur: number) => void>();
|
||
let seekFn: ((sec: number) => void) | null = null;
|
||
|
||
export const publishPlayerTime = (sec: number, dur: number): void => {
|
||
position = sec;
|
||
duration = dur;
|
||
for (const fn of subscribers) fn(sec, dur);
|
||
};
|
||
|
||
/** Latest values, for a subscriber that mounts mid-track. */
|
||
export const getPlayerTime = (): number => position;
|
||
export const getPlayerDuration = (): number => duration;
|
||
|
||
export const subscribePlayerTime = (fn: (sec: number, dur: number) => void): (() => void) => {
|
||
subscribers.add(fn);
|
||
return () => {
|
||
subscribers.delete(fn);
|
||
};
|
||
};
|
||
|
||
export const registerPlayerSeek = (fn: (sec: number) => void): (() => void) => {
|
||
seekFn = fn;
|
||
return () => {
|
||
if (seekFn === fn) seekFn = null;
|
||
};
|
||
};
|
||
|
||
export const seekPlayer = (sec: number): void => seekFn?.(sec);
|