feat(ios): ship iOS SwiftUI client (VoiceCatiOS)
Full SwiftUI app at clients/apple/iOS/VoiceCatiOS.xcodeproj:
- 24 Swift source files: AppState + SessionState (@Observable @MainActor),
AudioSessionManager (AVAudioSession owner + interruption/route handling),
ServerListStore/SavedServer (App Group container + Keychain sharing),
and 14 SwiftUI views covering the full feature set
- NavigationSplitView on iPad, TabView on iPhone (horizontalSizeClass)
- Channel tree via OutlineGroup, user list with context menu admin actions
- PTT via DragGesture(minimumDistance: 0) + @GestureState
- onEvent closures hop to MainActor via Task { @MainActor in ... }
- App Group: group.cat.voice.VoiceCat (shared with future ReplayKit extension)
C ABI: add vc_audio_suspend / vc_audio_resume (AudioEngine::suspend/resume)
called by AudioSessionManager on AVAudioSession interruption events.
XCFramework: add ios-arm64 and ios-arm64-simulator slices to build-xcframework.sh;
Package.swift gains .iOS(.v17) platform; CMakePresets.json adds apple-ios /
apple-ios-sim presets with arm64-ios / arm64-ios-simulator vcpkg triplets.
Verified: xcodebuild -target VoiceCatiOS -sdk iphonesimulator26.5 BUILD SUCCEEDED.
This commit is contained in:
@@ -75,6 +75,16 @@ if(VOICECAT_USE_VCPKG_DEPS)
|
||||
|
||||
target_compile_definitions(voicecat PUBLIC VOICECAT_HAS_OPUS VOICECAT_HAS_AUDIO)
|
||||
|
||||
# On iOS, miniaudio's AVFoundation backend includes Objective-C headers (AVFoundation.h →
|
||||
# Foundation.h). Compiling those as plain C++ fails; setting LANGUAGE OBJCXX for
|
||||
# audio_engine.cpp (the only file that includes miniaudio.h directly) fixes this.
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
||||
set_source_files_properties(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/audio/audio_engine.cpp
|
||||
PROPERTIES LANGUAGE OBJCXX
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# AcceptEx / GetAcceptExSockaddrs live in mswsock; ws2_32 covers the base Winsock API.
|
||||
target_link_libraries(voicecat PRIVATE ws2_32 mswsock)
|
||||
|
||||
@@ -467,6 +467,13 @@ VC_API void vc_free_account_list(vc_account_list* list);
|
||||
/* Pull the caller's own permissions (from the last AuthResult). */
|
||||
VC_API vc_result vc_get_permissions(vc_client* c, vc_permissions* out);
|
||||
|
||||
/* AVAudioSession interruption hooks (iOS M6). Pause/resume miniaudio device I/O for
|
||||
* AVAudioSession interruptions (phone call, Siri, etc.) and backgrounding. Call
|
||||
* vc_audio_suspend() when an interruption begins; call vc_audio_resume() after the
|
||||
* session is re-activated. No-op if the audio engine is not running. */
|
||||
VC_API vc_result vc_audio_suspend(vc_client* c);
|
||||
VC_API vc_result vc_audio_resume(vc_client* c);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
@@ -274,6 +274,30 @@ void AudioEngine::stop() {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AudioEngine::suspend() {
|
||||
#ifdef VOICECAT_HAS_AUDIO
|
||||
if (!running_.load(std::memory_order_acquire)) return true;
|
||||
bool ok = true;
|
||||
if (capture_started_) ok &= (ma_device_stop(&capture_device_) == MA_SUCCESS);
|
||||
if (playback_started_) ok &= (ma_device_stop(&playback_device_) == MA_SUCCESS);
|
||||
return ok;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AudioEngine::resume() {
|
||||
#ifdef VOICECAT_HAS_AUDIO
|
||||
if (!running_.load(std::memory_order_acquire)) return true;
|
||||
bool ok = true;
|
||||
if (capture_started_) ok &= (ma_device_start(&capture_device_) == MA_SUCCESS);
|
||||
if (playback_started_) ok &= (ma_device_start(&playback_device_) == MA_SUCCESS);
|
||||
return ok;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void AudioEngine::inject_capture(int kind, const int16_t* pcm, size_t n) {
|
||||
InjectTap* tap;
|
||||
{
|
||||
|
||||
@@ -127,6 +127,12 @@ class AudioEngine {
|
||||
|
||||
bool running() const { return running_.load(std::memory_order_acquire); }
|
||||
|
||||
// Pause/resume miniaudio device I/O (called from vc_audio_suspend/resume for
|
||||
// AVAudioSession interruptions on iOS). Thread-safe via ma_device_stop/start.
|
||||
// Returns true on success; false if a device stop/start fails.
|
||||
bool suspend();
|
||||
bool resume();
|
||||
|
||||
// Enumerate input or output devices (for UI pickers / vc_list_devices). Static: works
|
||||
// before any AudioEngine instance is running (device pickers need to populate pre-connect).
|
||||
// Inits a throwaway ma_context if VOICECAT_HAS_AUDIO; returns {} otherwise. See DeviceInfo
|
||||
|
||||
@@ -1399,6 +1399,14 @@ vc_result vc_client::get_remote_stream(uint32_t user_id, uint32_t stream_id,
|
||||
return VC_OK;
|
||||
}
|
||||
|
||||
vc_result vc_client::audio_suspend() {
|
||||
return audio_engine_.suspend() ? VC_OK : VC_ERR_AUDIO;
|
||||
}
|
||||
|
||||
vc_result vc_client::audio_resume() {
|
||||
return audio_engine_.resume() ? VC_OK : VC_ERR_AUDIO;
|
||||
}
|
||||
|
||||
vc_result vc_client::get_stream_audio_config(uint32_t user_id, uint32_t stream_id,
|
||||
vc_audio_config* out) {
|
||||
if (state_net_.load(std::memory_order_acquire) != VC_STATE_CONNECTED) return VC_ERR_NOT_CONNECTED;
|
||||
@@ -1863,5 +1871,7 @@ vc_result vc_client::delete_account(const char*) { return VC_ERR_NOT_IMPLEMENTED
|
||||
vc_result vc_client::list_accounts() { return VC_ERR_NOT_IMPLEMENTED; }
|
||||
vc_result vc_client::get_account_list(vc_account_list*) { return VC_ERR_NOT_IMPLEMENTED; }
|
||||
vc_result vc_client::get_permissions(vc_permissions*) { return VC_ERR_NOT_IMPLEMENTED; }
|
||||
vc_result vc_client::audio_suspend() { return VC_ERR_NOT_IMPLEMENTED; }
|
||||
vc_result vc_client::audio_resume() { return VC_ERR_NOT_IMPLEMENTED; }
|
||||
|
||||
#endif // VOICECAT_HAS_NET
|
||||
|
||||
@@ -57,6 +57,8 @@ struct vc_client {
|
||||
bool noise_reduction);
|
||||
vc_result get_remote_stream(uint32_t user_id, uint32_t stream_id,
|
||||
vc_remote_stream_state* out);
|
||||
vc_result audio_suspend();
|
||||
vc_result audio_resume();
|
||||
|
||||
vc_result send_text(vc_text_scope scope, uint32_t target_id, const char* utf8);
|
||||
|
||||
|
||||
@@ -295,4 +295,14 @@ vc_result vc_get_permissions(vc_client* c, vc_permissions* out) {
|
||||
return c->get_permissions(out);
|
||||
}
|
||||
|
||||
vc_result vc_audio_suspend(vc_client* c) {
|
||||
if (c == nullptr) return VC_ERR_INVALID_ARG;
|
||||
return c->audio_suspend();
|
||||
}
|
||||
|
||||
vc_result vc_audio_resume(vc_client* c) {
|
||||
if (c == nullptr) return VC_ERR_INVALID_ARG;
|
||||
return c->audio_resume();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user