Skip to content

Commit 1e9ce05

Browse files
committed
fix(web): limit device input fix to non-primary buttons
1 parent afeb735 commit 1e9ce05

2 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎apps/web/src/components/device/DeviceStreamView.test.tsx‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ afterEach(async () => {
4343
});
4444

4545
async function setup() {
46+
const touches: unknown[] = [];
4647
vi.useFakeTimers();
4748
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
4849
vi.stubGlobal("fetch", () => {
@@ -54,7 +55,11 @@ async function setup() {
5455
class {
5556
static OPEN = 1;
5657
readyState = 1;
57-
send() {}
58+
send(packet: Uint8Array) {
59+
if (packet[0] === 0x03) {
60+
touches.push(JSON.parse(new TextDecoder().decode(packet.subarray(1))));
61+
}
62+
}
5863
close() {}
5964
},
6065
);
@@ -90,9 +95,41 @@ async function setup() {
9095
},
9196
});
9297
});
93-
return { images, view };
98+
return { images, view, touches };
9499
}
95100

101+
it.each([1, 2])(
102+
"ignores button %i gestures and still forwards the next primary drag",
103+
async (button) => {
104+
const { touches } = await setup();
105+
const viewport = renderer!.root.findByType("canvas").parent!;
106+
const currentTarget = {
107+
setPointerCapture() {},
108+
parentElement: { focus() {} },
109+
getBoundingClientRect: () => ({ left: 20, top: 40, width: 400, height: 800 }),
110+
};
111+
const event = { button, pointerId: 1, currentTarget, clientX: 120, clientY: 640 };
112+
await act(async () => {
113+
viewport.props.onPointerDown(event);
114+
viewport.props.onPointerMove({ ...event, clientY: 240 });
115+
viewport.props.onPointerUp({ ...event, clientY: 240 });
116+
});
117+
expect(touches).toEqual([]);
118+
119+
await act(async () => {
120+
viewport.props.onPointerDown({ ...event, button: 0 });
121+
viewport.props.onPointerMove({ ...event, button: 0, clientY: 240 });
122+
viewport.props.onPointerUp({ ...event, button: 0, clientY: 240 });
123+
viewport.props.onPointerMove({ ...event, button: 0, clientY: 440 });
124+
});
125+
expect(touches).toEqual([
126+
{ type: "begin", x: 0.25, y: 0.75 },
127+
{ type: "move", x: 0.25, y: 0.25 },
128+
{ type: "end", x: 0.25, y: 0.25 },
129+
]);
130+
},
131+
);
132+
96133
it("removes MJPEG requests while hidden and reconnects when shown", async () => {
97134
const { images, view } = await setup();
98135
expect(images[0]!.src).toContain("stream.mjpeg");

‎apps/web/src/components/device/DeviceStreamView.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,10 @@ export function DeviceStreamView(props: {
408408
}}
409409
>
410410
<div
411-
className={cn(
412-
"relative touch-none select-none",
413-
showPhone && "invisible pointer-events-none",
414-
)}
411+
className={cn("relative select-none", showPhone && "invisible pointer-events-none")}
415412
style={{ width: frame.width, height: frame.height }}
416413
onPointerDown={(event) => {
417414
if (event.button !== 0) return;
418-
event.preventDefault();
419415
event.currentTarget.setPointerCapture(event.pointerId);
420416
(event.currentTarget.parentElement as HTMLElement | null)?.focus();
421417
pointerActive.current = true;

0 commit comments

Comments
 (0)