diff --git a/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift b/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift index 53f3818..e31aa4e 100644 --- a/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift +++ b/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift @@ -9,33 +9,9 @@ import SwiftUI import linphonesw -struct LinphoneVideoView: UIViewRepresentable { - var core:Core - private let _view = UIView() - - func makeUIView(context: Context) -> UIView { - core.nativeVideoWindowId = UnsafeMutableRawPointer(Unmanaged.passRetained(_view).toOpaque()) - return _view - } - - func updateUIView(_ uiView: UIView, context: Context) {} -} - -struct LinphoneVideoPreview: UIViewRepresentable { - var core:Core - private let _view = UIView() - - func makeUIView(context: Context) -> UIView { - core.nativePreviewWindowId = UnsafeMutableRawPointer(Unmanaged.passRetained(_view).toOpaque()) - return _view - } - - func updateUIView(_ uiView: UIView, context: Context) {} -} - struct ContentView: View { - @ObservedObject var tutorialContext = VideoCallExample() + @ObservedObject var tutorialContext : VideoCallExample func getCallButtonText() -> String { @@ -120,7 +96,8 @@ struct ContentView: View { } }) { - Text(getCallButtonText()) + + Text(getCallButtonText()) .font(.largeTitle) .foregroundColor(Color.white) .frame(width: 180.0, height: 42.0) @@ -142,11 +119,20 @@ struct ContentView: View { .padding(.top) } HStack { - LinphoneVideoView(core: tutorialContext.mCore).frame(width: 150, height: 210).border(Color.gray).padding(.leading) + LinphoneVideoViewHolder() { view in + self.tutorialContext.mCore.nativeVideoWindowId = UnsafeMutableRawPointer(Unmanaged.passRetained(view).toOpaque()) + } + .frame(width: 150, height: 210) + .border(Color.gray) + .padding(.leading) Spacer() - LinphoneVideoPreview(core: tutorialContext.mCore).frame(width: 120, height: 160).border(Color.gray).padding(.horizontal) + LinphoneVideoViewHolder() { view in + self.tutorialContext.mCore.nativePreviewWindowId = UnsafeMutableRawPointer(Unmanaged.passRetained(view).toOpaque()) + } + .frame(width: 90, height: 120) + .border(Color.gray) + .padding(.horizontal) } - Spacer() Group { Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled.value) { Text("Logs collection") diff --git a/swift/VideoCallTutorial/VideoCallTutorial/SceneDelegate.swift b/swift/VideoCallTutorial/VideoCallTutorial/SceneDelegate.swift index 9fe5572..6702495 100644 --- a/swift/VideoCallTutorial/VideoCallTutorial/SceneDelegate.swift +++ b/swift/VideoCallTutorial/VideoCallTutorial/SceneDelegate.swift @@ -19,7 +19,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - let contentView = ContentView() + let delegate = UIApplication.shared.delegate as! AppDelegate + + let contentView = ContentView(tutorialContext: delegate.tutorialContext) // Use a UIHostingController as window root view controller. if let windowScene = scene as? UIWindowScene { diff --git a/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift b/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift index de66b48..456645e 100644 --- a/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift +++ b/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift @@ -8,7 +8,6 @@ import linphonesw - class VideoCallExample : ObservableObject { var mCore: Core! // We need a Core for... anything, basically @@ -25,7 +24,7 @@ class VideoCallExample : ObservableObject var mUsedVideoDeviceId : Int = 0 var callAlreadyStopped = false; - @Published var videoEnabled : Bool = false + @Published var videoEnabled : Bool = true @Published var callRunning : Bool = false @Published var isCallIncoming : Bool = false @Published var dest : String = "sip:arguillq@sip.linphone.org" @@ -52,6 +51,7 @@ class VideoCallExample : ObservableObject mCore.addDelegate(delegate: mCallStateTracer) mCore.addDelegate(delegate: mRegistrationDelegate) + } func registrationExample()