From f10d7065b03a93defe712a337351b8a4595a526d Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Wed, 26 Aug 2020 11:10:48 +0200 Subject: [PATCH] Add video preview. Move all video display intelligence to the GUI part --- .../VideoCallTutorial/ContentView.swift | 29 +++++++++++++++++-- .../VideoCallTutorial/VideoCallExample.swift | 18 +----------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift b/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift index 341f6ec..53f3818 100644 --- a/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift +++ b/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift @@ -7,6 +7,31 @@ // 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 { @@ -117,9 +142,9 @@ struct ContentView: View { .padding(.top) } HStack { + LinphoneVideoView(core: tutorialContext.mCore).frame(width: 150, height: 210).border(Color.gray).padding(.leading) Spacer() - tutorialContext.videoView.frame(width : 150) - Spacer() + LinphoneVideoPreview(core: tutorialContext.mCore).frame(width: 120, height: 160).border(Color.gray).padding(.horizontal) } Spacer() Group { diff --git a/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift b/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift index 5f8383a..de66b48 100644 --- a/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift +++ b/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift @@ -7,7 +7,7 @@ // import linphonesw -import SwiftUI + class VideoCallExample : ObservableObject { @@ -34,20 +34,6 @@ class VideoCallExample : ObservableObject @Published var id : String = "sip:quentindev@sip.linphone.org" @Published var passwd : String = "dev" @Published var loggedIn: Bool = false - - /*--- Wrapper to incorporate the video chat view into a SwiftUI gui ---*/ - struct VideoView: UIViewRepresentable { - let videoAsUIView = UIView() - - func makeUIView(context: Context) -> UIView { - videoAsUIView.backgroundColor = .black - return videoAsUIView - } - - func updateUIView(_ uiView: UIView, context: Context) {} - } - let videoView = VideoView() - init() { @@ -60,8 +46,6 @@ class VideoCallExample : ObservableObject // main loop for receiving notifications and doing background linphonecore work: mCore.autoIterateEnabled = true - // Give the UIView in which the video will be rendered to the Linphone Core - mCore.nativeVideoWindowId = UnsafeMutableRawPointer(Unmanaged.passRetained(videoView.videoAsUIView).toOpaque()) try? mCore.start() mVideoDevices = mCore.videoDevicesList