Skip to content

Commit

Permalink
Merge pull request #307 from AgoraIO-Usecase/dev/scene/show_ios_wu
Browse files Browse the repository at this point in the history
fix: add room destory detected
  • Loading branch information
tamworth authored Dec 30, 2022
2 parents fa7e065 + 2ff4f69 commit 0d6dd77
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
19 changes: 11 additions & 8 deletions iOS/AgoraEntScenarios/Scenes/Show/Controller/ShowRoomListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ class ShowRoomListVC: UIViewController {
// 加入房间
private func joinRoom(_ room: ShowRoomListModel){
AppContext.showServiceImp.joinRoom(room: room) {[weak self] error, detailModel in
if error == nil {
guard let wSelf = self else { return }
let vc = ShowLiveViewController()
vc.audiencePresetType = wSelf.audiencePresetType
vc.room = room
let nc = UINavigationController(rootViewController: vc)
nc.modalPresentationStyle = .fullScreen
wSelf.present(nc, animated: true)
if let error = error {
ToastView.show(text: error.localizedDescription)
return
}

guard let wSelf = self else { return }
let vc = ShowLiveViewController()
vc.audiencePresetType = wSelf.audiencePresetType
vc.room = room
let nc = UINavigationController(rootViewController: vc)
nc.modalPresentationStyle = .fullScreen
wSelf.present(nc, animated: true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,38 +243,48 @@ class ShowSyncManagerServiceImp: NSObject, ShowServiceProtocol {
let params = room.yy_modelToJSONObject() as? [String: Any]

initScene { [weak self] in
SyncUtil.joinScene(id: room.roomId!,
userId: room.ownerId!,
property: params) { result in
// LogUtils.log(message: "result == \(result.toJson() ?? "")", level: .info)
let channelName = result.getPropertyWith(key: "roomId", type: String.self) as? String
let userId = result.getPropertyWith(key: "creator", type: String.self) as? String ?? ""
self?.roomId = channelName
NetworkManager.shared.generateTokens(channelName: channelName ?? "",
uid: "\(UserInfo.userId)",
tokenGeneratorType: .token006,
tokenTypes: [.rtc, .rtm]) { tokenMap in
guard let self = self,
let rtcToken = tokenMap[NetworkManager.AgoraTokenType.rtc.rawValue],
let rtmToken = tokenMap[NetworkManager.AgoraTokenType.rtm.rawValue]
else {
agoraAssert(tokenMap.count == 2, "rtcToken == nil || rtmToken == nil")
return
}
VLUserCenter.user.ifMaster = VLUserCenter.user.id == userId ? true : false
VLUserCenter.user.agoraRTCToken = rtcToken
VLUserCenter.user.agoraRTMToken = rtmToken
let output = ShowRoomDetailModel.yy_model(with: params!)
completion(nil, output)
self._startCheckExpire()
self._subscribeAll()
self._addUserIfNeed()
self._getAllPKInvitationList(room: nil) { error, list in
//TODO: check room vaild
self?._getRoomList(page: 0) { [weak self] error, list in
guard let _ = list?.filter({ room.objectId == $0.objectId }).first else {
completion(NSError(domain: "Show Service Error", code: 1, userInfo: [ NSLocalizedDescriptionKey : "show_error_room_has_been_destory".show_localized]), nil)
return
}

SyncUtil.joinScene(id: room.roomId!,
userId: room.ownerId!,
property: params) { result in
// LogUtils.log(message: "result == \(result.toJson() ?? "")", level: .info)
let channelName = result.getPropertyWith(key: "roomId", type: String.self) as? String
let userId = result.getPropertyWith(key: "creator", type: String.self) as? String ?? ""
self?.roomId = channelName
NetworkManager.shared.generateTokens(channelName: channelName ?? "",
uid: "\(UserInfo.userId)",
tokenGeneratorType: .token006,
tokenTypes: [.rtc, .rtm]) { tokenMap in
guard let self = self,
let rtcToken = tokenMap[NetworkManager.AgoraTokenType.rtc.rawValue],
let rtmToken = tokenMap[NetworkManager.AgoraTokenType.rtm.rawValue]
else {
agoraAssert(tokenMap.count == 2, "rtcToken == nil || rtmToken == nil")
return
}
VLUserCenter.user.ifMaster = VLUserCenter.user.id == userId ? true : false
VLUserCenter.user.agoraRTCToken = rtcToken
VLUserCenter.user.agoraRTMToken = rtmToken
let output = ShowRoomDetailModel.yy_model(with: params!)
completion(nil, output)
self._startCheckExpire()
self._subscribeAll()
self._addUserIfNeed()
self._getAllPKInvitationList(room: nil) { error, list in
}
}
} fail: { error in
completion(error.toNSError(), nil)
}
} fail: { error in
completion(error.toNSError(), nil)
}


}
}

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 0d6dd77

Please sign in to comment.