mirror of https://github.com/jetkvm/kvm.git
chore: add comments and remove unused code
This commit is contained in:
parent
4592269dd1
commit
7feb92c9c7
|
@ -229,6 +229,7 @@ export default function WebRTCVideo() {
|
||||||
if (rpcHidReady) {
|
if (rpcHidReady) {
|
||||||
reportRelMouseEvent(dx, dy, buttons);
|
reportRelMouseEvent(dx, dy, buttons);
|
||||||
} else {
|
} else {
|
||||||
|
// kept for backward compatibility
|
||||||
send("relMouseReport", { dx, dy, buttons });
|
send("relMouseReport", { dx, dy, buttons });
|
||||||
}
|
}
|
||||||
setMouseMove({ x, y, buttons });
|
setMouseMove({ x, y, buttons });
|
||||||
|
@ -260,6 +261,7 @@ export default function WebRTCVideo() {
|
||||||
if (rpcHidReady) {
|
if (rpcHidReady) {
|
||||||
reportAbsMouseEvent(x, y, buttons);
|
reportAbsMouseEvent(x, y, buttons);
|
||||||
} else {
|
} else {
|
||||||
|
// kept for backward compatibility
|
||||||
send("absMouseReport", { x, y, buttons });
|
send("absMouseReport", { x, y, buttons });
|
||||||
}
|
}
|
||||||
// We set that for the debug info bar
|
// We set that for the debug info bar
|
||||||
|
|
|
@ -51,26 +51,13 @@ export default function useKeyboard() {
|
||||||
if (rpcHidReady) {
|
if (rpcHidReady) {
|
||||||
console.debug("Sending keyboard report via HidRPC");
|
console.debug("Sending keyboard report via HidRPC");
|
||||||
reportKeyboardEvent(state.keys, state.modifier);
|
reportKeyboardEvent(state.keys, state.modifier);
|
||||||
|
setkeyPressReportApiAvailable(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
send("keyboardReport", { keys: state.keys, modifier: state.modifier }, (resp: JsonRpcResponse) => {
|
send("keyboardReport", { keys: state.keys, modifier: state.modifier }, (resp: JsonRpcResponse) => {
|
||||||
if ("error" in resp) {
|
if ("error" in resp) {
|
||||||
console.error(`Failed to send keyboard report ${state}`, resp.error);
|
console.error(`Failed to send keyboard report ${state}`, resp.error);
|
||||||
} else {
|
|
||||||
// If the device supports keyPressReport API, it will (also) return the keysDownState when we send
|
|
||||||
// the keyboardReport
|
|
||||||
const keysDownState = resp.result as KeysDownState;
|
|
||||||
|
|
||||||
if (keysDownState) {
|
|
||||||
setKeysDownState(keysDownState); // treat the response as the canonical state
|
|
||||||
setkeyPressReportApiAvailable(true); // if they returned a keysDownState, we ALSO know they also support keyPressReport
|
|
||||||
} else {
|
|
||||||
// older devices versions do not return the keyDownState
|
|
||||||
// so we just pretend they accepted what we sent
|
|
||||||
setKeysDownState(state);
|
|
||||||
setkeyPressReportApiAvailable(false); // we ALSO know they do not support keyPressReport
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -79,7 +66,6 @@ export default function useKeyboard() {
|
||||||
rpcHidReady,
|
rpcHidReady,
|
||||||
send,
|
send,
|
||||||
reportKeyboardEvent,
|
reportKeyboardEvent,
|
||||||
setKeysDownState,
|
|
||||||
setkeyPressReportApiAvailable,
|
setkeyPressReportApiAvailable,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -92,41 +78,14 @@ export default function useKeyboard() {
|
||||||
// in client/browser-side code using simulateDeviceSideKeyHandlingForLegacyDevices.
|
// in client/browser-side code using simulateDeviceSideKeyHandlingForLegacyDevices.
|
||||||
const sendKeypressEvent = useCallback(
|
const sendKeypressEvent = useCallback(
|
||||||
async (key: number, press: boolean) => {
|
async (key: number, press: boolean) => {
|
||||||
if (rpcDataChannel?.readyState !== "open" && !rpcHidReady) return;
|
|
||||||
|
|
||||||
console.debug(`Send keypressEvent key: ${key}, press: ${press}`);
|
console.debug(`Send keypressEvent key: ${key}, press: ${press}`);
|
||||||
|
|
||||||
if (rpcHidReady) {
|
if (!rpcHidReady) return;
|
||||||
console.debug("Sending keypress event via HidRPC");
|
|
||||||
reportKeypressEvent(key, press);
|
reportKeypressEvent(key, press);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
send("keypressReport", { key, press }, (resp: JsonRpcResponse) => {
|
|
||||||
if ("error" in resp) {
|
|
||||||
// -32601 means the method is not supported because the device is running an older version
|
|
||||||
if (resp.error.code === -32601) {
|
|
||||||
console.error("Legacy device does not support keypressReport API, switching to local key down state handling", resp.error);
|
|
||||||
setkeyPressReportApiAvailable(false);
|
|
||||||
} else {
|
|
||||||
console.error(`Failed to send key ${key} press: ${press}`, resp.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const keysDownState = resp.result as KeysDownState;
|
|
||||||
|
|
||||||
if (keysDownState) {
|
|
||||||
setKeysDownState(keysDownState);
|
|
||||||
// we don't need to set keyPressReportApiAvailable here, because it's already true or we never landed here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
rpcDataChannel?.readyState,
|
|
||||||
rpcHidReady,
|
rpcHidReady,
|
||||||
send,
|
|
||||||
setkeyPressReportApiAvailable,
|
|
||||||
setKeysDownState,
|
|
||||||
reportKeypressEvent,
|
reportKeypressEvent,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue