Three iOS client problems fixed plus a new core stereo-mic capture ABI: 1. Channel-id sync bug (mic button permanently dimmed): SessionState never synced currentChannelId from the self user's channelId on connect, so the mic button (gated on currentChannelId == 0) stayed dimmed. Added syncSelfChannel() (mirrors macOS MainWindowController.swift:461,491,522); called from init/.channelList/.userJoined/.userLeft/.userUpdated/.joinResult. Added applyServerMuteState() + serverMuted/serverDeafened to VoiceState. 2. Join/Leave Voice button: replaced icon-only mic toggle with explicit text button (parity with macOS). Mute/deafen disable when not in voice. 3. IOSAudioRouter.swift (new): full AVAudioSession routing layer — input port selection, built-in mic orientation/polar patterns, Bluetooth HFP/A2DP/Off modes, Standard/Raw mic processing, stereo capture, AirPlay, UserDefaults persistence. AudioSessionManager delegates to it. 4. Core stereo-mic capture (append-only ABI): vc_set_capture_channels() lets the core open the mic device in stereo (2-ch interleaved). LocalStream gains capture_channels; ensure_audio_running reads it; audio_engine.cpp capture_accum_ + on_capture updated to channel-aware accumulation. Test test_stereo_mic_capture (headless, L!=R stereo round-trip). Swift wrapper VoiceCatClient.setCaptureChannels. 5. Settings UI rework: AVAudioSession-derived input/output tree replaces miniaudio device picker. 6. iOS deployment target raised to 18.0 (Package.swift + project.pbxproj). swift-tools-version 6.0 with swiftLanguageModes .v5. Docs: tech-stack.md, architecture.md, voice.md, roadmap.md, building.md updated; stale 'vc_audio_suspend/resume deferred' claims corrected. Verified: ctest --preset dev 21/21 green; swift test 6/6 green; xcodebuild -target VoiceCatiOS -sdk iphonesimulator BUILD SUCCEEDED.
135 lines
5.1 KiB
Swift
135 lines
5.1 KiB
Swift
import SwiftUI
|
|
import VoiceCatCore
|
|
|
|
struct VoiceControlsView: View {
|
|
@Bindable var session: SessionState
|
|
|
|
var body: some View {
|
|
HStack(spacing: 20) {
|
|
// Join/Leave Voice button (mirrors macOS micToggleButton)
|
|
if session.voiceState.inputMode == .pushToTalk {
|
|
PTTButton(session: session)
|
|
} else {
|
|
Button {
|
|
if session.voiceState.micActive {
|
|
session.stopMicStream()
|
|
} else {
|
|
session.startMicStream()
|
|
}
|
|
} label: {
|
|
Text(session.voiceState.micActive ? "Leave Voice" : "Join Voice")
|
|
.font(.body.weight(.semibold))
|
|
.frame(minWidth: 110)
|
|
.padding(.vertical, 8)
|
|
.padding(.horizontal, 12)
|
|
.background(session.voiceState.micActive ? Color.green.opacity(0.2) : Color.accentColor.opacity(0.15), in: RoundedRectangle(cornerRadius: 8))
|
|
.foregroundStyle(session.voiceState.micActive ? .green : .accentColor)
|
|
}
|
|
.disabled(session.currentChannelId == 0)
|
|
.accessibilityLabel(session.voiceState.micActive ? "Leave Voice — stop sending microphone audio" : "Join Voice — start sending microphone audio")
|
|
}
|
|
|
|
// Level meter
|
|
LevelMeterView(level: session.voiceState.level)
|
|
.frame(width: 80, height: 8)
|
|
.accessibilityHidden(true)
|
|
|
|
Spacer()
|
|
|
|
// Self mute (disabled when not in voice)
|
|
Button {
|
|
session.setMute(!session.voiceState.selfMuted, deafened: session.voiceState.selfDeafened)
|
|
} label: {
|
|
Image(systemName: session.voiceState.selfMuted ? "mic.slash" : "mic")
|
|
.font(.title3)
|
|
.foregroundStyle(session.voiceState.selfMuted ? .red : .primary)
|
|
}
|
|
.disabled(!session.voiceState.micActive)
|
|
.accessibilityLabel(session.voiceState.selfMuted ? "Unmute microphone" : "Mute microphone")
|
|
|
|
// Self deafen (disabled when not in voice)
|
|
Button {
|
|
session.setMute(session.voiceState.selfMuted, deafened: !session.voiceState.selfDeafened)
|
|
} label: {
|
|
Image(systemName: session.voiceState.selfDeafened ? "headphones.slash" : "headphones")
|
|
.font(.title3)
|
|
.foregroundStyle(session.voiceState.selfDeafened ? .red : .primary)
|
|
}
|
|
.disabled(!session.voiceState.micActive)
|
|
.accessibilityLabel(session.voiceState.selfDeafened ? "Undeafen" : "Deafen")
|
|
|
|
// Disconnect
|
|
Button(role: .destructive) {
|
|
session.stopMicStream()
|
|
session.client.disconnect()
|
|
} label: {
|
|
Image(systemName: "phone.down.fill")
|
|
.font(.title3)
|
|
.foregroundStyle(.red)
|
|
}
|
|
.accessibilityLabel("Disconnect from server")
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.background(.bar)
|
|
}
|
|
}
|
|
|
|
// MARK: - PTT Button (DragGesture instead of NSEvent on iOS)
|
|
|
|
private struct PTTButton: View {
|
|
@Bindable var session: SessionState
|
|
@GestureState private var isPressing = false
|
|
|
|
var body: some View {
|
|
Circle()
|
|
.fill(isPressing ? Color.blue : Color(.systemGray4))
|
|
.frame(width: 44, height: 44)
|
|
.overlay {
|
|
Image(systemName: "mic.fill")
|
|
.foregroundStyle(isPressing ? .white : .primary)
|
|
}
|
|
.gesture(
|
|
DragGesture(minimumDistance: 0)
|
|
.updating($isPressing) { _, state, _ in state = true }
|
|
.onChanged { _ in
|
|
if !isPressing { return }
|
|
if !session.voiceState.micActive { session.startMicStream() }
|
|
session.setPushToTalk(true)
|
|
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
|
}
|
|
.onEnded { _ in
|
|
session.setPushToTalk(false)
|
|
session.stopMicStream()
|
|
}
|
|
)
|
|
.accessibilityLabel("Push to talk, hold to transmit")
|
|
.accessibilityAddTraits(.isButton)
|
|
}
|
|
}
|
|
|
|
// MARK: - Level Meter
|
|
|
|
private struct LevelMeterView: View {
|
|
let level: Float
|
|
|
|
var body: some View {
|
|
GeometryReader { geo in
|
|
ZStack(alignment: .leading) {
|
|
RoundedRectangle(cornerRadius: 4)
|
|
.fill(Color(.systemGray5))
|
|
RoundedRectangle(cornerRadius: 4)
|
|
.fill(levelColor)
|
|
.frame(width: geo.size.width * CGFloat(min(level * 10, 1.0)))
|
|
.animation(.linear(duration: 0.05), value: level)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var levelColor: Color {
|
|
if level > 0.15 { return .orange }
|
|
if level > 0.05 { return .green }
|
|
return .green.opacity(0.5)
|
|
}
|
|
}
|