alqindiirsyam преди 2 години
родител
ревизия
74ccac5c4f

+ 9 - 0
appbuilder-ios/AppBuilder/AppBuilder/FourthTabViewController.swift

@@ -425,6 +425,7 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
                     banner.show()
                     return
                 }
+                Nexilis.showLoader()
                 DispatchQueue.global().async {
                     self.deleteAllRecordDatabase()
                     Nexilis.destroyAll()
@@ -441,6 +442,7 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
                             // pos registration
                             _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
                             DispatchQueue.main.async {
+                                Nexilis.hideLoader()
                                 let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
                                 imageView.tintColor = .white
                                 let banner = FloatingNotificationBanner(title: "Successfully Logout".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
@@ -451,9 +453,16 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
                                 self.makeMenu()
                                 self.tableView.reloadData()
                             }
+                        } else {
+                            Nexilis.hideLoader()
+                            let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
+                            imageView.tintColor = .white
+                            let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
+                            banner.show()
                         }
                     } else {
                         DispatchQueue.main.async {
+                            Nexilis.hideLoader()
                             let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
                             imageView.tintColor = .white
                             let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)

+ 76 - 44
appbuilder-ios/NexilisLite/Nexilis.swift

@@ -18,7 +18,7 @@ import NotificationBannerSwift
 public class Nexilis: NSObject {
     public static var sAPIKey = ""
     
-    static let ADDRESS = ADDRESS_RELEASE
+    public static let ADDRESS = ADDRESS_RELEASE
     
     static let ADDRESS_33 = "192.168.0.33"
     
@@ -52,6 +52,8 @@ public class Nexilis: NSObject {
     
     public static var openBroadcast = false
     
+    public static var loadingAlert = UIAlertController()
+    
     private func createDelegate() {
         print("createDelegate...")
         callDelegate = self
@@ -396,56 +398,36 @@ public class Nexilis: NSObject {
     
     public static func startAudio(nMode: Int!, bSpeakerOn: Bool!) {
         
-        let xSessionMode = nMode == 0 ? nSessionMode : nMode
+        let nSessionMode = nMode
         do {
-            if ("iPhone 6" == UIDevice.current.modelName) {
-                try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: .duckOthers)
-                if (xSessionMode == 1) {
-                    try AVAudioSession.sharedInstance().setMode(.voiceChat)
-                } else if (xSessionMode == 2) {
-                    try AVAudioSession.sharedInstance().setMode(.voiceChat)
-                    // try avAudioSession.setMode(AVAudioSessionModeVideoChat)
-                }
-                if (bSpeakerOn) {
-                    try AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)
-                } else {
-                    try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
-                }
+            let avAudioSession = AVAudioSession.sharedInstance()
+            try avAudioSession.setInputGain(1.0)
+//            if (bSpeakerOn) {
+//                try avAudioSession.setCategory(.playAndRecord, mode: (nSessionMode == 1 ? .voiceChat : .videoChat), options: [.defaultToSpeaker, .duckOthers, .allowBluetooth])
+//            } else {
+//                try avAudioSession.setCategory(.playAndRecord, mode: (nSessionMode == 1 ? .voiceChat : .videoChat), options: [.duckOthers, .allowBluetooth])
+//            }
+            try avAudioSession.setCategory(.playAndRecord, mode: (nSessionMode == 1 ? .voiceChat : .default), options: [.defaultToSpeaker, .duckOthers, .allowBluetooth])
+            if (bSpeakerOn) {
+                API.adjustVolume(fValue: 10.0)
             } else {
-                if (bSpeakerOn) {
-                    try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: .defaultToSpeaker)
-                } else {
-                    try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: .duckOthers)
-                }
-                if (xSessionMode == 1) {
-                    try AVAudioSession.sharedInstance().setMode(.voiceChat)
-                } else if (xSessionMode == 2) {
-                    try AVAudioSession.sharedInstance().setMode(.voiceChat)
-                }
+                API.adjustVolume(fValue: 0.3)
             }
-            try AVAudioSession.sharedInstance().setActive(true)
-        } catch {}
-        nSessionMode = xSessionMode
+            try avAudioSession.setActive(true, options: .notifyOthersOnDeactivation)
+        } catch {
+        }
     }
     
     public static func turnSpeakerOn(bSpeakerOn: Bool!) {
-        do{
-            if ("iPhone 6" == UIDevice.current.modelName) {
-                if (bSpeakerOn) {
-                    try AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)
-                } else {
-                    try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
-                }
-                return
-            }
-        }catch{
-            print(error)
+//         API.pauseAudio()
+//         ViewController.stopAudio()
+//         ViewController.startAudio(nMode: 0, bSpeakerOn: bSpeakerOn)
+//         API.resumeAudio(bSpeakerOn: bSpeakerOn)
+        if (bSpeakerOn) {
+            API.adjustVolume(fValue: 10.0)
+        } else {
+            API.adjustVolume(fValue: 0.3)
         }
-        
-        API.pauseAudio()
-        stopAudio()
-        startAudio(nMode: 0, bSpeakerOn: bSpeakerOn)
-        API.resumeAudio(bSpeakerOn: bSpeakerOn)
     }
     public static func stopAudio() {
         do {
@@ -484,6 +466,8 @@ public class Nexilis: NSObject {
             fb.bniBookingTap()
         } else if id == "openHistoryCC" {
             fb.historyBroadcastTap()
+        } else if index == 7 {
+            fb.openCustomURL(url: id)
         } else {
             let idButton = UIButton()
             idButton.restorationIdentifier = id
@@ -491,6 +475,22 @@ public class Nexilis: NSObject {
         }
     }
     
+    public static func showLoader() {
+        loadingAlert = UIAlertController(title: nil, message: "Please wait...".localized(), preferredStyle: .alert)
+
+        let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
+        loadingIndicator.hidesWhenStopped = true
+        loadingIndicator.style = .medium
+        loadingIndicator.startAnimating()
+
+        loadingAlert.view.addSubview(loadingIndicator)
+        UIApplication.shared.visibleViewController?.present(loadingAlert, animated: true, completion: nil)
+    }
+    
+    public static func hideLoader() {
+        loadingAlert.dismiss(animated: true)
+    }
+    
     private static var groupWait = DispatchGroup()
     
     private static var waitQueue = [String: TMessage]()
@@ -1299,6 +1299,17 @@ extension Nexilis: CallDelegate {
                 if !onGoingCC.isEmpty {
                     videoController.isAutoAccept = true
                     DispatchQueue.main.asyncAfter(deadline: .now() + isShowAlert!, execute: {
+                        if UIApplication.shared.visibleViewController is UIAlertController {
+                            let vc = UIApplication.shared.visibleViewController as! UIAlertController
+                            vc.dismiss(animated: true, completion: {
+                                if UIApplication.shared.visibleViewController?.navigationController != nil {
+                                    UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
+                                } else {
+                                    UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
+                                }
+                            })
+                            return
+                        }
                         if UIApplication.shared.visibleViewController?.navigationController != nil {
                             UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
                         } else {
@@ -1306,6 +1317,17 @@ extension Nexilis: CallDelegate {
                         }
                     })
                 } else {
+                    if UIApplication.shared.visibleViewController is UIAlertController {
+                        let vc = UIApplication.shared.visibleViewController as! UIAlertController
+                        vc.dismiss(animated: true, completion: {
+                            if UIApplication.shared.visibleViewController?.navigationController != nil {
+                                UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
+                            } else {
+                                UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
+                            }
+                        })
+                        return
+                    }
                     if UIApplication.shared.visibleViewController?.navigationController != nil {
                         UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
                     } else {
@@ -2590,6 +2612,11 @@ extension Nexilis: MessageDelegate {
                                     vc.navigationController?.popViewController(animated: true)
                                     openEditor()
                                 }
+                            } else if UIApplication.shared.visibleViewController is UIAlertController {
+                                let vc = UIApplication.shared.visibleViewController as! UIAlertController
+                                vc.dismiss(animated: true, completion: {
+                                    openEditor()
+                                })
                             } else {
                                 openEditor()
                             }
@@ -2656,6 +2683,11 @@ extension Nexilis: MessageDelegate {
                                     vc.navigationController?.popViewController(animated: true)
                                     openEditor()
                                 }
+                            } else if UIApplication.shared.visibleViewController is UIAlertController {
+                                let vc = UIApplication.shared.visibleViewController as! UIAlertController
+                                vc.dismiss(animated: true, completion: {
+                                    openEditor()
+                                })
                             } else {
                                 openEditor()
                             }

+ 2 - 0
appbuilder-ios/NexilisLite/NexilisLite/Resource/id.lproj/Localizable.strings

@@ -176,3 +176,5 @@
 "Video call is over" = "Panngilan video telah berakhir";
 "End Video Call" = "Akhiri Panggilan Video";
 "Are you sure you want to end video call?" = "Apakah anda yakin ingin mengakhiri panggilan video?";
+"Please wait..." = "Mohon tunggu...";
+"Unable to access servers. Try again later" = "Tidak dapat mengakses server. Coba lagi nanti";

+ 18 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -52,6 +52,8 @@ public class Nexilis: NSObject {
     
     public static var openBroadcast = false
     
+    public static var loadingAlert = UIAlertController()
+    
     private func createDelegate() {
         print("createDelegate...")
         callDelegate = self
@@ -473,6 +475,22 @@ public class Nexilis: NSObject {
         }
     }
     
+    public static func showLoader() {
+        loadingAlert = UIAlertController(title: nil, message: "Please wait...".localized(), preferredStyle: .alert)
+
+        let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
+        loadingIndicator.hidesWhenStopped = true
+        loadingIndicator.style = .medium
+        loadingIndicator.startAnimating()
+
+        loadingAlert.view.addSubview(loadingIndicator)
+        UIApplication.shared.visibleViewController?.present(loadingAlert, animated: true, completion: nil)
+    }
+    
+    public static func hideLoader() {
+        loadingAlert.dismiss(animated: true)
+    }
+    
     private static var groupWait = DispatchGroup()
     
     private static var waitQueue = [String: TMessage]()

+ 5 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ChangeDeviceViewController.swift

@@ -92,11 +92,13 @@ public class ChangeDeviceViewController: UIViewController {
             banner.show()
             return
         }
+        Nexilis.showLoader()
         DispatchQueue.global().async {
             let md5Hex = Utils.getMD5(string: password).map { String(format: "%02hhx", $0) }.joined()
             if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignIn(p_name: name, p_password: md5Hex), timeout: 30 * 1000) {
                 if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
                     DispatchQueue.main.async {
+                        Nexilis.hideLoader()
                         let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
                         imageView.tintColor = .white
                         let banner = FloatingNotificationBanner(title: "Invalid user / Username and password does not match".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
@@ -104,6 +106,7 @@ public class ChangeDeviceViewController: UIViewController {
                     }
                 } else if !response.isOk() {
                     DispatchQueue.main.async {
+                        Nexilis.hideLoader()
                         let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
                         imageView.tintColor = .white
                         let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
@@ -122,6 +125,7 @@ public class ChangeDeviceViewController: UIViewController {
                         // pos registration
                         _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
                         DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
+                            Nexilis.hideLoader()
                             let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
                             imageView.tintColor = .white
                             let banner = FloatingNotificationBanner(title: "Successfully changed device".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
@@ -133,6 +137,7 @@ public class ChangeDeviceViewController: UIViewController {
                 }
             } else {
                 DispatchQueue.main.async {
+                    Nexilis.hideLoader()
                     let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
                     imageView.tintColor = .white
                     let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)

+ 8 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ChangeNamePassswordViewController.swift

@@ -125,10 +125,12 @@ public class ChangeNamePassswordViewController: UIViewController {
             banner.show()
             return
         }
+        Nexilis.showLoader()
         DispatchQueue.global().async {
             if let resp = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSendOTPChangeProfile(name: first + " " + last, type: "2")) {
                 if resp.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "1a" {
                     DispatchQueue.main.async {
+                        Nexilis.hideLoader()
                         let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
                         imageView.tintColor = .white
                         let banner = FloatingNotificationBanner(title: "Username has already been registered. Please use another username".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
@@ -151,15 +153,19 @@ public class ChangeNamePassswordViewController: UIViewController {
                             UserDefaults.standard.synchronize()
         //                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateFifthTab"), object: nil, userInfo: nil)
                             DispatchQueue.main.async {
+                                Nexilis.hideLoader()
+                            }
+                            DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
                                 let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
                                 imageView.tintColor = .white
                                 let banner = FloatingNotificationBanner(title: "Successfully changed".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
                                 banner.show()
                                 self.didTapExit(sender: "exit")
-                            }
+                            })
                         }
                     } else {
                         DispatchQueue.main.async {
+                            Nexilis.hideLoader()
                             let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
                             imageView.tintColor = .white
                             let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
@@ -169,6 +175,7 @@ public class ChangeNamePassswordViewController: UIViewController {
                 }
             } else {
                 DispatchQueue.main.async {
+                    Nexilis.hideLoader()
                     let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
                     imageView.tintColor = .white
                     let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)

+ 8 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ProfileViewController.swift

@@ -571,6 +571,9 @@ extension ProfileViewController: ImageVideoPickerDelegate {
             guard let me = UserDefaults.standard.string(forKey: "me") else {
                 return
             }
+            DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
+                Nexilis.showLoader()
+            })
             DispatchQueue.global().async {
                 let resize = image.resize(target: CGSize(width: 800, height: 600))
                 let documentDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
@@ -595,9 +598,14 @@ extension ProfileViewController: ImageVideoPickerDelegate {
                                 let banner = FloatingNotificationBanner(title: "Successfully changed image".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
                                 banner.show()
                                 self.dismissImage?(image, fileDir.lastPathComponent)
+                                Nexilis.hideLoader()
                             }
+                        } else {
+                            Nexilis.hideLoader()
                         }
                     }
+                } else {
+                    Nexilis.hideLoader()
                 }
             }
         }