Commit fd6dc03
committed
Summary of Additional Fixes
1. Idempotency guard in _startRecorderWithDevice()
(src/index.ts:894-898)
Added early return guard to prevent multiple begin() calls: if
(this.recorderStarted || this._hasLiveRecorderStream()) {
console.debug('_startRecorderWithDevice: already started, skipping');
return; }
2. Concurrency protection in requestPermission()
(src/wavtools/lib/wav_recorder.js:246-274)
Added _permissionPromise deduplication to prevent concurrent
getUserMedia calls: if (this._permissionPromise) { return
this._permissionPromise; } this._permissionPromise = (async () => { //
... getUserMedia logic })(); return this._permissionPromise;
3. Skip first device callback flag (src/index.ts:286, 368, 893,
1410-1418, 1497)
Added _skipFirstDeviceCallback flag to explicitly skip device
switching on the first callback after starting the recorder: - Set to
true in audioInputConnect() before _setupDeviceChangeListener() -
Checked and cleared in deviceChangeListener callback - Reset in
_performDisconnectCleanup()
4. Set useSystemDefaultDevice correctly (src/index.ts:877-884)
When starting with no specific device, mark useSystemDefaultDevice =
true so the device change listener logic works correctly.
Final Flow
Now when audioInput is enabled: 1. audioInputConnect() →
_startRecorderWithDevice() → begin() → single getUserMedia 2. Set
_skipFirstDeviceCallback = true 3. _setupDeviceChangeListener() →
listDevices() → requestPermission() → skipped (has permission) 4.
First device callback → skipped (flag is set), flag cleared,
lastKnownSystemDefaultDeviceKey initialized 5. Future callbacks work
normally for real device changes
This reduces iOS Safari connection time from ~10s (3× getUserMedia) to
~2-3s (1× getUserMedia).1 parent c611247 commit fd6dc03
2 files changed
+61
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
285 | 287 | | |
286 | 288 | | |
287 | 289 | | |
| |||
363 | 365 | | |
364 | 366 | | |
365 | 367 | | |
| 368 | + | |
366 | 369 | | |
367 | 370 | | |
368 | 371 | | |
| |||
872 | 875 | | |
873 | 876 | | |
874 | 877 | | |
875 | | - | |
| 878 | + | |
876 | 879 | | |
877 | 880 | | |
878 | | - | |
879 | | - | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
880 | 889 | | |
881 | 890 | | |
882 | 891 | | |
| 892 | + | |
| 893 | + | |
883 | 894 | | |
884 | 895 | | |
885 | 896 | | |
| |||
888 | 899 | | |
889 | 900 | | |
890 | 901 | | |
891 | | - | |
| 902 | + | |
| 903 | + | |
892 | 904 | | |
893 | 905 | | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
894 | 912 | | |
895 | 913 | | |
896 | 914 | | |
| |||
1379 | 1397 | | |
1380 | 1398 | | |
1381 | 1399 | | |
1382 | | - | |
| 1400 | + | |
1383 | 1401 | | |
1384 | 1402 | | |
1385 | 1403 | | |
| |||
1389 | 1407 | | |
1390 | 1408 | | |
1391 | 1409 | | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1392 | 1420 | | |
1393 | 1421 | | |
1394 | 1422 | | |
| |||
1466 | 1494 | | |
1467 | 1495 | | |
1468 | 1496 | | |
| 1497 | + | |
1469 | 1498 | | |
1470 | 1499 | | |
1471 | 1500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
237 | 239 | | |
238 | 240 | | |
239 | 241 | | |
240 | | - | |
| 242 | + | |
| 243 | + | |
241 | 244 | | |
242 | 245 | | |
243 | 246 | | |
244 | 247 | | |
245 | 248 | | |
246 | 249 | | |
247 | 250 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
259 | 254 | | |
260 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
261 | 275 | | |
262 | 276 | | |
263 | 277 | | |
| |||
0 commit comments