Control/VU updates stop when client view is hidden.

This commit is contained in:
Robin Davies
2024-10-13 11:36:09 -04:00
parent fec62960ad
commit 1788f08633
2 changed files with 41 additions and 20 deletions
+39 -18
View File
@@ -457,13 +457,39 @@ export class PiPedalModel //implements PiPedalModel
this.onSocketConnectionLost = this.onSocketConnectionLost.bind(this); 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) { expectDisconnect(reason: ReconnectReason) {
this.cancelExpectDisconnectTimer();
this.reconnectReason = reason; this.reconnectReason = reason;
if (this.reconnectReason !== ReconnectReason.Disconnected)
{
this.startExpectDisconnectTimer();
}
} }
onSocketReconnecting(retry: number, maxRetries: number): boolean { onSocketReconnecting(retry: number, maxRetries: number): boolean {
this.cancelExpectDisconnectTimer();
if (this.isClosed) return false; if (this.isClosed) return false;
if (this.visibilityState.get() === VisibilityState.Hidden) return false;
//if (retry !== 0) { //if (retry !== 0) {
switch (this.reconnectReason) { switch (this.reconnectReason) {
case ReconnectReason.Disconnected: case ReconnectReason.Disconnected:
@@ -515,7 +541,6 @@ export class PiPedalModel //implements PiPedalModel
} }
onSocketMessage(header: PiPedalMessageHeader, body?: any) { onSocketMessage(header: PiPedalMessageHeader, body?: any) {
if (this.visibilityState.get() === VisibilityState.Hidden) return;
let message = header.message; let message = header.message;
if (message === "onControlChanged") { if (message === "onControlChanged") {
@@ -1187,7 +1212,6 @@ export class PiPedalModel //implements PiPedalModel
if (this.backgroundStateTimeout) { if (this.backgroundStateTimeout) {
clearTimeout(this.backgroundStateTimeout); clearTimeout(this.backgroundStateTimeout);
this.backgroundStateTimeout = undefined; this.backgroundStateTimeout = undefined;
return;
} }
if (this.state.get() === State.Background) { if (this.state.get() === State.Background) {
console.log("Exiting background state."); console.log("Exiting background state.");
@@ -1200,17 +1224,19 @@ export class PiPedalModel //implements PiPedalModel
// on Android, delay entering background state by 180 seconds, // on Android, delay entering background state by 180 seconds,
// since background management is more complicated. e.g. screen flips, and system upload dialogs. // since background management is more complicated. e.g. screen flips, and system upload dialogs.
if (this.isAndroidHosted()) { // if (this.isAndroidHosted()) {
if (this.backgroundStateTimeout) { // yyyx;
clearTimeout(this.backgroundStateTimeout); // if (this.backgroundStateTimeout) {
} // clearTimeout(this.backgroundStateTimeout);
this.backgroundStateTimeout = setTimeout(() => { // }
this.backgroundStateTimeout = undefined; // this.backgroundStateTimeout = setTimeout(() => {
// this.backgroundStateTimeout = undefined;
// this.enterBackgroundState_();
// }, 180000);
// } else {
// this.enterBackgroundState_();
// }
this.enterBackgroundState_(); this.enterBackgroundState_();
}, 180000);
} else {
this.enterBackgroundState_();
}
} }
enterBackgroundState_() { enterBackgroundState_() {
if (this.state.get() !== State.Background) { if (this.state.get() !== State.Background) {
@@ -1227,11 +1253,9 @@ export class PiPedalModel //implements PiPedalModel
switch (document.visibilityState) { switch (document.visibilityState) {
case "visible": case "visible":
this.visibilityState.set(VisibilityState.Visible);
this.exitBackgroundState(); this.exitBackgroundState();
break; break;
case "hidden": case "hidden":
this.visibilityState.set(VisibilityState.Hidden);
this.enterBackgroundState(); this.enterBackgroundState();
break; break;
} }
@@ -2424,9 +2448,6 @@ export class PiPedalModel //implements PiPedalModel
} }
private handleNotifyPatchProperty(clientHandle: number, instanceId: number, propertyUri: string, jsonObject: any) { 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 pedalboard = this.pedalboard.get();
let pedalboardItem = pedalboard.getItem(instanceId); let pedalboardItem = pedalboard.getItem(instanceId);
if (pedalboardItem) { if (pedalboardItem) {
+1 -1
View File
@@ -86,7 +86,7 @@ export default class SnapshotDialog extends ResizeResponsiveComponent<SnapshotDi
} }
getFullScreen() { getFullScreen() {
return window.innerHeight < 450; return window.innerHeight < 450 || window.innerWidth < 450;
} }
onWindowSizeChanged(width: number, height: number): void { onWindowSizeChanged(width: number, height: number): void {
this.setState( this.setState(