|
|
|
|
@ -34,8 +34,8 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
var seconds = 55
|
|
|
|
|
var isUserConnect : Bool = false
|
|
|
|
|
|
|
|
|
|
var onFloat:((Bool)->Void)? = nil
|
|
|
|
|
var onMinimize:(()->Void)? = nil
|
|
|
|
|
var onRectFloat:((Bool)->Void)? = nil
|
|
|
|
|
var onCircleFloat:((Bool)->Void)? = nil
|
|
|
|
|
var onCallConnect:(()->Void)? = nil
|
|
|
|
|
var onCallDisconnect:(()->Void)? = nil
|
|
|
|
|
|
|
|
|
|
@ -50,26 +50,55 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
@IBOutlet var minimizeConstraint: [NSLayoutConstraint]!
|
|
|
|
|
@IBOutlet var maximisedConstraint: [NSLayoutConstraint]!
|
|
|
|
|
|
|
|
|
|
@IBOutlet weak var btnMinimize: UIButton!
|
|
|
|
|
@IBOutlet weak var hideVideoBtn: UIButton!
|
|
|
|
|
@IBOutlet weak var draggableBoundryDefiner: UIView!
|
|
|
|
|
var localVideoDraggable:AADraggableView?
|
|
|
|
|
@IBOutlet weak var controlButtons: UIView!
|
|
|
|
|
@IBOutlet weak var remoteVideoMutedIndicator: UIImageView!
|
|
|
|
|
@IBOutlet weak var localVideoMutedBg: UIView!
|
|
|
|
|
|
|
|
|
|
@IBOutlet weak var btnScreenTap: UIButton!
|
|
|
|
|
@IBOutlet weak var localVideoContainer: UIView!
|
|
|
|
|
@IBOutlet weak var topBar: UIView!
|
|
|
|
|
@IBOutlet weak var lblCallDuration: UILabel!
|
|
|
|
|
@IBOutlet weak var remoteVideo: UIView!
|
|
|
|
|
@IBOutlet weak var localVideo: UIView!{
|
|
|
|
|
@IBOutlet weak var fullVideoView: UIView!
|
|
|
|
|
@IBOutlet weak var smallVideoView: UIView!{
|
|
|
|
|
didSet{
|
|
|
|
|
localVideo.layer.borderColor = UIColor.white.cgColor
|
|
|
|
|
localVideoDraggable = localVideo?.superview as? AADraggableView
|
|
|
|
|
smallVideoView.layer.borderColor = UIColor.white.cgColor
|
|
|
|
|
localVideoDraggable = smallVideoView?.superview as? AADraggableView
|
|
|
|
|
localVideoDraggable?.reposition = .edgesOnly
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
localVideoDraggable?.respectedView = draggableBoundryDefiner
|
|
|
|
|
localVideoDraggable?.respectedView = localVideoContainer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func click(gesture:UIGestureRecognizer){
|
|
|
|
|
gesture.view?.removeFromSuperview()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func btnOnScreenTapped(_ sender: Any) {
|
|
|
|
|
if(hideVideoBtn.isSelected){
|
|
|
|
|
circleFloatBtnTapped(hideVideoBtn)
|
|
|
|
|
|
|
|
|
|
}else if(btnMinimize.isSelected){
|
|
|
|
|
btnMinimizeTapped(btnMinimize)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func btnSwipeVideoTapped(_ sender: Any) {
|
|
|
|
|
// let smallVdoRender = smallVideoView.subviews.first
|
|
|
|
|
// let fullVdoRender = fullVideoView.subviews.first
|
|
|
|
|
// if let vdo = smallVdoRender{
|
|
|
|
|
// fullVideoView.addSubview(vdo)
|
|
|
|
|
// }
|
|
|
|
|
// if let vdo = fullVdoRender{
|
|
|
|
|
// smallVideoView.addSubview(vdo)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// layoutVideoRenderViews()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func didClickMuteButton(_ sender: UIButton) {
|
|
|
|
|
@ -77,10 +106,9 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
publisher!.publishAudio = !sender.isSelected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func didClickSpeakerButton(_ sender: UIButton) {
|
|
|
|
|
@IBAction func didClickSpeakerButton(_ sender: UIButton) {
|
|
|
|
|
sender.isSelected = !sender.isSelected
|
|
|
|
|
subscriber?.subscribeToAudio = !sender.isSelected
|
|
|
|
|
// resetHideButtonsTimer()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func didClickVideoMuteButton(_ sender: UIButton) {
|
|
|
|
|
@ -90,9 +118,8 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
} else {
|
|
|
|
|
publisher!.publishVideo = true
|
|
|
|
|
}
|
|
|
|
|
localVideo.isHidden = sender.isSelected
|
|
|
|
|
smallVideoView.isHidden = sender.isSelected
|
|
|
|
|
localVideoMutedBg.isHidden = !sender.isSelected
|
|
|
|
|
// resetHideButtonsTimer()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -104,7 +131,6 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
} else {
|
|
|
|
|
publisher!.cameraPosition = AVCaptureDevice.Position.back
|
|
|
|
|
}
|
|
|
|
|
/// resetHideButtonsTimer()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func hangUp(_ sender: UIButton) {
|
|
|
|
|
@ -112,36 +138,46 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
sessionDisconnect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func hideVideoBtnTapped(_ sender: Any) {
|
|
|
|
|
onMinimize?()
|
|
|
|
|
@IBAction func circleFloatBtnTapped(_ sender: UIButton) {
|
|
|
|
|
sender.isSelected = !sender.isSelected
|
|
|
|
|
onCircleFloat?(sender.isSelected)
|
|
|
|
|
topBar.isHidden = sender.isSelected
|
|
|
|
|
controlButtons.isHidden = sender.isSelected
|
|
|
|
|
smallVideoView.isHidden = sender.isSelected
|
|
|
|
|
self.publisher?.view?.layoutIfNeeded()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var floated = false
|
|
|
|
|
@IBAction func onMinimize(_ sender: UIButton) {
|
|
|
|
|
floated = !floated
|
|
|
|
|
onFloat?(floated)
|
|
|
|
|
sender.isSelected = floated
|
|
|
|
|
@IBAction func btnMinimizeTapped(_ sender: UIButton) {
|
|
|
|
|
minimizeVideoState(state: !sender.isSelected)
|
|
|
|
|
btnScreenTap.isHidden = !sender.isSelected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func minimizeVideoState(state:Bool){
|
|
|
|
|
btnMinimize.isSelected = state
|
|
|
|
|
onRectFloat?(state)
|
|
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate(floated ? minimizeConstraint : maximisedConstraint)
|
|
|
|
|
NSLayoutConstraint.deactivate(floated ? maximisedConstraint : minimizeConstraint)
|
|
|
|
|
localVideoDraggable?.enable(!floated)
|
|
|
|
|
NSLayoutConstraint.activate(state ? minimizeConstraint : maximisedConstraint)
|
|
|
|
|
NSLayoutConstraint.deactivate(state ? maximisedConstraint : minimizeConstraint)
|
|
|
|
|
localVideoDraggable?.enable(!state)
|
|
|
|
|
|
|
|
|
|
lblRemoteUsername.isHidden = floated
|
|
|
|
|
hideVideoBtn.isHidden = !floated
|
|
|
|
|
lblRemoteUsername.isHidden = state
|
|
|
|
|
hideVideoBtn.isHidden = !state
|
|
|
|
|
lblCallDuration.superview?.isHidden = !hideVideoBtn.isHidden
|
|
|
|
|
|
|
|
|
|
let min_ = floated
|
|
|
|
|
UIView.animate(withDuration: 0.5) {
|
|
|
|
|
self.videoMuteBtn.isHidden = min_
|
|
|
|
|
self.micMuteBtn.isHidden = min_
|
|
|
|
|
self.camSwitchBtn.isHidden = min_
|
|
|
|
|
|
|
|
|
|
let localVdoSize = self.localVideo.bounds.size
|
|
|
|
|
let remoteVdoSize = self.remoteVideo.bounds.size
|
|
|
|
|
self.publisher?.view?.frame = CGRect(x: 0, y: 0, width: localVdoSize.width, height: localVdoSize.height)
|
|
|
|
|
self.subscriber?.view?.frame = CGRect(x: 0, y: 0, width: remoteVdoSize.width, height: remoteVdoSize.height)
|
|
|
|
|
self.publisher?.view?.layoutIfNeeded()
|
|
|
|
|
self.subscriber?.view?.layoutIfNeeded()
|
|
|
|
|
self.videoMuteBtn.isHidden = state
|
|
|
|
|
self.micMuteBtn.isHidden = state
|
|
|
|
|
self.camSwitchBtn.isHidden = state
|
|
|
|
|
self.layoutVideoRenderViews()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func layoutVideoRenderViews(){
|
|
|
|
|
if let publisherVdoSize = publisher?.view?.superview?.bounds.size{
|
|
|
|
|
publisher?.view?.frame = CGRect(x: 0, y: 0, width: publisherVdoSize.width, height: publisherVdoSize.height)
|
|
|
|
|
}
|
|
|
|
|
if let subscriberVdoSize = subscriber?.view?.superview?.bounds.size{
|
|
|
|
|
subscriber?.view?.frame = CGRect(x: 0, y: 0, width: subscriberVdoSize.width, height: subscriberVdoSize.height)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -161,6 +197,9 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func start(params:VideoCallRequestParameters){
|
|
|
|
|
lblRemoteUsername.text = params.patientName ?? "- - -"
|
|
|
|
|
btnScreenTap.isHidden = true
|
|
|
|
|
hideVideoBtn.isHidden = true
|
|
|
|
|
|
|
|
|
|
self.kApiKey = params.apiKey ?? ""
|
|
|
|
|
self.kSessionId = params.sessionId ?? ""
|
|
|
|
|
@ -171,11 +210,11 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
self.DoctorId = params.doctorId ?? 0
|
|
|
|
|
self.baseUrl = params.baseUrl ?? ""
|
|
|
|
|
|
|
|
|
|
setupButtons()
|
|
|
|
|
askForMicrophonePermission()
|
|
|
|
|
requestCameraPermissionsIfNeeded()
|
|
|
|
|
hideVideoMuted()
|
|
|
|
|
setupSession()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func changeCallStatus(callStatus:Int){
|
|
|
|
|
@ -238,13 +277,6 @@ class VideoCallViewController: UIViewController {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setupButtons() {
|
|
|
|
|
perform(#selector(hideControlButtons), with: nil, afterDelay: 3)
|
|
|
|
|
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(remoteVideoTapped(_:)))
|
|
|
|
|
view.addGestureRecognizer(tapGestureRecognizer)
|
|
|
|
|
view.isUserInteractionEnabled = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: -Microphone Camera and Permission Request
|
|
|
|
|
func askForMicrophonePermission() {
|
|
|
|
|
@ -387,10 +419,11 @@ extension VideoCallViewController: OTSessionDelegate {
|
|
|
|
|
showAlert(error?.localizedDescription)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
publisher?.view!.frame = CGRect(x: 0, y: 0, width: localVideo.bounds.size.width, height: localVideo.bounds.size.height)
|
|
|
|
|
publisher?.view?.tag = 11
|
|
|
|
|
publisher?.view?.layer.cornerRadius = 5
|
|
|
|
|
publisher?.view?.clipsToBounds = true
|
|
|
|
|
localVideo.addSubview((publisher?.view)!)
|
|
|
|
|
smallVideoView.addSubview((publisher?.view)!)
|
|
|
|
|
layoutVideoRenderViews()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sessionDidDisconnect(_ session: OTSession) {
|
|
|
|
|
@ -430,9 +463,9 @@ extension VideoCallViewController: OTSessionDelegate {
|
|
|
|
|
guard let subscriberView = subscriber.view else {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
subscriberView.frame = CGRect(x: 0, y: 0, width: remoteVideo.bounds.width, height: remoteVideo.bounds.height)
|
|
|
|
|
remoteVideo.addSubview(subscriberView)
|
|
|
|
|
subscriberView.tag = 22
|
|
|
|
|
fullVideoView.addSubview(subscriberView)
|
|
|
|
|
layoutVideoRenderViews()
|
|
|
|
|
|
|
|
|
|
startUpdateCallDuration()
|
|
|
|
|
onCallConnect?()
|
|
|
|
|
@ -481,12 +514,6 @@ extension VideoCallViewController: OTPublisherDelegate {
|
|
|
|
|
func publisher(_ publisher: OTPublisherKit, didFailWithError error: OTError) {
|
|
|
|
|
print("The publisher failed: \(error)")
|
|
|
|
|
}
|
|
|
|
|
@objc func remoteVideoTapped(_ recognizer: UITapGestureRecognizer?) {
|
|
|
|
|
if controlButtons.isHidden {
|
|
|
|
|
controlButtons.isHidden = false
|
|
|
|
|
perform(#selector(hideControlButtons), with: nil, afterDelay: 3)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension VideoCallViewController: OTSubscriberDelegate {
|
|
|
|
|
@ -497,8 +524,5 @@ extension VideoCallViewController: OTSubscriberDelegate {
|
|
|
|
|
public func subscriber(_ subscriber: OTSubscriberKit, didFailWithError error: OTError) {
|
|
|
|
|
print("The subscriber failed to connect to the stream.")
|
|
|
|
|
}
|
|
|
|
|
@objc func hideControlButtons() {
|
|
|
|
|
// controlButtons.isHidden = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|