Skip to content

Commit b8bd916

Browse files
committed
Send touch edges on low latency RTC input
1 parent 1986f2f commit b8bd916

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

client/src/app/AppShell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ export function AppShell({
849849
sendControl(
850850
selectedSimulator.udid,
851851
{ type: "touch", ...coords, phase },
852-
{ realtime: phase === "moved" },
852+
{ realtime: true },
853853
);
854854
},
855855
onTouchPreview: showTouchIndicator,

client/src/features/input/usePointerInput.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function usePointerInput({
3333
onTouchPreview,
3434
}: UsePointerInputOptions) {
3535
const activePointerRef = useRef<number | null>(null);
36+
const sentMoveThisFrameRef = useRef(false);
3637
const moveFrameRef = useRef<number>(0);
3738
const panningRef = useRef<{
3839
startX: number;
@@ -52,17 +53,34 @@ export function usePointerInput({
5253
}, []);
5354

5455
function queueMove(coords: Point) {
56+
if (!sentMoveThisFrameRef.current) {
57+
sentMoveThisFrameRef.current = true;
58+
onTouch("moved", coords);
59+
if (!moveFrameRef.current) {
60+
moveFrameRef.current = requestAnimationFrame(() => {
61+
moveFrameRef.current = 0;
62+
sentMoveThisFrameRef.current = false;
63+
const nextCoords = queuedMoveRef.current;
64+
queuedMoveRef.current = null;
65+
if (nextCoords) {
66+
queueMove(nextCoords);
67+
}
68+
});
69+
}
70+
return;
71+
}
5572
queuedMoveRef.current = coords;
5673
if (moveFrameRef.current) {
5774
return;
5875
}
5976

6077
moveFrameRef.current = requestAnimationFrame(() => {
6178
moveFrameRef.current = 0;
79+
sentMoveThisFrameRef.current = false;
6280
const nextCoords = queuedMoveRef.current;
6381
queuedMoveRef.current = null;
6482
if (nextCoords) {
65-
onTouch("moved", nextCoords);
83+
queueMove(nextCoords);
6684
}
6785
});
6886
}
@@ -73,6 +91,7 @@ export function usePointerInput({
7391
moveFrameRef.current = 0;
7492
}
7593
queuedMoveRef.current = null;
94+
sentMoveThisFrameRef.current = false;
7695
}
7796

7897
function startPanning(event: React.PointerEvent<HTMLElement>) {

client/src/features/stream/streamWorkerClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class WebRtcStreamClient implements StreamClientBackend {
162162
const realtimeInputChannel = peerConnection.createDataChannel(
163163
WEBRTC_REALTIME_INPUT_CHANNEL_LABEL,
164164
{
165-
maxRetransmits: 0,
165+
maxRetransmits: 1,
166166
ordered: false,
167167
},
168168
);

0 commit comments

Comments
 (0)