From 357213e7e4858ca8d18a431b12ecd40194a85171 Mon Sep 17 00:00:00 2001
From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com>
Date: Wed, 24 Nov 2021 21:32:40 +0700
Subject: [PATCH] macOS support (#33)
* mac os support 1
* entitlements
* fix updateTrack bug
* clean
* throws on mac
* simplify structure
* lock
---
example/ios/Podfile.lock | 10 ++---
.../Flutter/GeneratedPluginRegistrant.swift | 2 +
example/macos/Podfile.lock | 17 +++++---
.../macos/Runner/DebugProfile.entitlements | 4 ++
example/macos/Runner/Info.plist | 8 ++--
example/macos/Runner/Release.entitlements | 4 ++
ios/Classes/LiveKitPlugin.h | 4 --
ios/Classes/LiveKitPlugin.m | 15 -------
ios/Classes/LiveKitPlugin.swift | 1 +
ios/livekit_client.podspec | 6 ---
macos/Classes/LiveKitPlugin.swift | 1 +
macos/livekit_client.podspec | 20 +++++++++
pubspec.yaml | 2 +
.../LiveKitPlugin.swift | 43 ++++++++++++++-----
14 files changed, 87 insertions(+), 50 deletions(-)
delete mode 100644 ios/Classes/LiveKitPlugin.h
delete mode 100644 ios/Classes/LiveKitPlugin.m
create mode 120000 ios/Classes/LiveKitPlugin.swift
create mode 120000 macos/Classes/LiveKitPlugin.swift
create mode 100644 macos/livekit_client.podspec
rename ios/Classes/SwiftLiveKitPlugin.swift => shared_swift/LiveKitPlugin.swift (86%)
diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock
index 738d566..3405c97 100644
--- a/example/ios/Podfile.lock
+++ b/example/ios/Podfile.lock
@@ -8,7 +8,7 @@ PODS:
- livekit_client (0.5.3):
- Flutter
- WebRTC-SDK (~> 92.4515)
- - path_provider (0.0.1):
+ - path_provider_ios (0.0.1):
- Flutter
- shared_preferences (0.0.1):
- Flutter
@@ -18,7 +18,7 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_webrtc (from `.symlinks/plugins/flutter_webrtc/ios`)
- livekit_client (from `.symlinks/plugins/livekit_client/ios`)
- - path_provider (from `.symlinks/plugins/path_provider/ios`)
+ - path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
SPEC REPOS:
@@ -33,8 +33,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_webrtc/ios"
livekit_client:
:path: ".symlinks/plugins/livekit_client/ios"
- path_provider:
- :path: ".symlinks/plugins/path_provider/ios"
+ path_provider_ios:
+ :path: ".symlinks/plugins/path_provider_ios/ios"
shared_preferences:
:path: ".symlinks/plugins/shared_preferences/ios"
@@ -43,7 +43,7 @@ SPEC CHECKSUMS:
flutter_webrtc: a5a79904f0bca0ea23aff49c51ca765f70a0f703
Libyuv: 5f79ced0ee66e60a612ca97de1e6ccacd187a437
livekit_client: 2b15f8f6f37bc447184af227bd66d30ed1c5fd38
- path_provider: d1e9807085df1f9cc9318206cd649dc0b76be3de
+ path_provider_ios: 7d7ce634493af4477d156294792024ec3485acd5
shared_preferences: 5033afbb22d372e15aff8ff766df9021b845f273
WebRTC-SDK: 21dbc6028a68f3a89718057a2caa970a4da8ebb7
diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift
index 2653f3a..d965146 100644
--- a/example/macos/Flutter/GeneratedPluginRegistrant.swift
+++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift
@@ -6,11 +6,13 @@ import FlutterMacOS
import Foundation
import flutter_webrtc
+import livekit_client
import path_provider_macos
import shared_preferences_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterWebRTCPlugin.register(with: registry.registrar(forPlugin: "FlutterWebRTCPlugin"))
+ LiveKitPlugin.register(with: registry.registrar(forPlugin: "LiveKitPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}
diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock
index 35d8ad6..4fc86a1 100644
--- a/example/macos/Podfile.lock
+++ b/example/macos/Podfile.lock
@@ -1,17 +1,21 @@
PODS:
- - flutter_webrtc (0.2.3):
+ - flutter_webrtc (0.7.1):
- FlutterMacOS
- - WebRTC-SDK (= 92.4515.10)
+ - WebRTC-SDK (= 92.4515.11)
- FlutterMacOS (1.0.0)
+ - livekit_client (0.5.3):
+ - FlutterMacOS
+ - WebRTC-SDK (~> 92.4515)
- path_provider_macos (0.0.1):
- FlutterMacOS
- shared_preferences_macos (0.0.1):
- FlutterMacOS
- - WebRTC-SDK (92.4515.10)
+ - WebRTC-SDK (92.4515.11)
DEPENDENCIES:
- flutter_webrtc (from `Flutter/ephemeral/.symlinks/plugins/flutter_webrtc/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
+ - livekit_client (from `Flutter/ephemeral/.symlinks/plugins/livekit_client/macos`)
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
- shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`)
@@ -24,17 +28,20 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_webrtc/macos
FlutterMacOS:
:path: Flutter/ephemeral
+ livekit_client:
+ :path: Flutter/ephemeral/.symlinks/plugins/livekit_client/macos
path_provider_macos:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
shared_preferences_macos:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos
SPEC CHECKSUMS:
- flutter_webrtc: 8d69a6819b422e5caf1c7b2844a05bc6a62b437b
+ flutter_webrtc: eb68063546a533bb98f0fbcc7b54daf62edea4ed
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
+ livekit_client: b137f094e90d910cfa846b282ad41e0e4a6a029b
path_provider_macos: 160cab0d5461f0c0e02995469a98f24bdb9a3f1f
shared_preferences_macos: 480ce071d0666e37cef23fe6c702293a3d21799e
- WebRTC-SDK: dabc6471c193814aeb0ad9e6712052567acff601
+ WebRTC-SDK: 21dbc6028a68f3a89718057a2caa970a4da8ebb7
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
diff --git a/example/macos/Runner/DebugProfile.entitlements b/example/macos/Runner/DebugProfile.entitlements
index 3ba6c12..e92c0f0 100644
--- a/example/macos/Runner/DebugProfile.entitlements
+++ b/example/macos/Runner/DebugProfile.entitlements
@@ -6,6 +6,10 @@
com.apple.security.cs.allow-jit
+ com.apple.security.device.audio-input
+
+ com.apple.security.device.camera
+
com.apple.security.network.client
com.apple.security.network.server
diff --git a/example/macos/Runner/Info.plist b/example/macos/Runner/Info.plist
index 74c5a22..9646fb5 100644
--- a/example/macos/Runner/Info.plist
+++ b/example/macos/Runner/Info.plist
@@ -2,8 +2,6 @@
- NSMicrophoneUsageDescription
- Please enable mic to publish.
CFBundleDevelopmentRegion
$(DEVELOPMENT_LANGUAGE)
CFBundleExecutable
@@ -26,13 +24,15 @@
public.app-category.developer-tools
LSMinimumSystemVersion
$(MACOSX_DEPLOYMENT_TARGET)
+ NSCameraUsageDescription
+ Please enable camera to publish.
NSHumanReadableCopyright
$(PRODUCT_COPYRIGHT)
NSMainNibFile
MainMenu
+ NSMicrophoneUsageDescription
+ Please enable mic to publish.
NSPrincipalClass
NSApplication
- NSCameraUsageDescription
- Please enable camera to publish.
diff --git a/example/macos/Runner/Release.entitlements b/example/macos/Runner/Release.entitlements
index 7a2230d..0a36428 100644
--- a/example/macos/Runner/Release.entitlements
+++ b/example/macos/Runner/Release.entitlements
@@ -4,6 +4,10 @@
com.apple.security.app-sandbox
+ com.apple.security.device.audio-input
+
+ com.apple.security.device.camera
+
com.apple.security.network.client
com.apple.security.network.server
diff --git a/ios/Classes/LiveKitPlugin.h b/ios/Classes/LiveKitPlugin.h
deleted file mode 100644
index e6e50ef..0000000
--- a/ios/Classes/LiveKitPlugin.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#import
-
-@interface LiveKitPlugin : NSObject
-@end
diff --git a/ios/Classes/LiveKitPlugin.m b/ios/Classes/LiveKitPlugin.m
deleted file mode 100644
index f16b3b3..0000000
--- a/ios/Classes/LiveKitPlugin.m
+++ /dev/null
@@ -1,15 +0,0 @@
-#import "LiveKitPlugin.h"
-#if __has_include()
-#import
-#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*)registrar {
- [SwiftLiveKitPlugin registerWithRegistrar:registrar];
-}
-@end
diff --git a/ios/Classes/LiveKitPlugin.swift b/ios/Classes/LiveKitPlugin.swift
new file mode 120000
index 0000000..6beb53b
--- /dev/null
+++ b/ios/Classes/LiveKitPlugin.swift
@@ -0,0 +1 @@
+../../shared_swift/LiveKitPlugin.swift
\ No newline at end of file
diff --git a/ios/livekit_client.podspec b/ios/livekit_client.podspec
index 9c9aa57..d3f4bc0 100644
--- a/ios/livekit_client.podspec
+++ b/ios/livekit_client.podspec
@@ -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'
diff --git a/macos/Classes/LiveKitPlugin.swift b/macos/Classes/LiveKitPlugin.swift
new file mode 120000
index 0000000..6beb53b
--- /dev/null
+++ b/macos/Classes/LiveKitPlugin.swift
@@ -0,0 +1 @@
+../../shared_swift/LiveKitPlugin.swift
\ No newline at end of file
diff --git a/macos/livekit_client.podspec b/macos/livekit_client.podspec
new file mode 100644
index 0000000..f04a041
--- /dev/null
+++ b/macos/livekit_client.podspec
@@ -0,0 +1,20 @@
+Pod::Spec.new do |s|
+ s.name = 'livekit_client'
+ s.version = '0.5.3'
+ s.summary = 'Open source platform for real-time audio and video.'
+ s.description = 'Open source platform for real-time audio and video.'
+ s.homepage = 'https://livekit.io/'
+ s.license = { :file => '../LICENSE' }
+ s.author = { 'LiveKit' => 'contact@livekit.io' }
+ s.source = { :path => '.' }
+ s.source_files = 'Classes/**/*'
+ s.public_header_files = 'Classes/**/*.h'
+ s.platform = :osx, '10.11'
+ # Flutter.framework does not contain a i386 slice.
+ s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
+ s.swift_version = '5.0'
+ s.static_framework = true
+
+ s.dependency 'FlutterMacOS'
+ s.dependency 'WebRTC-SDK', '~> 92.4515'
+end
diff --git a/pubspec.yaml b/pubspec.yaml
index 14979d7..1703899 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -35,6 +35,8 @@ flutter:
platforms:
ios:
pluginClass: LiveKitPlugin
+ macos:
+ pluginClass: LiveKitPlugin
android:
package: io.livekit.plugin
pluginClass: LiveKitPlugin
diff --git a/ios/Classes/SwiftLiveKitPlugin.swift b/shared_swift/LiveKitPlugin.swift
similarity index 86%
rename from ios/Classes/SwiftLiveKitPlugin.swift
rename to shared_swift/LiveKitPlugin.swift
index 329cf4c..faf42a3 100644
--- a/ios/Classes/SwiftLiveKitPlugin.swift
+++ b/shared_swift/LiveKitPlugin.swift
@@ -1,14 +1,29 @@
-import Flutter
-import UIKit
import WebRTC
-public class SwiftLiveKitPlugin: NSObject, FlutterPlugin {
+#if os(macOS)
+import Cocoa
+import FlutterMacOS
+#else
+import Flutter
+import UIKit
+#endif
+
+public class LiveKitPlugin: NSObject, FlutterPlugin {
+
public static func register(with registrar: FlutterPluginRegistrar) {
- let channel = FlutterMethodChannel(name: "livekit_client", binaryMessenger: registrar.messenger())
- let instance = SwiftLiveKitPlugin()
+
+ #if os(macOS)
+ let messenger = registrar.messenger
+ #else
+ let messenger = registrar.messenger()
+ #endif
+
+ let channel = FlutterMethodChannel(name: "livekit_client", binaryMessenger: messenger)
+ let instance = LiveKitPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}
+ #if !os(macOS)
// https://developer.apple.com/documentation/avfaudio/avaudiosession/category
let categoryMap: [String: AVAudioSession.Category] = [
"ambient": .ambient,
@@ -16,7 +31,7 @@ public class SwiftLiveKitPlugin: NSObject, FlutterPlugin {
"playAndRecord": .playAndRecord,
"playback": .playback,
"record": .record,
- "soloAmbient": .soloAmbient,
+ "soloAmbient": .soloAmbient
]
// https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions
@@ -27,9 +42,9 @@ public class SwiftLiveKitPlugin: NSObject, FlutterPlugin {
"allowBluetooth": .allowBluetooth,
"allowBluetoothA2DP": .allowBluetoothA2DP,
"allowAirPlay": .allowAirPlay,
- "defaultToSpeaker": .defaultToSpeaker,
-// @available(iOS 14.5, *)
-// "overrideMutedMicrophoneInterruption": .overrideMutedMicrophoneInterruption,
+ "defaultToSpeaker": .defaultToSpeaker
+ // @available(iOS 14.5, *)
+ // "overrideMutedMicrophoneInterruption": .overrideMutedMicrophoneInterruption,
]
// https://developer.apple.com/documentation/avfaudio/avaudiosession/mode
@@ -42,21 +57,26 @@ public class SwiftLiveKitPlugin: NSObject, FlutterPlugin {
"videoChat": .videoChat,
"videoRecording": .videoRecording,
"voiceChat": .voiceChat,
- "voicePrompt": .voicePrompt,
+ "voicePrompt": .voicePrompt
]
private func categoryOptions(fromFlutter options: [String]) -> AVAudioSession.CategoryOptions {
var result: AVAudioSession.CategoryOptions = []
for option in categoryOptionsMap {
- if (options.contains(option.key)) {
+ if options.contains(option.key) {
result.insert(option.value)
}
}
return result
}
+ #endif
public func handleConfigureNativeAudio(args: [String: Any?], result: @escaping FlutterResult) {
+ #if os(macOS)
+ result(FlutterMethodNotImplemented)
+ #else
+
let configuration = RTCAudioSessionConfiguration.webRTC()
// Category
@@ -117,6 +137,7 @@ public class SwiftLiveKitPlugin: NSObject, FlutterPlugin {
print("[LiveKit] Configure audio error: ", error)
result(FlutterError(code: "configure", message: error.localizedDescription, details: nil))
}
+ #endif
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {