iOS demo for the p2p-webrtc video-transform example

This commit is contained in:
Filipi Fuchter
2025-04-04 16:40:52 -03:00
parent 6466573b84
commit a1578bd67a
33 changed files with 1887 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import Foundation
class SettingsManager {
private static let preferencesKey = "settingsPreference"
static func getSettings() -> SettingsPreference {
if let data = UserDefaults.standard.data(forKey: preferencesKey),
let settings = try? JSONDecoder().decode(SettingsPreference.self, from: data) {
return settings
} else {
// default values in case we don't have any settings
return SettingsPreference(enableMic: true, enableCam: true, backendURL: "http://YOUR_IP:7860")
}
}
static func updateSettings(settings: SettingsPreference) {
if let data = try? JSONEncoder().encode(settings) {
UserDefaults.standard.set(data, forKey: preferencesKey)
}
}
}

View File

@@ -0,0 +1,9 @@
import Foundation
struct SettingsPreference: Codable {
var selectedMic: String?
var enableMic: Bool
var enableCam: Bool
var backendURL: String
}

View File

@@ -0,0 +1,82 @@
import SwiftUI
struct SettingsView: View {
@EnvironmentObject private var model: CallContainerModel
@Binding var showingSettings: Bool
@State private var isMicEnabled: Bool = true
@State private var isCamEnabled: Bool = true
@State private var backendURL: String = ""
var body: some View {
NavigationView {
Form {
Section {
List(model.availableMics, id: \.self.id.id) { mic in
Button(action: {
model.selectMic(mic.id)
}) {
HStack {
Text(mic.name)
Spacer()
if mic.id == model.selectedMic {
Image(systemName: "checkmark")
}
}
}
}
} header: {
VStack(alignment: .leading) {
Text("Audio Settings")
Text("(No selection = system default)")
}
}
Section(header: Text("Start options")) {
Toggle("Enable Microphone", isOn: $isMicEnabled)
Toggle("Enable Cam", isOn: $isCamEnabled)
}
Section(header: Text("Server")) {
TextField("Backend URL", text: $backendURL)
.keyboardType(.URL)
}
}
.navigationTitle("Settings")
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Close") {
self.saveSettings()
self.showingSettings = false
}
}
}
.onAppear {
self.loadSettings()
}
}
}
private func saveSettings() {
let newSettings = SettingsPreference(
selectedMic: model.selectedMic?.id,
enableMic: isMicEnabled,
enableCam: isCamEnabled,
backendURL: backendURL
)
SettingsManager.updateSettings(settings: newSettings)
}
private func loadSettings() {
let savedSettings = SettingsManager.getSettings()
self.isMicEnabled = savedSettings.enableMic
self.isCamEnabled = savedSettings.enableCam
self.backendURL = savedSettings.backendURL
}
}
#Preview {
let mockModel = MockCallContainerModel()
let result = SettingsView(showingSettings: .constant(true)).environmentObject(mockModel as CallContainerModel)
return result
}