fix(media-server): guard against undefined playback from stale cache
PR #6315 added playback/location fields to StreamSession but cached query data may still lack these fields, causing 'can't access property state, playback is undefined' errors on the media server widget.
This commit is contained in:
1 parent
dd23de7aaa
commit
e93e9ed839
1 file changed
+4
-2
@@ -66,10 +66,12 @@ export default function MediaServerWidget({ options, integrationIds }: WidgetCom
|
||||
const currentlyPlaying = row.original.currentlyPlaying;
|
||||
if (!currentlyPlaying) return null;
|
||||
|
||||
const isPaused = currentlyPlaying.playback.state === "paused";
|
||||
const playback = currentlyPlaying.playback;
|
||||
const isPaused = playback?.state === "paused";
|
||||
const Icon = isPaused ? IconPlayerPause : mediaTypeIconMap[currentlyPlaying.type];
|
||||
|
||||
const { positionMs, durationMs } = currentlyPlaying.playback;
|
||||
const positionMs = playback?.positionMs ?? null;
|
||||
const durationMs = playback?.durationMs ?? null;
|
||||
const progressPercent =
|
||||
positionMs !== null && durationMs !== null && durationMs > 0
|
||||
? Math.min(100, Math.round((positionMs / durationMs) * 100))
|
||||
|
||||
Reference in new issue
Block a user