Skip to content

Commit 2fb2cef

Browse files
committed
Restore ordered touch control path
1 parent b8bd916 commit 2fb2cef

4 files changed

Lines changed: 6 additions & 85 deletions

File tree

client/src/app/AppShell.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ import { useKeyboardInput } from "../features/input/useKeyboardInput";
3939
import { usePointerInput } from "../features/input/usePointerInput";
4040
import { simulatorRuntimeLabel } from "../features/simulators/simulatorDisplay";
4141
import { useSimulatorList } from "../features/simulators/useSimulatorList";
42-
import {
43-
sendWebRtcControlMessage,
44-
sendWebRtcRealtimeControlMessage,
45-
} from "../features/stream/streamWorkerClient";
42+
import { sendWebRtcControlMessage } from "../features/stream/streamWorkerClient";
4643
import { useLiveStream } from "../features/stream/useLiveStream";
4744
import { DebugPanel } from "../features/toolbar/DebugPanel";
4845
import { Toolbar } from "../features/toolbar/Toolbar";
@@ -846,11 +843,7 @@ export function AppShell({
846843
setAccessibilitySelectedId("");
847844
setAccessibilityHoveredId(null);
848845
}
849-
sendControl(
850-
selectedSimulator.udid,
851-
{ type: "touch", ...coords, phase },
852-
{ realtime: true },
853-
);
846+
sendControl(selectedSimulator.udid, { type: "touch", ...coords, phase });
854847
},
855848
onTouchPreview: showTouchIndicator,
856849
pan,
@@ -1002,20 +995,10 @@ export function AppShell({
1002995
return state;
1003996
}, []);
1004997

1005-
function sendControl(
1006-
udid: string,
1007-
message: ControlMessage,
1008-
options: { realtime?: boolean } = {},
1009-
): boolean {
998+
function sendControl(udid: string, message: ControlMessage): boolean {
1010999
setLocalError("");
10111000
const encoded = JSON.stringify(message);
1012-
const sent = options.realtime
1013-
? sendWebRtcRealtimeControlMessage(encoded)
1014-
: sendWebRtcControlMessage(encoded);
1015-
if (sent) {
1016-
return true;
1017-
}
1018-
if (options.realtime) {
1001+
if (sendWebRtcControlMessage(encoded)) {
10191002
return true;
10201003
}
10211004
const state = ensureControlSocket(udid);

client/src/features/input/usePointerInput.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export function usePointerInput({
3333
onTouchPreview,
3434
}: UsePointerInputOptions) {
3535
const activePointerRef = useRef<number | null>(null);
36-
const sentMoveThisFrameRef = useRef(false);
3736
const moveFrameRef = useRef<number>(0);
3837
const panningRef = useRef<{
3938
startX: number;
@@ -53,34 +52,17 @@ export function usePointerInput({
5352
}, []);
5453

5554
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-
}
7255
queuedMoveRef.current = coords;
7356
if (moveFrameRef.current) {
7457
return;
7558
}
7659

7760
moveFrameRef.current = requestAnimationFrame(() => {
7861
moveFrameRef.current = 0;
79-
sentMoveThisFrameRef.current = false;
8062
const nextCoords = queuedMoveRef.current;
8163
queuedMoveRef.current = null;
8264
if (nextCoords) {
83-
queueMove(nextCoords);
65+
onTouch("moved", nextCoords);
8466
}
8567
});
8668
}
@@ -91,7 +73,6 @@ export function usePointerInput({
9173
moveFrameRef.current = 0;
9274
}
9375
queuedMoveRef.current = null;
94-
sentMoveThisFrameRef.current = false;
9576
}
9677

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

client/src/features/stream/streamWorkerClient.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ import type {
1010

1111
const HAVE_CURRENT_DATA = 2;
1212
const WEBRTC_CONTROL_CHANNEL_LABEL = "simdeck-control";
13-
const WEBRTC_REALTIME_INPUT_CHANNEL_LABEL = "simdeck-input";
1413
const WEBRTC_TELEMETRY_CHANNEL_LABEL = "simdeck-telemetry";
1514
const WEBRTC_FIRST_FRAME_TIMEOUT_MS = 10000;
1615
const WEBRTC_STALLED_FRAME_TIMEOUT_MS = 8000;
1716
const WEBRTC_REMOTE_DISCONNECTED_GRACE_MS = 3000;
18-
const WEBRTC_REALTIME_INPUT_BUFFER_LIMIT = 1024;
1917

2018
let activeWebRtcControlChannel: RTCDataChannel | null = null;
21-
let activeWebRtcRealtimeInputChannel: RTCDataChannel | null = null;
2219
let activeWebRtcTelemetryChannel: RTCDataChannel | null = null;
2320
let activeStreamClient: StreamWorkerClient | null = null;
2421

@@ -28,20 +25,6 @@ export function sendWebRtcControlMessage(encoded: string): boolean {
2825
return sendDataChannelMessage(activeWebRtcControlChannel, encoded);
2926
}
3027

31-
export function sendWebRtcRealtimeControlMessage(encoded: string): boolean {
32-
if (activeWebRtcRealtimeInputChannel?.readyState !== "open") {
33-
return false;
34-
}
35-
if (
36-
activeWebRtcRealtimeInputChannel.bufferedAmount >
37-
WEBRTC_REALTIME_INPUT_BUFFER_LIMIT
38-
) {
39-
return true;
40-
}
41-
activeWebRtcRealtimeInputChannel.send(encoded);
42-
return true;
43-
}
44-
4528
export function sendWebRtcClientStats(stats: unknown): boolean {
4629
return sendDataChannelMessage(
4730
activeWebRtcTelemetryChannel,
@@ -90,7 +73,6 @@ class WebRtcStreamClient implements StreamClientBackend {
9073
private lastVideoFrameAt = 0;
9174
private peerConnection: RTCPeerConnection | null = null;
9275
private reconnectTimeout = 0;
93-
private realtimeInputChannel: RTCDataChannel | null = null;
9476
private remoteMode = false;
9577
private reportedVideoConfig = false;
9678
private shouldReconnect = false;
@@ -159,20 +141,6 @@ class WebRtcStreamClient implements StreamClientBackend {
159141
activeWebRtcControlChannel = null;
160142
}
161143
});
162-
const realtimeInputChannel = peerConnection.createDataChannel(
163-
WEBRTC_REALTIME_INPUT_CHANNEL_LABEL,
164-
{
165-
maxRetransmits: 1,
166-
ordered: false,
167-
},
168-
);
169-
this.realtimeInputChannel = realtimeInputChannel;
170-
activeWebRtcRealtimeInputChannel = realtimeInputChannel;
171-
realtimeInputChannel.addEventListener("close", () => {
172-
if (activeWebRtcRealtimeInputChannel === realtimeInputChannel) {
173-
activeWebRtcRealtimeInputChannel = null;
174-
}
175-
});
176144
const telemetryChannel = peerConnection.createDataChannel(
177145
WEBRTC_TELEMETRY_CHANNEL_LABEL,
178146
{
@@ -345,11 +313,6 @@ class WebRtcStreamClient implements StreamClientBackend {
345313
activeWebRtcControlChannel = null;
346314
}
347315
this.controlChannel = null;
348-
this.realtimeInputChannel?.close();
349-
if (activeWebRtcRealtimeInputChannel === this.realtimeInputChannel) {
350-
activeWebRtcRealtimeInputChannel = null;
351-
}
352-
this.realtimeInputChannel = null;
353316
this.telemetryChannel?.close();
354317
if (activeWebRtcTelemetryChannel === this.telemetryChannel) {
355318
activeWebRtcTelemetryChannel = null;

server/src/transport/webrtc.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use webrtc::track::track_local::TrackLocalWriter;
3636
const ANNEX_B_START_CODE: &[u8] = &[0, 0, 0, 1];
3737
const DEFAULT_STUN_URL: &str = "stun:stun.l.google.com:19302";
3838
const WEBRTC_CONTROL_CHANNEL_LABEL: &str = "simdeck-control";
39-
const WEBRTC_REALTIME_INPUT_CHANNEL_LABEL: &str = "simdeck-input";
4039
const WEBRTC_TELEMETRY_CHANNEL_LABEL: &str = "simdeck-telemetry";
4140
const WEBRTC_BOOTSTRAP_KEYFRAME_INTERVAL: Duration = Duration::from_millis(150);
4241
const WEBRTC_BOOTSTRAP_KEYFRAME_REPEATS: u8 = 3;
@@ -348,12 +347,7 @@ fn register_control_data_channel(
348347
let udid = udid.clone();
349348
Box::pin(async move {
350349
let label = channel.label();
351-
if !matches!(
352-
label.as_ref(),
353-
WEBRTC_CONTROL_CHANNEL_LABEL
354-
| WEBRTC_REALTIME_INPUT_CHANNEL_LABEL
355-
| WEBRTC_TELEMETRY_CHANNEL_LABEL
356-
) {
350+
if label != WEBRTC_CONTROL_CHANNEL_LABEL && label != WEBRTC_TELEMETRY_CHANNEL_LABEL {
357351
return;
358352
}
359353
attach_control_data_channel(channel, session, state, udid);

0 commit comments

Comments
 (0)