spaces: a room carries what its members are playing, sealed in the window its chat already uses
This commit is contained in:
1 parent
4ca9ab043b
commit
df06f849e0
6 files changed
+459
-14
No files matched your search
@@ -367,6 +367,45 @@
|
||||
void api.smtcMetadata(title, artist, album, art);
|
||||
});
|
||||
|
||||
/* A listen for any Space that asked for one (src-tauri/src/spaces.rs —
|
||||
which rooms hear it is that side's business, since the ledger knows and
|
||||
this bar does not). Reported from here for the same reason the OS card
|
||||
is: `metaParts` is where a track's artist and album are reconciled, and
|
||||
deriving them a second time would be a second set of rules.
|
||||
|
||||
Once per track, and only after it has actually been LISTENED to — 30s,
|
||||
or halfway for anything shorter. A skip says nothing about taste, and
|
||||
the Space's window is shared with its chat, so a room that posted every
|
||||
press would push its own conversation out inside a day. */
|
||||
const LISTEN_AFTER = 30;
|
||||
let listened = "";
|
||||
$effect(() => {
|
||||
const title = player.track?.title ?? "";
|
||||
const pos = player.position ?? 0;
|
||||
if (!title) return;
|
||||
const [artist, album] = metaParts;
|
||||
// The track, not the render. Coming back to a song after playing
|
||||
// something else changes this key twice, so it reports again — while
|
||||
// seeking around inside one play never does. This lives in memory, so
|
||||
// a reload with something already past the threshold reports it again;
|
||||
// the repeat is dropped on the other side, which is the only place
|
||||
// that knows what was last said in each room.
|
||||
const key = `${player.track?.path ?? ""}|${title}|${artist}`;
|
||||
if (key === listened) return;
|
||||
const enough = Math.min(LISTEN_AFTER, (player.duration ?? LISTEN_AFTER * 2) / 2);
|
||||
if (pos < enough) return;
|
||||
listened = key;
|
||||
void api
|
||||
// No catalog id: `player.track` carries what the bar needs to draw
|
||||
// itself and nothing more. Artist and title are what a listen is
|
||||
// found by anyway, the same pair `slsk_hint` carries.
|
||||
.spaceReportListen(title, artist, album, player.duration ? Math.round(player.duration) : null, null)
|
||||
.catch(() => {
|
||||
// A Space that cannot be posted to is not this bar's problem;
|
||||
// the backend already logged which one and why.
|
||||
});
|
||||
});
|
||||
|
||||
// Waveform canvas + hover state.
|
||||
let waveWrap = $state(null);
|
||||
let waveCanvas = $state(null);
|
||||
|
||||
Reference in new issue
Block a user