The Core wrote several limits as bare literals, some of them twice: the voice bitrate default and send range, the relay capacity default, member, room and title name lengths, short keys, IDs, attachment names, message and reply text, watch URLs and rate, signal SDP and candidates, and room passwords. Each is now one named const in the Core module that validates it, and the production Rust copies, Native's screen source title among them, refer to it. Boundary tests keep their own literals. TypeScript held its copies in protocol.ts, shared/protocol.ts, relay-capacity.ts, room-interactions.ts and remote-control/protocol.ts. They move to src/shared/core-limits.ts and the callers import from there. channel_wire_limits now emits every limit under its TypeScript name, so the parity test compares the whole module with the compiled Core. protocol.ts and relay-capacity.ts re-export only the names that session.ts and ChannelShareControl.tsx still import, because those files are held elsewhere. No value changes.
64 lines
3.0 KiB
TypeScript
64 lines
3.0 KiB
TypeScript
import { z } from "zod";
|
|
import { isComposingOrAltGraph } from "../ui/shortcut-key";
|
|
import { INPUT_FRAME_BYTES, REMOTE_INPUT_COMMAND_BYTES, REMOTE_TEXT_BYTES } from "../../shared/core-limits";
|
|
|
|
const encoder = new TextEncoder();
|
|
export function inputFrameFits(frame: string): boolean {
|
|
return frame.length <= INPUT_FRAME_BYTES && encoder.encode(frame).byteLength <= INPUT_FRAME_BYTES;
|
|
}
|
|
|
|
// The editor can measure the command before sending. Every grant has the same hex length.
|
|
const exampleGrant = "0".repeat(64);
|
|
export function remoteTextFits(text: string, grant = exampleGrant): boolean {
|
|
return text.length <= REMOTE_TEXT_BYTES && encoder.encode(text).byteLength <= REMOTE_TEXT_BYTES
|
|
&& encoder.encode(JSON.stringify({ type: "text", text, grant })).byteLength <= REMOTE_INPUT_COMMAND_BYTES;
|
|
}
|
|
|
|
// F12 is reserved by Windows debuggers, including for global modified chords.
|
|
export const remoteShortcutKeySchema = z.number().int().min(1).max(11);
|
|
export const REMOTE_SHORTCUT_KEYS = Array.from({ length: 11 }, (_, index) => index + 1);
|
|
|
|
export function matchesRemoteShortcut(event: Pick<KeyboardEvent, "code" | "ctrlKey" | "altKey" | "shiftKey" | "metaKey"
|
|
| "isComposing" | "keyCode" | "getModifierState">, key: number): boolean {
|
|
return !isComposingOrAltGraph(event) && event.ctrlKey && event.altKey && !event.shiftKey && !event.metaKey && event.code === `F${key}`;
|
|
}
|
|
|
|
export const remoteControlModeSchema = z.enum(["off", "ask", "room", "password"]);
|
|
export type RemoteControlMode = z.infer<typeof remoteControlModeSchema>;
|
|
export const remoteInputPlatformSchema = z.enum(["windows", "darwin", "linux"]);
|
|
export type RemoteInputPlatform = z.infer<typeof remoteInputPlatformSchema>;
|
|
|
|
export const remoteInputStateSchema = z.object({
|
|
state: z.enum(["ready", "unavailable", "pending", "active", "suspended", "failed"]),
|
|
mode: remoteControlModeSchema,
|
|
platform: z.string().min(1),
|
|
grant: z.string().regex(/^[0-9a-f]{64}$/).optional(),
|
|
intent: z.string().regex(/^[0-9a-f]{32}$/).optional(),
|
|
// A future diagnostic has no local copy, but differs from a reply with no reason.
|
|
reason: z.enum(["password", "retry", "busy", "gamepad"]).or(z.string().min(1).transform(() => null)).optional(),
|
|
capabilities: z.array(z.string().min(1).max(32)).max(16).optional(),
|
|
coPlay: z.boolean().optional(),
|
|
inputFailed: z.boolean().optional(),
|
|
});
|
|
export type RemoteInputState = z.infer<typeof remoteInputStateSchema>;
|
|
|
|
export function remoteTextAvailable(state: RemoteInputState): boolean {
|
|
return !state.coPlay || state.capabilities?.includes("text") === true;
|
|
}
|
|
|
|
export function remoteGamepadAvailable(state: RemoteInputState): boolean {
|
|
return state.coPlay === true && state.capabilities?.includes("gamepad") === true;
|
|
}
|
|
|
|
// Button bits follow W3C standard indices; sticks are signed 16-bit, Y down,
|
|
// and triggers are unsigned 8-bit. Native SDK layouts stay in Host adapters.
|
|
export interface RemoteGamepadReport {
|
|
buttons: number;
|
|
leftTrigger: number;
|
|
rightTrigger: number;
|
|
leftX: number;
|
|
leftY: number;
|
|
rightX: number;
|
|
rightY: number;
|
|
}
|