Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions app/src/components/computer/live-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,26 @@ export function LiveScreen({ computerId, driving, onProblem }: Props) {
};

socket.onmessage = async (event) => {
let message: {
let parsed: unknown;
try {
parsed = JSON.parse(String(event.data));
} catch {
return;
}
// A frame that is not an object (`null`, a number, a string, an array) has
// no `type` to read: reaching for it throws a `TypeError` inside this
// handler and stops the live view from drawing further frames. Drop it.
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
return;
}
const message = parsed as {
type: string;
data?: string;
width?: number;
height?: number;
error?: string;
};
try {
message = JSON.parse(String(event.data));
} catch {
return;
}
if (typeof message.type !== "string") return;
if (message.type === "error") {
onProblem?.(message.error ?? "The screen could not be shown.");
return;
Expand Down