chore: show hid rpc version

This commit is contained in:
Siyuan Miao 2025-08-30 14:10:35 +02:00
parent 3dd8645295
commit c459929a91
3 changed files with 18 additions and 7 deletions

View File

@ -15,8 +15,8 @@ import { useHidRpc } from "@/hooks/useHidRpc";
export default function InfoBar() {
const { keysDownState } = useHidStore();
const { mouseX, mouseY, mouseMove } = useMouseStore();
const { rpcHidReady } = useHidRpc();
const { rpcHidStatus } = useHidRpc();
const videoClientSize = useVideoStore(
(state: VideoState) => `${Math.round(state.clientWidth)}x${Math.round(state.clientHeight)}`,
);
@ -48,7 +48,7 @@ export default function InfoBar() {
const modifierNames = Object.entries(modifiers).filter(([_, mask]) => (activeModifierMask & mask) !== 0).map(([name, _]) => name);
const keyNames = Object.entries(keys).filter(([_, value]) => keysDown.includes(value)).map(([name, _]) => name);
return [...modifierNames,...keyNames].join(", ");
return [...modifierNames, ...keyNames].join(", ");
}, [keysDownState, showPressedKeys]);
return (
@ -105,7 +105,7 @@ export default function InfoBar() {
{debugMode && (
<div className="flex w-[156px] items-center gap-x-1">
<span className="text-xs font-semibold">HidRPC State:</span>
<span className="text-xs">{rpcHidReady ? "Ready" : "Not Ready"}</span>
<span className="text-xs">{rpcHidStatus}</span>
</div>
)}

View File

@ -163,6 +163,13 @@ export function useHidRpc(onHidRpcMessage?: (payload: HidRpcMessage) => void) {
return rpcHidChannel?.readyState === "open" && rpcHidProtocolVersion !== null;
}, [rpcHidChannel, rpcHidProtocolVersion]);
const rpcHidStatus = useMemo(() => {
if (!rpcHidChannel) return "N/A";
if (rpcHidChannel.readyState !== "open") return rpcHidChannel.readyState;
if (!rpcHidProtocolVersion) return "handshaking";
return `ready (v${rpcHidProtocolVersion})`;
}, [rpcHidChannel, rpcHidProtocolVersion]);
const reportKeyboardEvent = useCallback(
(keys: number[], modifier: number) => {
if (!rpcHidReady) return;
@ -262,5 +269,6 @@ export function useHidRpc(onHidRpcMessage?: (payload: HidRpcMessage) => void) {
reportRelMouseEvent,
rpcHidProtocolVersion,
rpcHidReady,
rpcHidStatus,
};
}

View File

@ -134,21 +134,24 @@ func newSession(config SessionConfig) (*Session, error) {
}()
scopedLogger.Info().Str("label", d.Label()).Uint16("id", *d.ID()).Msg("New DataChannel")
switch d.Label() {
case "hidrpc":
session.HidChannel = d
d.OnMessage(func(msg webrtc.DataChannelMessage) {
l := scopedLogger.With().Str("data", string(msg.Data)).Int("length", len(msg.Data)).Logger()
if msg.IsString {
scopedLogger.Warn().Str("data", string(msg.Data)).Msg("received string data in HID RPC message handler")
l.Warn().Msg("received string data in HID RPC message handler")
return
}
if len(msg.Data) < 1 {
scopedLogger.Warn().Int("length", len(msg.Data)).Msg("received empty data in HID RPC message handler")
l.Warn().Msg("received empty data in HID RPC message handler")
return
}
scopedLogger.Debug().Str("data", string(msg.Data)).Msg("received data in HID RPC message handler")
l.Trace().Msg("received data in HID RPC message handler")
// Enqueue to ensure ordered processing
session.hidQueue <- msg