From 1788f086331f5e6289cef07ad2568e55748cb715 Mon Sep 17 00:00:00 2001 From: Robin Davies Date: Sun, 13 Oct 2024 11:36:09 -0400 Subject: [PATCH] Control/VU updates stop when client view is hidden. --- react/src/PiPedalModel.tsx | 59 ++++++++++++++++++++++++------------ react/src/SnapshotDialog.tsx | 2 +- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/react/src/PiPedalModel.tsx b/react/src/PiPedalModel.tsx index d54a494..196688c 100644 --- a/react/src/PiPedalModel.tsx +++ b/react/src/PiPedalModel.tsx @@ -457,13 +457,39 @@ export class PiPedalModel //implements PiPedalModel this.onSocketConnectionLost = this.onSocketConnectionLost.bind(this); } + + private expectDisconnectTimer?: NodeJS.Timeout = undefined; + + cancelExpectDisconnectTimer() + { + if (this.expectDisconnectTimer) { + clearTimeout(this.expectDisconnectTimer); + } + } + startExpectDisconnectTimer() + { + this.cancelExpectDisconnectTimer(); + // poll for access to a running pipedal server + this.expectDisconnectTimer = setTimeout( + async () => { + this.reconnectReason = ReconnectReason.Disconnected; + }, + 5 * 1000); + + } + expectDisconnect(reason: ReconnectReason) { + this.cancelExpectDisconnectTimer(); this.reconnectReason = reason; + if (this.reconnectReason !== ReconnectReason.Disconnected) + { + this.startExpectDisconnectTimer(); + } } onSocketReconnecting(retry: number, maxRetries: number): boolean { + this.cancelExpectDisconnectTimer(); if (this.isClosed) return false; - if (this.visibilityState.get() === VisibilityState.Hidden) return false; //if (retry !== 0) { switch (this.reconnectReason) { case ReconnectReason.Disconnected: @@ -515,7 +541,6 @@ export class PiPedalModel //implements PiPedalModel } onSocketMessage(header: PiPedalMessageHeader, body?: any) { - if (this.visibilityState.get() === VisibilityState.Hidden) return; let message = header.message; if (message === "onControlChanged") { @@ -1187,7 +1212,6 @@ export class PiPedalModel //implements PiPedalModel if (this.backgroundStateTimeout) { clearTimeout(this.backgroundStateTimeout); this.backgroundStateTimeout = undefined; - return; } if (this.state.get() === State.Background) { console.log("Exiting background state."); @@ -1200,17 +1224,19 @@ export class PiPedalModel //implements PiPedalModel // on Android, delay entering background state by 180 seconds, // since background management is more complicated. e.g. screen flips, and system upload dialogs. - if (this.isAndroidHosted()) { - if (this.backgroundStateTimeout) { - clearTimeout(this.backgroundStateTimeout); - } - this.backgroundStateTimeout = setTimeout(() => { - this.backgroundStateTimeout = undefined; - this.enterBackgroundState_(); - }, 180000); - } else { - this.enterBackgroundState_(); - } + // if (this.isAndroidHosted()) { + // yyyx; + // if (this.backgroundStateTimeout) { + // clearTimeout(this.backgroundStateTimeout); + // } + // this.backgroundStateTimeout = setTimeout(() => { + // this.backgroundStateTimeout = undefined; + // this.enterBackgroundState_(); + // }, 180000); + // } else { + // this.enterBackgroundState_(); + // } + this.enterBackgroundState_(); } enterBackgroundState_() { if (this.state.get() !== State.Background) { @@ -1227,11 +1253,9 @@ export class PiPedalModel //implements PiPedalModel switch (document.visibilityState) { case "visible": - this.visibilityState.set(VisibilityState.Visible); this.exitBackgroundState(); break; case "hidden": - this.visibilityState.set(VisibilityState.Hidden); this.enterBackgroundState(); break; } @@ -2424,9 +2448,6 @@ export class PiPedalModel //implements PiPedalModel } private handleNotifyPatchProperty(clientHandle: number, instanceId: number, propertyUri: string, jsonObject: any) { - // yyy this whole path is obsolete. We now get property change notifications - // always, since the entire pedalboard must track excactly. - // Review carefully. let pedalboard = this.pedalboard.get(); let pedalboardItem = pedalboard.getItem(instanceId); if (pedalboardItem) { diff --git a/react/src/SnapshotDialog.tsx b/react/src/SnapshotDialog.tsx index 3076795..8c1b973 100644 --- a/react/src/SnapshotDialog.tsx +++ b/react/src/SnapshotDialog.tsx @@ -86,7 +86,7 @@ export default class SnapshotDialog extends ResizeResponsiveComponent