refactor: remove activity dependency from LinphoneBridge

This commit is contained in:
Andrew 2026-01-22 17:11:24 +07:00
parent 0375fe4d1a
commit 9a86c4881c
2 changed files with 1 additions and 22 deletions

View file

@ -6,7 +6,6 @@ public class LiblinphoneFlutterPlugin: NSObject, FlutterPlugin {
private var registrationEventsChannel: FlutterEventSink?
private var callEventsChannel: FlutterEventSink?
private var activity: UIViewController?
private var remoteViewCache: [Int: UIView] = [:]
private var localViewCache: [Int: UIView] = [:]
@ -76,13 +75,6 @@ public class LiblinphoneFlutterPlugin: NSObject, FlutterPlugin {
}
)
callEventChannel.setStreamHandler(callStreamHandler)
// Get root view controller
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first,
let rootViewController = window.rootViewController {
instance.activity = rootViewController
}
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
@ -92,18 +84,8 @@ public class LiblinphoneFlutterPlugin: NSObject, FlutterPlugin {
result(hasPermissions)
case "initialize":
do {
guard let activity = self.activity else {
result(FlutterError(
code: "NO_ACTIVITY",
message: "Activity not available",
details: nil
))
return
}
do {
linphoneBridge = LinphoneBridge(
activity: activity,
remoteViewAcquisitor: { [weak self] in
return self?.acquireRemoteView()
},

View file

@ -7,7 +7,6 @@ class LinphoneBridge {
private var core: Core!
private var isRegistered = false
private var currentCall: Call?
private let activity: UIViewController
private let remoteViewAcquisitor: () -> UIView?
private let localViewAcquisitor: () -> UIView?
private let onRegistrationStateChanged: (Int) -> Void
@ -30,13 +29,11 @@ class LinphoneBridge {
private static let TAG = "LinphoneBridge"
init(
activity: UIViewController,
remoteViewAcquisitor: @escaping () -> UIView?,
localViewAcquisitor: @escaping () -> UIView?,
onRegistrationStateChanged: @escaping (Int) -> Void,
onCallStateChanged: @escaping (Int) -> Void
) {
self.activity = activity
self.remoteViewAcquisitor = remoteViewAcquisitor
self.localViewAcquisitor = localViewAcquisitor
self.onRegistrationStateChanged = onRegistrationStateChanged