jetpackjules commited on
Commit
93bb0df
·
verified ·
1 Parent(s): fc5c497

Avoid auto-connect signaling race

Browse files
Files changed (1) hide show
  1. main.js +10 -1
main.js CHANGED
@@ -1182,7 +1182,16 @@ function renderRobotList(robots) {
1182
  // to make. Start it automatically on LAN and through the HF relay alike.
1183
  const onlyRobot = robots.length === 1 ? robots[0] : null;
1184
  if (!selectedRobotId && onlyRobot && !onlyRobot.busy) {
1185
- queueMicrotask(() => pickRobot(onlyRobot));
 
 
 
 
 
 
 
 
 
1186
  }
1187
  }
1188
 
 
1182
  // to make. Start it automatically on LAN and through the HF relay alike.
1183
  const onlyRobot = robots.length === 1 ? robots[0] : null;
1184
  if (!selectedRobotId && onlyRobot && !onlyRobot.busy) {
1185
+ // Do not start from inside the SDK's robotsChanged dispatch. The
1186
+ // signaling read-loop may still be finishing connect(); negotiating
1187
+ // in that same turn can process the SDP twice and leave the peer in
1188
+ // `stable` before setRemoteDescription(answer). A short task delay
1189
+ // starts from a settled connected state and matches a real card tap.
1190
+ setTimeout(() => {
1191
+ if (!selectedRobotId && robot.state === "connected") {
1192
+ pickRobot(onlyRobot);
1193
+ }
1194
+ }, 750);
1195
  }
1196
  }
1197