Skip to content

Commit 249cecc

Browse files
committed
make onOpen clear cached instlist so it resubscribes to all pvs
1 parent b48a27a commit 249cecc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/components/InstrumentData.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
5959
} = useWebSocket(socketURL, {
6060
shouldReconnect: (closeEvent) => true,
6161
onOpen: () => {
62+
setLastUpdate(""); // if this is called on a reconnect, we want to clear the last update so we can re-subscribe to everything again
6263
sendJsonMessage(instListSubscription);
6364
},
6465
onMessage: (m) => {

app/components/InstrumentsDisplay.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export default function InstrumentsDisplay({
6464
);
6565
},
6666
onOpen: () => {
67+
setInstList([]); // if this is called on a reconnect, clear the instlist so we can re-subscribe to it and get its latest value
6768
sendJsonMessage(instListSubscription);
69+
// Subscribe to beam current PVs
6870
sendJsonMessage({
6971
type: PVWSRequestType.subscribe,
7072
pvs: [ts1BeamCurrentPv, ts2BeamCurrentPv, muonTargetCurrentPv],
@@ -76,7 +78,12 @@ export default function InstrumentsDisplay({
7678
const updatedPVbytes: string | null | undefined = updatedPV.b64byt;
7779
const updatedPVvalue: string | null | undefined = updatedPV.text;
7880
const updatedPVnum: number | null | undefined = updatedPV.value;
79-
if (updatedPVName == instListPV && updatedPVbytes != null) {
81+
// PVWS seems to give 2 updates for the instlist, so just use the first one to avoid re-subscribing to all the runstate PVs.
82+
if (
83+
updatedPVName == instListPV &&
84+
updatedPVbytes != null &&
85+
instList.length == 0
86+
) {
8087
const instListDict = instListFromBytes(updatedPVbytes);
8188

8289
for (const item of instListDict) {

0 commit comments

Comments
 (0)