From 693effd6b7953ea1faf90f5a8109583920620b5a Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 5 Jul 2020 14:10:18 +0300 Subject: [PATCH] first step form calling API --- ios/Podfile | 2 +- ios/Podfile.lock | 6 +++- ios/Runner/AppDelegate.swift | 9 ++++-- ios/Runner/ICallProtocoll.swift | 3 +- ios/Runner/VideoViewController.swift | 42 +++++++++++++++++++++++++--- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/ios/Podfile b/ios/Podfile index 3b20de57..bebf8f5b 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -64,7 +64,7 @@ target 'Runner' do # Keep pod path relative so it can be checked into Podfile.lock. pod 'Flutter', :path => 'Flutter' pod 'OpenTok' - + pod 'Alamofire' # Plugin Pods # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock diff --git a/ios/Podfile.lock b/ios/Podfile.lock index ab95eb7c..70b9d103 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1,4 +1,5 @@ PODS: + - Alamofire (4.9.1) - barcode_scan (0.0.1): - Flutter - MTBBarcodeScanner @@ -41,6 +42,7 @@ PODS: - Flutter DEPENDENCIES: + - Alamofire - barcode_scan (from `.symlinks/plugins/barcode_scan/ios`) - connectivity (from `.symlinks/plugins/connectivity/ios`) - connectivity_macos (from `.symlinks/plugins/connectivity_macos/ios`) @@ -62,6 +64,7 @@ DEPENDENCIES: SPEC REPOS: trunk: + - Alamofire - MTBBarcodeScanner - OpenTok - Reachability @@ -104,6 +107,7 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/url_launcher_web/ios" SPEC CHECKSUMS: + Alamofire: 85e8a02c69d6020a0d734f6054870d7ecb75cf18 barcode_scan: a5c27959edfafaa0c771905bad0b29d6d39e4479 connectivity: 6e94255659cc86dcbef1d452ad3e0491bb1b3e75 connectivity_macos: e2e9731b6b22dda39eb1b128f6969d574460e191 @@ -126,6 +130,6 @@ SPEC CHECKSUMS: url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313 url_launcher_web: e5527357f037c87560776e36436bf2b0288b965c -PODFILE CHECKSUM: ad71cae222b2dc22820a69b80873417b35fef79e +PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69 COCOAPODS: 1.9.3 diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index e763b11d..e4992e16 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -11,8 +11,12 @@ import OpenTok var result: FlutterResult? - func sessionDone() { - self.result?("Session Done") + func sessionDone(res:Any) { + self.result?(res) + + } + func sessionNotResponded(res:Any) { + self.result?(res) } override func application( @@ -20,7 +24,6 @@ import OpenTok didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - let controller : FlutterViewController = window?.rootViewController as! FlutterViewController let videoCallChannel = FlutterMethodChannel(name: "Dr.cloudSolution/videoCall", binaryMessenger: controller.binaryMessenger) diff --git a/ios/Runner/ICallProtocoll.swift b/ios/Runner/ICallProtocoll.swift index 1e267a17..197be424 100644 --- a/ios/Runner/ICallProtocoll.swift +++ b/ios/Runner/ICallProtocoll.swift @@ -10,5 +10,6 @@ import Foundation protocol ICallProtocol { - func sessionDone() + func sessionDone(res:Any) + func sessionNotResponded(res: Any) } diff --git a/ios/Runner/VideoViewController.swift b/ios/Runner/VideoViewController.swift index 357c696f..d9834fea 100644 --- a/ios/Runner/VideoViewController.swift +++ b/ios/Runner/VideoViewController.swift @@ -8,6 +8,7 @@ import UIKit import OpenTok +import Alamofire class ViewController: UIViewController { @@ -25,6 +26,7 @@ class ViewController: UIViewController { var callBack: ICallProtocol? var timer = Timer() var seconds = 30 + var isUserConnect : Bool = false override func viewDidLoad() { @@ -37,6 +39,38 @@ class ViewController: UIViewController { setupSession() // Do any additional setup after loading the view. } + + + private func callApi() { + let URL_USER_REGISTER = "https://uat.hmgwebservices.com/LiveCareApi/DoctorApp/GetSessionStatus" + let headers: HTTPHeaders = [ + "Content-Type":"application/json", + "Accept":"application/json", + + ] + + let parameters = [ + "VC_ID": 3245, + "TokenID": "hfkjshdf347r8743", + "generalid": "Cs2020@2016$2958", + "DoctorId" : 1485 , + ] as [String : Any] + Alamofire.request(URL_USER_REGISTER, method: .post,parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON{ + response in + if self.isUserConnect { + } else { + if let result = response.result.value { + let jsonData = result as! NSDictionary + self.callBack?.sessionNotResponded(res: ["sessionStatus":jsonData, "callResponse":"CallNotRespond"]) + + } + self.sessionDisconnect(); + self.timer.invalidate() + } + //getting json value from the server + + } + } func setupButtons() { perform(#selector(hideControlButtons), with: nil, afterDelay: 3) @@ -115,7 +149,7 @@ class ViewController: UIViewController { if (session != nil) { print("disconnecting....") session!.disconnect(nil) - callBack?.sessionDone() + callBack?.sessionDone(res:["callResponse":"CallEnd"]) dismiss(animated: true) return } @@ -214,10 +248,10 @@ class ViewController: UIViewController { seconds -= 1 //This will decrement(count down)the seconds. print(seconds) if seconds == 0 { - sessionDisconnect(); - timer.invalidate() + callApi() } + } } @@ -330,7 +364,7 @@ extension ViewController: OTSessionDelegate { if let connectionId = connection?.connectionId { print("session connectionCreated (\(connectionId))") } - + isUserConnect = true timer.invalidate() }