From 4ee9995fa9ba3b63a1b439534d32290d467bca62 Mon Sep 17 00:00:00 2001 From: VladimirBrejcha Date: Tue, 27 Apr 2021 20:33:34 +0300 Subject: [PATCH] (ScreenSharing) Implement log file sharing functionality --- ScreenSharing/AppDelegate.swift | 5 +- .../Stories/LoginViewController.swift | 28 ++++---- .../Stories/MainViewController.swift | 71 +++++++++---------- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/ScreenSharing/AppDelegate.swift b/ScreenSharing/AppDelegate.swift index 44588a0..8ce729a 100644 --- a/ScreenSharing/AppDelegate.swift +++ b/ScreenSharing/AppDelegate.swift @@ -19,13 +19,12 @@ fileprivate let callManager: CallManager = CallManager(client, authService, darw fileprivate let storyAssembler: StoryAssembler = StoryAssembler(authService: authService, callManager: callManager) @UIApplicationMain -final class AppDelegate: UIResponder, UIApplicationDelegate, Loggable { +final class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - var appName: String { "ScreenSharing" } override init() { super.init() - configureDefaultLogging() + Logger.configure(appName: "ScreenSharing") } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { diff --git a/ScreenSharing/Stories/LoginViewController.swift b/ScreenSharing/Stories/LoginViewController.swift index ef80381..0f9e9d7 100644 --- a/ScreenSharing/Stories/LoginViewController.swift +++ b/ScreenSharing/Stories/LoginViewController.swift @@ -12,9 +12,7 @@ final class LoginViewController: UIViewController, LoadingShowable { override func viewDidLoad() { super.viewDidLoad() - - loginView.setTitle(text: "Screen sharing demo") - + let loginHandler: AuthService.LoginCompletion = { [weak self] error in guard let self = self else { return } self.hideProgress() @@ -24,16 +22,20 @@ final class LoginViewController: UIViewController, LoadingShowable { self.present(self.storyAssembler.main, animated: true) } } - - loginView.loginTouchHandler = { [weak self] username, password in - Log.d("Manually Logging in with password") - self?.showLoading(title: "Connecting", details: "Please wait...") - self?.authService.login( - user: username.appendingVoxDomain, - password: password, - loginHandler - ) - } + + loginView.configure( + title: "Screen sharing demo", + controller: self, + loginHandler: { [weak self] username, password in + Log.d("Manually Logging in with password") + self?.showLoading(title: "Connecting", details: "Please wait...") + self?.authService.login( + user: username.appendingVoxDomain, + password: password, + loginHandler + ) + } + ) if authService.possibleToLogin { Log.d("Automatically Logging in with token") diff --git a/ScreenSharing/Stories/MainViewController.swift b/ScreenSharing/Stories/MainViewController.swift index 7819543..0900e90 100644 --- a/ScreenSharing/Stories/MainViewController.swift +++ b/ScreenSharing/Stories/MainViewController.swift @@ -19,46 +19,45 @@ final class MainViewController: override func viewDidLoad() { super.viewDidLoad() - - if let displayName = authService.loggedInUserDisplayName { - mainView.setDisplayName(text: "Logged in as \(displayName)") - } - - mainView.callTouchHandler = { [weak self] username in - Log.d("Calling \(String(describing: username))") - PermissionsHelper.requestRecordPermissions(includingVideo: true) { error in - if let error = error { - self?.handleError(error) - return - } - - guard let self = self else { return } - - let beginCall = { - do { - try self.callManager.makeOutgoingCall(to: username ?? "") - self.view.endEditing(true) - self.present(AnimatedTransitionNavigationController( - rootViewController: self.storyAssembler.call), animated: true) - } catch (let error) { - Log.e(error.localizedDescription) - AlertHelper.showError(message: error.localizedDescription, on: self) + + mainView.configure( + displayName: "Logged in as \(authService.loggedInUserDisplayName ?? "")", + controller: self, + callHandler: { [weak self] username in + Log.d("Calling \(String(describing: username))") + PermissionsHelper.requestRecordPermissions(includingVideo: true) { error in + if let error = error { + self?.handleError(error) + return + } + + guard let self = self else { return } + + let beginCall = { + do { + try self.callManager.makeOutgoingCall(to: username ?? "") + self.view.endEditing(true) + self.present(AnimatedTransitionNavigationController( + rootViewController: self.storyAssembler.call), animated: true) + } catch (let error) { + Log.e(error.localizedDescription) + AlertHelper.showError(message: error.localizedDescription, on: self) + } + } + + if !self.authService.isLoggedIn { + self.reconnect(onSuccess: beginCall) + } else { + beginCall() } } - - if !self.authService.isLoggedIn { - self.reconnect(onSuccess: beginCall) - } else { - beginCall() + }, + logoutHandler: { [weak self] in + self?.authService.logout { + self?.dismiss(animated: true) } } - } - - mainView.logoutTouchHandler = { [weak self] in - self?.authService.logout { - self?.dismiss(animated: true) - } - } + ) } // MARK: - AppLifeCycleDelegate -