macOS support (#33)
* mac os support 1 * entitlements * fix updateTrack bug * clean * throws on mac * simplify structure * lock
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
@interface LiveKitPlugin : NSObject<FlutterPlugin>
|
||||
@end
|
||||
@@ -1,15 +0,0 @@
|
||||
#import "LiveKitPlugin.h"
|
||||
#if __has_include(<livekit_client/livekit_client-Swift.h>)
|
||||
#import <livekit_client/livekit_client-Swift.h>
|
||||
#else
|
||||
// Support project import fallback if the generated compatibility header
|
||||
// is not copied when this plugin is created as a library.
|
||||
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
|
||||
#import "livekit_client-Swift.h"
|
||||
#endif
|
||||
|
||||
@implementation LiveKitPlugin
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||
[SwiftLiveKitPlugin registerWithRegistrar:registrar];
|
||||
}
|
||||
@end
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../shared_swift/LiveKitPlugin.swift
|
||||
@@ -1,138 +0,0 @@
|
||||
import Flutter
|
||||
import UIKit
|
||||
import WebRTC
|
||||
|
||||
public class SwiftLiveKitPlugin: NSObject, FlutterPlugin {
|
||||
public static func register(with registrar: FlutterPluginRegistrar) {
|
||||
let channel = FlutterMethodChannel(name: "livekit_client", binaryMessenger: registrar.messenger())
|
||||
let instance = SwiftLiveKitPlugin()
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
}
|
||||
|
||||
// https://developer.apple.com/documentation/avfaudio/avaudiosession/category
|
||||
let categoryMap: [String: AVAudioSession.Category] = [
|
||||
"ambient": .ambient,
|
||||
"multiRoute": .multiRoute,
|
||||
"playAndRecord": .playAndRecord,
|
||||
"playback": .playback,
|
||||
"record": .record,
|
||||
"soloAmbient": .soloAmbient,
|
||||
]
|
||||
|
||||
// https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions
|
||||
let categoryOptionsMap: [String: AVAudioSession.CategoryOptions] = [
|
||||
"mixWithOthers": .mixWithOthers,
|
||||
"duckOthers": .duckOthers,
|
||||
"interruptSpokenAudioAndMixWithOthers": .interruptSpokenAudioAndMixWithOthers,
|
||||
"allowBluetooth": .allowBluetooth,
|
||||
"allowBluetoothA2DP": .allowBluetoothA2DP,
|
||||
"allowAirPlay": .allowAirPlay,
|
||||
"defaultToSpeaker": .defaultToSpeaker,
|
||||
// @available(iOS 14.5, *)
|
||||
// "overrideMutedMicrophoneInterruption": .overrideMutedMicrophoneInterruption,
|
||||
]
|
||||
|
||||
// https://developer.apple.com/documentation/avfaudio/avaudiosession/mode
|
||||
let modeMap: [String: AVAudioSession.Mode] = [
|
||||
"default": .default,
|
||||
"gameChat": .gameChat,
|
||||
"measurement": .measurement,
|
||||
"moviePlayback": .moviePlayback,
|
||||
"spokenAudio": .spokenAudio,
|
||||
"videoChat": .videoChat,
|
||||
"videoRecording": .videoRecording,
|
||||
"voiceChat": .voiceChat,
|
||||
"voicePrompt": .voicePrompt,
|
||||
]
|
||||
|
||||
private func categoryOptions(fromFlutter options: [String]) -> AVAudioSession.CategoryOptions {
|
||||
var result: AVAudioSession.CategoryOptions = []
|
||||
for option in categoryOptionsMap {
|
||||
if (options.contains(option.key)) {
|
||||
result.insert(option.value)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public func handleConfigureNativeAudio(args: [String: Any?], result: @escaping FlutterResult) {
|
||||
|
||||
let configuration = RTCAudioSessionConfiguration.webRTC()
|
||||
|
||||
// Category
|
||||
if let string = args["appleAudioCategory"] as? String,
|
||||
let category = categoryMap[string] {
|
||||
configuration.category = category.rawValue
|
||||
print("[LiveKit] Configuring category: ", configuration.category)
|
||||
}
|
||||
|
||||
// CategoryOptions
|
||||
if let strings = args["appleAudioCategoryOptions"] as? [String] {
|
||||
configuration.categoryOptions = categoryOptions(fromFlutter: strings)
|
||||
print("[LiveKit] Configuring categoryOptions: ", strings)
|
||||
}
|
||||
|
||||
// Mode
|
||||
if let string = args["appleAudioMode"] as? String,
|
||||
let mode = modeMap[string] {
|
||||
configuration.mode = mode.rawValue
|
||||
print("[LiveKit] Configuring mode: ", configuration.mode)
|
||||
}
|
||||
|
||||
// get `RTCAudioSession` and lock
|
||||
let rtcSession = RTCAudioSession.sharedInstance()
|
||||
rtcSession.lockForConfiguration()
|
||||
|
||||
var isLocked: Bool = true
|
||||
let unlock = {
|
||||
guard isLocked else {
|
||||
print("[LiveKit] not locked, ignoring unlock")
|
||||
return
|
||||
}
|
||||
rtcSession.unlockForConfiguration()
|
||||
isLocked = false
|
||||
}
|
||||
|
||||
// always `unlock()` when exiting scope, calling multiple times has no side-effect
|
||||
defer {
|
||||
unlock()
|
||||
}
|
||||
|
||||
do {
|
||||
try rtcSession.setConfiguration(configuration, active: true)
|
||||
// unlock here before configuring `AVAudioSession`
|
||||
// unlock()
|
||||
print("[LiveKit] RTCAudioSession Configure success")
|
||||
|
||||
// also configure longFormAudio
|
||||
// let avSession = AVAudioSession.sharedInstance()
|
||||
// try avSession.setCategory(AVAudioSession.Category(rawValue: configuration.category),
|
||||
// mode: AVAudioSession.Mode(rawValue: configuration.mode),
|
||||
// policy: .default,
|
||||
// options: configuration.categoryOptions)
|
||||
// print("[LiveKit] AVAudioSession Configure success")
|
||||
|
||||
result(true)
|
||||
} catch let error {
|
||||
print("[LiveKit] Configure audio error: ", error)
|
||||
result(FlutterError(code: "configure", message: error.localizedDescription, details: nil))
|
||||
}
|
||||
}
|
||||
|
||||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
|
||||
guard let args = call.arguments as? [String: Any?] else {
|
||||
print("[LiveKit] arguments must be a dictionary")
|
||||
result(FlutterMethodNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
switch call.method {
|
||||
case "configureNativeAudio":
|
||||
handleConfigureNativeAudio(args: args, result: result)
|
||||
default:
|
||||
print("[LiveKit] method not found: ", call.method)
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,3 @@
|
||||
#
|
||||
# LiveKit
|
||||
# https://livekit.io/
|
||||
# https://github.com/livekit
|
||||
#
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'livekit_client'
|
||||
s.version = '0.5.3'
|
||||
|
||||
Reference in New Issue
Block a user