MemberInviteViewModel.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // MemberInviteViewModel.swift
  3. // TUIRoomKit
  4. //
  5. // Created by krabyu on 2023/8/21.
  6. //
  7. import Foundation
  8. import RTCRoomEngine
  9. protocol MemberInviteResponder : NSObjectProtocol {
  10. func showCopyToast(copyType: CopyType?)
  11. }
  12. class MemberInviteViewModel {
  13. var title: String = .inviteMembersToJoin
  14. private(set) lazy var messageItems: [ListCellItemData] = {
  15. return generateListData()
  16. }()
  17. private lazy var roomInfo = {
  18. EngineManager.shared.store.roomInfo
  19. }()
  20. private lazy var conferenceInfoDetails = {
  21. title
  22. }()
  23. private var roomLink: String? {
  24. guard let bundleId = Bundle.main.bundleIdentifier else { return nil }
  25. if bundleId == "com.tencent.tuiroom.apiexample" || bundleId == "com.tencent.fx.rtmpdemo" {
  26. return "https://web.sdk.qcloud.com/trtc/webrtc/test/tuiroom-inner/index.html#/" + "room?roomId=" + roomInfo.roomId
  27. } else if bundleId == "com.tencent.mrtc" {
  28. return "https://web.sdk.qcloud.com/component/tuiroom/index.html#/" + "room?roomId=" + roomInfo.roomId
  29. } else {
  30. return nil
  31. }
  32. }
  33. weak var viewResponder: MemberInviteResponder?
  34. func createListCellItemData(titleText: String, messageText: String,
  35. hasButton: Bool, copyType: CopyType?) -> ListCellItemData {
  36. let item = ListCellItemData()
  37. item.titleText = titleText
  38. item.messageText = messageText
  39. item.hasRightButton = hasButton
  40. if hasButton {
  41. let buttonData = ButtonItemData()
  42. buttonData.normalIcon = "room_copy"
  43. buttonData.normalTitle = .copyText
  44. buttonData.cornerRadius = 4
  45. buttonData.titleFont = UIFont(name: "PingFangSC-Regular", size: 12)
  46. buttonData.titleColor = UIColor(0xB2BBD1)
  47. buttonData.backgroundColor = UIColor(0x6B758A).withAlphaComponent(0.7)
  48. buttonData.resourceBundle = tuiRoomKitBundle()
  49. buttonData.action = { [weak self] sender in
  50. guard let self = self, let button = sender as? UIButton else { return }
  51. self.copyAction(sender: button, text: item.messageText,copyType: copyType)
  52. }
  53. conferenceInfoDetails = conferenceInfoDetails + "\n\(titleText) : \(messageText)"
  54. item.buttonData = buttonData
  55. }
  56. return item
  57. }
  58. func generateListData() -> [ListCellItemData] {
  59. var array: [ListCellItemData] = []
  60. let roomNametem = createListCellItemData(titleText: .roomName, messageText: roomInfo.name, hasButton: false, copyType: nil)
  61. array.append(roomNametem)
  62. let roomTypeItem = createListCellItemData(titleText: .roomType, messageText: roomInfo.isSeatEnabled ? .onStageSpeechRoom : .freeSpeechRoom, hasButton: false, copyType: nil)
  63. array.append(roomTypeItem)
  64. let roomIdItem = createListCellItemData(titleText: .roomIdText, messageText: roomInfo.roomId, hasButton: true, copyType: .copyRoomIdType)
  65. array.append(roomIdItem)
  66. if roomInfo.password.count > 0 {
  67. let roomPasswordItem = createListCellItemData(titleText: .roomPassword, messageText: roomInfo.password, hasButton: true, copyType: .copyRoomPassword)
  68. array.append(roomPasswordItem)
  69. }
  70. if let roomLink = roomLink {
  71. let roomLinkItem = createListCellItemData(titleText: .roomLinkText, messageText: roomLink, hasButton: true, copyType: .copyRoomLinkType)
  72. array.append(roomLinkItem)
  73. }
  74. return array
  75. }
  76. func copyAction(sender: UIButton, text: String, copyType: CopyType?) {
  77. UIPasteboard.general.string = text
  78. viewResponder?.showCopyToast(copyType: copyType)
  79. }
  80. func copyAction() {
  81. UIPasteboard.general.string = conferenceInfoDetails
  82. }
  83. func reportMemberInvitePanelShow() {
  84. RoomKitReport.reportData(.metricsShareRoomInfoPanelShow)
  85. }
  86. deinit {
  87. debugPrint("deinit \(self)")
  88. }
  89. }
  90. private extension String {
  91. static var roomIdText: String {
  92. localized("ConferenceID")
  93. }
  94. static var roomLinkText: String {
  95. localized("Link")
  96. }
  97. static var copyText: String {
  98. localized("Copy")
  99. }
  100. static var inviteMemberText: String {
  101. localized("Invite member")
  102. }
  103. static let roomPassword = localized("Conference password")
  104. static let conferencePasswordSuccess = localized("Conference password copied successfully.")
  105. static let roomName = localized("Room name")
  106. static let roomType = localized("Room type")
  107. static let freeSpeechRoom = localized("Free Speech Room")
  108. static let onStageSpeechRoom = localized("On-stage Speech Room")
  109. static let inviteMembersToJoin = localized("Invite Others")
  110. }