feat(voice): add iOS VAD runtime support

This commit is contained in:
Edison Jwa
2026-05-21 20:51:45 +09:00
parent 171baf6e41
commit 6af4ecab0f
73 changed files with 11529 additions and 1249 deletions
+62 -49
View File
@@ -23,60 +23,73 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:chanora_flutter/src/rust/api.dart' as rust;
import 'package:chanora_flutter/src/rust/frb_generated.dart';
const _runE2e = bool.fromEnvironment('CHANORA_RUN_E2E');
const _skipReason =
'Set --dart-define=CHANORA_RUN_E2E=true with a built native bridge to run '
'network end-to-end acceptance.';
void main() {
setUpAll(() async {
if (!_runE2e) return;
await RustLib.init();
});
test('connect → start_audio → PTT cycle → disconnect', () async {
// Defensive cleanup in case a previous test left state.
try {
test(
'connect → start_audio → PTT cycle → disconnect',
() async {
// Defensive cleanup in case a previous test left state.
try {
await rust.disconnect();
} catch (_) {}
final snap = await rust.connect(
host: 'cn.teamspeak.app',
nickname: 'ChanoraBetaTest',
password: '',
);
expect(snap.serverName, isNotEmpty);
expect(snap.channels, isNotEmpty);
await rust.voiceJoin(channelId: snap.channels.first.id, password: '');
// Zero out the release tail so set_ptt(false) takes effect
// synchronously — the default 200 ms tail (SDD-096) would
// otherwise delay the assertion below.
await rust.setReleaseTailMs(ms: 0);
// Initial stats: PTT off, no frames sent yet.
final s0 = await rust.audioStats();
expect(s0.pttActive, isFalse);
expect(s0.framesSent, 0);
// Press PTT, wait ~250 ms, then read stats. If the host has a
// real microphone the encoder will emit ~10-12 frames. If the
// host has only a null source (typical headless), capture will
// have logged a warning at startAudio time and run in
// playback-only mode; framesSent stays at 0. Either outcome is
// a successful test of the wiring — what we actually verify
// here is that the PTT flag changes and no exception is thrown.
await rust.setPtt(active: true);
await Future<void>.delayed(const Duration(milliseconds: 250));
final s1 = await rust.audioStats();
expect(s1.pttActive, isTrue);
await rust.setPtt(active: false);
// Give the release-tail (set to 0 above) one tick to settle.
await Future<void>.delayed(const Duration(milliseconds: 50));
final s2 = await rust.audioStats();
expect(s2.pttActive, isFalse);
await rust.disconnect();
} catch (_) {}
final connectedAfter = await rust.isConnected();
expect(connectedAfter, isFalse);
final snap = await rust.connect(
host: 'cn.teamspeak.app',
nickname: 'ChanoraBetaTest',
password: '',
);
expect(snap.serverName, isNotEmpty);
expect(snap.channels, isNotEmpty);
await rust.voiceJoin(channelId: snap.channels.first.id, password: '');
// Zero out the release tail so set_ptt(false) takes effect
// synchronously — the default 200 ms tail (SDD-096) would
// otherwise delay the assertion below.
await rust.setReleaseTailMs(ms: 0);
// Initial stats: PTT off, no frames sent yet.
final s0 = await rust.audioStats();
expect(s0.pttActive, isFalse);
expect(s0.framesSent, 0);
// Press PTT, wait ~250 ms, then read stats. If the host has a
// real microphone the encoder will emit ~10-12 frames. If the
// host has only a null source (typical headless), capture will
// have logged a warning at startAudio time and run in
// playback-only mode; framesSent stays at 0. Either outcome is
// a successful test of the wiring — what we actually verify
// here is that the PTT flag changes and no exception is thrown.
await rust.setPtt(active: true);
await Future<void>.delayed(const Duration(milliseconds: 250));
final s1 = await rust.audioStats();
expect(s1.pttActive, isTrue);
await rust.setPtt(active: false);
// Give the release-tail (set to 0 above) one tick to settle.
await Future<void>.delayed(const Duration(milliseconds: 50));
final s2 = await rust.audioStats();
expect(s2.pttActive, isFalse);
await rust.disconnect();
final connectedAfter = await rust.isConnected();
expect(connectedAfter, isFalse);
// ignore: avoid_print
print('Beta E2E: TX=${s1.framesSent} frames, RX=${s1.framesReceived} frames');
}, timeout: const Timeout(Duration(seconds: 30)));
// ignore: avoid_print
print(
'Beta E2E: TX=${s1.framesSent} frames, RX=${s1.framesReceived} frames',
);
},
timeout: const Timeout(Duration(seconds: 30)),
skip: _runE2e ? false : _skipReason,
);
}