From c3eb6b7d1ab3f9919841c5844ed1c0e96f62bd52 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Fri, 23 Jan 2026 18:47:52 +0530 Subject: [PATCH] fix: enable VU meter updates by calling SetVURefreshRate VU meters were not lighting up because the native audio client was never told to start sending VU data. This fix adds the SetVURefreshRate(150) call when joining a session to enable VU updates every 150ms. Also adds a ref pattern in useMixerStore to prevent potential stale closure issues in the handleBridgeCallback VU callback handler. Co-Authored-By: Claude Sonnet 4.5 --- .../src/components/client/JKSessionScreen.js | 1 + jam-ui/src/hooks/useMixerStore.js | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/jam-ui/src/components/client/JKSessionScreen.js b/jam-ui/src/components/client/JKSessionScreen.js index f20dc3885..b4ae8600a 100644 --- a/jam-ui/src/components/client/JKSessionScreen.js +++ b/jam-ui/src/components/client/JKSessionScreen.js @@ -437,6 +437,7 @@ const JKSessionScreen = () => { const joinSession = async () => { + await jamClient.SetVURefreshRate(150); await jamClient.SessionRegisterCallback("JK.HandleBridgeCallback2"); await jamClient.SessionSetAlertCallback("JK.HandleAlertCallback"); await jamClient.RegisterRecordingCallbacks("JK.HandleRecordingStartResult", "JK.HandleRecordingStopResult", "JK.HandleRecordingStarted", "JK.HandleRecordingStopped", "JK.HandleRecordingAborted"); diff --git a/jam-ui/src/hooks/useMixerStore.js b/jam-ui/src/hooks/useMixerStore.js index 305c8f318..207e2dc01 100644 --- a/jam-ui/src/hooks/useMixerStore.js +++ b/jam-ui/src/hooks/useMixerStore.js @@ -34,6 +34,7 @@ export default function useMixerStore() { jamClient, } = useJamServerContext(); const mixerHelper = useMixersContext(); + const mixerHelperRef = useRef(null); const logger = console; // Replace with your logging mechanism if needed //const { updateVU } = useVuHelpers(); @@ -64,6 +65,11 @@ export default function useMixerStore() { 6: "MetroFile" }; + // Keep mixerHelperRef in sync with current mixerHelper + useEffect(() => { + mixerHelperRef.current = mixerHelper; + }, [mixerHelper]); + // Initialize global callbacks useEffect(() => { if (!window.JK) window.JK = {}; @@ -165,11 +171,18 @@ export default function useMixerStore() { // value is a DB value from -80 to 20. Convert to float from 0.0-1.0 //console.log('handleBridgeCallback@mixers',@mixers) - // console.log("mixerHelper.isReady", mixerHelper.isReady.current); - if (mixerHelper.isReady.current) { - // console.log("mixerHelper handleBridgeCallback: ", mixerId, mode, leftValue, rightValue, leftClipping, rightClipping); + // Use ref to get current mixerHelper (fixes stale closure issue) + const currentMixerHelper = mixerHelperRef.current; - mixerHelper.updateVU(mixerId, mode, (leftValue + 80) / 80, leftClipping, (rightValue + 80) / 80, rightClipping); + if (currentMixerHelper?.isReady.current) { + currentMixerHelper.updateVU( + mixerId, + mode, + (leftValue + 80) / 80, + leftClipping, + (rightValue + 80) / 80, + rightClipping + ); } } }