fix(playback): dispatch each remote command once; stabilise controllers

This commit is contained in:
Uruk
2026-05-22 02:30:29 +02:00
parent e9f61a2f7c
commit 8b94f491e4
3 changed files with 68 additions and 32 deletions

View File

@@ -5,7 +5,7 @@
*/
import { useAtomValue } from "jotai";
import { useEffect } from "react";
import { useEffect, useRef } from "react";
import { toast } from "sonner-native";
import { activePlaybackControllerAtom } from "@/utils/playback/playbackController";
import {
@@ -16,9 +16,11 @@ import {
/** Handle one remote-control message (call it whenever a new WS message arrives). */
export const useRemoteControl = (lastMessage: RemoteWsMessage | null): void => {
const controller = useAtomValue(activePlaybackControllerAtom);
const handledRef = useRef<RemoteWsMessage | null>(null);
useEffect(() => {
if (!lastMessage) return;
if (!lastMessage || lastMessage === handledRef.current) return;
handledRef.current = lastMessage;
const action = mapRemoteCommand(lastMessage);
if (!action) return;