You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
doctor_app_flutter/ios/Runner/MainAppViewController.swift

143 lines
4.9 KiB
Swift

//
// MainAppViewController.swift
// Runner
//
// Created by Zohaib Iqbal Kambrani on 08/06/2021.
// Copyright © 2021 The Chromium Authors. All rights reserved.
//
import Foundation
class MainAppViewController: FlutterViewController{
var videoCallContainer:UIView!
var videoCallViewController:VideoCallViewController!
var videoCallFlutterResult:FlutterResult?
var vdoCallViewMinConstraint:[NSLayoutConstraint]!
var vdoCallViewMaxConstraint:[NSLayoutConstraint]!
override func viewDidLoad() {
super.viewDidLoad()
initFlutterBridge()
prepareVideoCallView()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
private func initFlutterBridge(){
let videoCallChannel = FlutterMethodChannel(name: "Dr.cloudSolution/videoCall", binaryMessenger: binaryMessenger)
videoCallChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
switch call.method {
case "openVideoCall":
self.startVideoCall(result: result, call: call)
default:
result(FlutterMethodNotImplemented)
}
})
}
}
// Video Call Functions
extension MainAppViewController : ICallProtocol{
func prepareVideoCallView(){
videoCallContainer = UIView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height))
videoCallContainer.alpha = 0.0
videoCallContainer.backgroundColor = UIColor.black
view.addSubview(videoCallContainer)
setVideoViewConstrints()
NSLayoutConstraint.activate(vdoCallViewMaxConstraint)
NSLayoutConstraint.deactivate(vdoCallViewMinConstraint)
ViewEmbedder.embed(
withIdentifier: "videoCall", // Storyboard ID
parent: self,
container: self.videoCallContainer){ vc in
self.videoCallViewController = vc as? VideoCallViewController
}
}
private func startVideoCall(result: @escaping FlutterResult, call:FlutterMethodCall) {
videoCallFlutterResult = result
if let arguments = call.arguments as? NSDictionary{
showVideoCallView(true)
videoCallViewController.onMinimize = { min in
self.minimizeVideoCall(min)
}
videoCallViewController.onClose = videoCallClosed
videoCallViewController.callBack = self
videoCallViewController.start(params: VideoCallRequestParameters(dictionary: arguments))
}
}
private func minimizeVideoCall(_ value:Bool){
UIView.animate(withDuration: 0.5) {
if(value){
NSLayoutConstraint.deactivate(self.vdoCallViewMaxConstraint)
NSLayoutConstraint.activate(self.vdoCallViewMinConstraint)
}else{
NSLayoutConstraint.deactivate(self.vdoCallViewMinConstraint)
NSLayoutConstraint.activate(self.vdoCallViewMaxConstraint)
}
self.videoCallContainer.layer.cornerRadius = value ? 10 : 0
self.videoCallContainer.layer.borderColor = value ? UIColor.white.cgColor : nil
self.videoCallContainer.layer.borderWidth = value ? 2 : 0
self.view.layoutIfNeeded()
}
}
private func showVideoCallView(_ value:Bool){
UIView.animate(withDuration: 0.5) {
self.videoCallContainer.alpha = value ? 1.0 : 0.0
} completion: { complete in
if(value == false){
self.videoCallContainer.removeFromSuperview()
}
}
}
private func videoCallClosed(){
showVideoCallView(false)
}
func sessionDone(res: Any) {
videoCallFlutterResult?(res)
}
func sessionNotResponded(res: Any) {
videoCallFlutterResult?(res)
}
func setVideoViewConstrints(){
let screen = UIScreen.main.bounds
videoCallContainer.translatesAutoresizingMaskIntoConstraints = false
vdoCallViewMinConstraint = [
videoCallContainer.topAnchor.constraint(equalTo: view.topAnchor, constant: 20),
videoCallContainer.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
videoCallContainer.widthAnchor.constraint(equalToConstant: screen.width/3),
videoCallContainer.heightAnchor.constraint(equalToConstant: screen.height/3.5)
]
vdoCallViewMaxConstraint = [
videoCallContainer.topAnchor.constraint(equalTo: view.topAnchor),
videoCallContainer.leadingAnchor.constraint(equalTo: view.leadingAnchor),
videoCallContainer.widthAnchor.constraint(equalToConstant: screen.width),
videoCallContainer.heightAnchor.constraint(equalToConstant: screen.height)
]
}
}