AppUtils.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // appUtil.swift
  3. // trtcScenesDemo
  4. //
  5. // Created by xcoderliu on 12/24/19.
  6. // Copyright © 2019 xcoderliu. All rights reserved.
  7. //
  8. import UIKit
  9. import ImSDK_Plus
  10. import TUIRoomKit
  11. import RTCRoomEngine
  12. // IMSDK APNS ID
  13. #if DEBUG
  14. let timSdkBusiId: UInt32 = 18_069
  15. #else
  16. let timSdkBusiId: UInt32 = 18_070
  17. #endif
  18. class AppUtils: NSObject {
  19. var roomId: String?
  20. var notificationType: String?
  21. var extString: String?
  22. weak var navigationController: UINavigationController?
  23. @objc static let shared = AppUtils()
  24. private override init() {
  25. super.init()
  26. ConferenceSession.sharedInstance.addObserver(observer: self)
  27. }
  28. @objc var appDelegate: AppDelegate {
  29. return UIApplication.shared.delegate as! AppDelegate
  30. }
  31. @objc var curUserId: String {
  32. #if NOT_LOGIN
  33. return ""
  34. #else
  35. return V2TIMManager.sharedInstance()?.getLoginUser() ?? ""
  36. #endif
  37. }
  38. func showConferenceMainViewController(roomId: String) {
  39. guard !(navigationController?.viewControllers.last is ConferenceMainViewController) else { return }
  40. let conferenceViewController = ConferenceMainViewController()
  41. let params = JoinConferenceParams(roomId: roomId)
  42. params.isOpenMicrophone = true
  43. params.isOpenCamera = false
  44. conferenceViewController.setJoinConferenceParams(params: params)
  45. navigationController?.pushViewController(conferenceViewController, animated: true)
  46. }
  47. func showConferenceOptionsViewController(nav: UINavigationController?) {
  48. guard ProfileManager.shared.curUserID() != nil else {
  49. debugPrint("not login")
  50. return
  51. }
  52. let prepareViewController = ConferenceOptionsViewController()
  53. navigationController = nav
  54. navigationController?.pushViewController(prepareViewController, animated: false)
  55. guard let roomId = roomId else { return }
  56. switch notificationType {
  57. case "conference_will_start":
  58. showConferenceMainViewController(roomId: roomId)
  59. case "conference_invitation":
  60. guard let extString = extString else { return }
  61. InvitationObserverService.shared.show(extString: extString)
  62. default:
  63. break
  64. }
  65. self.roomId = nil
  66. self.notificationType = nil
  67. self.extString = nil
  68. }
  69. }
  70. extension AppUtils: ConferenceObserver {
  71. func onConferenceStarted(roomInfo: TUIRoomInfo, error: TUIError, message: String) {
  72. if error != .success {
  73. navigationController?.popViewController(animated: true)
  74. }
  75. }
  76. func onConferenceJoined(roomInfo: TUIRoomInfo, error: TUIError, message: String) {
  77. if error != .success {
  78. navigationController?.popViewController(animated: true)
  79. }
  80. }
  81. }