Skip to content

Commit a06980a

Browse files
committed
fix(web): limit device input fix to non-primary buttons
1 parent 708cb29 commit a06980a

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ afterEach(async () => {
5959
});
6060

6161
async function setup(h264 = false) {
62+
const touches: unknown[] = [];
6263
vi.useFakeTimers();
6364
vi.stubGlobal("window", globalThis);
6465
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
@@ -109,7 +110,11 @@ async function setup(h264 = false) {
109110
sockets.push(this);
110111
}
111112
onmessage?: (event: { data: ArrayBuffer }) => void;
112-
send() {}
113+
send(packet: Uint8Array) {
114+
if (packet[0] === 0x03) {
115+
touches.push(JSON.parse(new TextDecoder().decode(packet.subarray(1))));
116+
}
117+
}
113118
close() {}
114119
},
115120
);
@@ -150,6 +155,7 @@ async function setup(h264 = false) {
150155
return {
151156
images,
152157
view,
158+
touches,
153159
configure() {
154160
const json = new TextEncoder().encode(
155161
JSON.stringify({ width: 400, height: 800, orientation: "portrait" }),
@@ -167,6 +173,39 @@ async function setup(h264 = false) {
167173
};
168174
}
169175

176+
it.each([1, 2])(
177+
"ignores button %i gestures and still forwards the next primary drag",
178+
async (button) => {
179+
const { touches, configure } = await setup();
180+
await act(async () => configure());
181+
const viewport = renderer!.root.findByType("canvas").parent!;
182+
const currentTarget = {
183+
setPointerCapture() {},
184+
parentElement: { focus() {} },
185+
getBoundingClientRect: () => ({ left: 20, top: 40, width: 400, height: 800 }),
186+
};
187+
const event = { button, pointerId: 1, currentTarget, clientX: 120, clientY: 640 };
188+
await act(async () => {
189+
viewport.props.onPointerDown(event);
190+
viewport.props.onPointerMove({ ...event, clientY: 240 });
191+
viewport.props.onPointerUp({ ...event, clientY: 240 });
192+
});
193+
expect(touches).toEqual([]);
194+
195+
await act(async () => {
196+
viewport.props.onPointerDown({ ...event, button: 0 });
197+
viewport.props.onPointerMove({ ...event, button: 0, clientY: 240 });
198+
viewport.props.onPointerUp({ ...event, button: 0, clientY: 240 });
199+
viewport.props.onPointerMove({ ...event, button: 0, clientY: 440 });
200+
});
201+
expect(touches).toEqual([
202+
{ type: "begin", x: 0.25, y: 0.75 },
203+
{ type: "move", x: 0.25, y: 0.25 },
204+
{ type: "end", x: 0.25, y: 0.25 },
205+
]);
206+
},
207+
);
208+
170209
it("removes MJPEG requests while hidden and reconnects when shown", async () => {
171210
const { images, view } = await setup();
172211
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)