Files
yinmeng-ios/xplan-ios/Main/Room/View/XPRoomViewController.m

283 lines
9.3 KiB
Mathematica
Raw Normal View History

//
// XPRoomViewController.m
// xplan-ios
//
// Created by on 2021/10/11.
//
#import "XPRoomViewController.h"
///Third
#import <Masonry/Masonry.h>
2021-12-02 00:09:04 +08:00
#import <NIMSDK/NIMSDK.h>
///Tool
#import "XPMacro.h"
2021-10-19 18:30:03 +08:00
#import "AccountInfoStorage.h"
2021-10-22 17:40:52 +08:00
#import "RtcManager.h"
///Model
#import "RoomInfoModel.h"
2021-10-19 18:30:03 +08:00
#import "UserInfoModel.h"
2021-12-02 00:09:04 +08:00
#import "AttachmentModel.h"
///View
2021-10-29 18:17:27 +08:00
#import "BaseNavigationController.h"
#import "XPRoomActivityContainerView.h"
#import "XPRoomBackContainerView.h"
#import "XPRoomMenuContainerView.h"
#import "XPRoomMessageContainerView.h"
#import "RoomHeaderView.h"
2021-10-26 19:14:01 +08:00
#import "SocialStageView.h"
#import "XPMiniRoomView.h"
2021-10-19 18:30:03 +08:00
///P
#import "XPRoomPresenter.h"
#import "XPRoomProtocol.h"
#import "RoomHostDelegate.h"
#import "RoomGuestDelegate.h"
2021-12-02 00:09:04 +08:00
@interface XPRoomViewController ()<XPRoomProtocol, RoomHostDelegate, NIMChatroomManagerDelegate>
///
@property (nonatomic,strong) XPRoomBackContainerView *backContainerView;
///
@property (nonatomic,strong) RoomHeaderView *roomHeaderView;
///
2021-10-26 19:14:01 +08:00
@property (nonatomic,strong) SocialStageView *stageView;
///
@property (nonatomic,strong) XPRoomMessageContainerView *messageContainerView;
///
@property (nonatomic,strong) XPRoomMenuContainerView *menuContainerView;
///
@property (nonatomic,strong) XPRoomActivityContainerView *activityContainerView;
2021-10-26 19:14:01 +08:00
///Uid
2021-10-29 18:17:27 +08:00
@property (nonatomic,copy) NSString * roomUid;
2021-10-19 18:30:03 +08:00
///
2021-10-26 19:14:01 +08:00
@property (nonatomic,strong) UserInfoModel *userInfo;
2021-10-19 18:30:03 +08:00
///
@property (nonatomic,strong) RoomInfoModel *roomInfo;
@end
@implementation XPRoomViewController
2021-10-29 18:17:27 +08:00
+ (BOOL)openRoom:(NSString *)roomUid viewController:(UIViewController *)viewController {
if ([XPMiniRoomView shareMiniRoomView].currentRoomUid.integerValue > 0 && [XPMiniRoomView shareMiniRoomView].currentRoomUid.integerValue != roomUid.integerValue) {
// 退
[[RtcManager instance] exitRoom];
}
///
[[XPMiniRoomView shareMiniRoomView] hiddenRoomMiniView];
2021-10-29 18:17:27 +08:00
XPRoomViewController * roomVC = [[self alloc] init];
roomVC.roomUid = roomUid;
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:baseNav animated:YES completion:nil];
return YES;
}
2021-10-19 18:30:03 +08:00
- (void)dealloc {
#warning to dox -
2021-11-04 17:48:32 +08:00
2021-10-19 18:30:03 +08:00
}
- (XPRoomPresenter *)createPresenter {
2021-11-04 17:48:32 +08:00
return [[XPRoomPresenter alloc] init];
2021-10-19 18:30:03 +08:00
}
- (BOOL)isHiddenNavBar {
2021-11-04 17:48:32 +08:00
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
2021-11-04 17:48:32 +08:00
[self initSubViews];
[self initSubViewConstraints];
2021-11-04 20:56:54 +08:00
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
2021-11-17 19:29:14 +08:00
///
[self.presenter getNormalGiftList:self.roomUid];
2021-12-02 00:09:04 +08:00
//
[[NIMSDK sharedSDK].chatroomManager addDelegate:self];
2021-10-21 17:55:51 +08:00
}
2021-10-29 15:53:44 +08:00
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
2021-11-04 17:48:32 +08:00
[self.view endEditing:YES];
2021-10-29 15:53:44 +08:00
}
2021-11-04 17:48:32 +08:00
2021-11-18 18:43:20 +08:00
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self.backContainerView superViewDidLayoutViews];
}
#pragma mark - Private Method
- (void)initSubViews {
2021-11-04 17:48:32 +08:00
[self.view addSubview:self.backContainerView];
[self.view addSubview:self.roomHeaderView];
[self.view addSubview:self.stageView];
[self.view addSubview:self.messageContainerView];
[self.view addSubview:self.menuContainerView];
[self.view addSubview:self.activityContainerView];
}
- (void)initSubViewConstraints {
2021-11-04 17:48:32 +08:00
[self.backContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self.roomHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
[self.stageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
}];
[self.messageContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.stageView.mas_bottom);
make.bottom.equalTo(self.menuContainerView.mas_top).offset(-5);
make.left.equalTo(self.view);
make.right.equalTo(self.activityContainerView.mas_left).offset(-10);
}];
[self.menuContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.bottom.mas_equalTo(-kSafeAreaBottomHeight- 8);
make.height.mas_equalTo(40);
}];
[self.activityContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.messageContainerView);
make.right.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.menuContainerView.mas_top).offset(-5);
make.width.mas_equalTo(80);
}];
}
2021-10-26 19:14:01 +08:00
2021-10-19 18:30:03 +08:00
#pragma mark - XPRoomProtocol
2021-11-04 17:48:32 +08:00
- (void)initEnterRoomSuccess:(RoomInfoModel *)roomInfo user:(UserInfoModel *)userInfo {
self.roomInfo = roomInfo;
self.userInfo = userInfo;
if (roomInfo.valid) { //
2021-12-01 18:27:08 +08:00
if (roomInfo.roomPwd.length > 0) {//
[self showErrorToast:@"房间已上锁"];
[self enterRoomFail];
} else {
[self.roomHeaderView onRoomUpdate];
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2021-11-04 17:48:32 +08:00
} else { //
if ([self.roomUid isEqualToString:[NSString stringWithFormat:@"%ld", userInfo.uid]]) { //
if (roomInfo.roomId > 0) { // 使
[self.presenter openRoom:roomInfo.title type:roomInfo.type roomPwd:roomInfo.roomPwd roomDesc:roomInfo.roomDesc backPic:@""];
} else { //
NSString* title = [NSString stringWithFormat:@"%@的房间", userInfo.nick];
[self.presenter openRoom:title type:RoomType_Game roomPwd:@"" roomDesc:@"" backPic:@""];
}
} else { //
2021-10-21 17:55:51 +08:00
// TODO: 线
2021-11-04 17:48:32 +08:00
[self showSuccessToast:@"房主已下线"];
[self enterRoomFail];
2021-10-21 17:55:51 +08:00
}
}
2021-10-19 18:30:03 +08:00
}
- (void)openRoomSuccess:(RoomInfoModel *)roomInfo {
2021-10-26 19:14:01 +08:00
self.roomInfo = roomInfo;
[self.roomHeaderView onRoomUpdate];
2021-10-26 19:14:01 +08:00
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2021-10-26 19:14:01 +08:00
- (void)enterRoomSuccess {
[self.stageView onRoomEntered];
2021-10-19 18:30:03 +08:00
}
2021-10-21 17:55:51 +08:00
- (void)enterRoomFail {
[self dismissViewControllerAnimated:YES completion:nil];
}
2021-12-02 00:09:04 +08:00
#pragma mark - NIMChatManagerDelegate
- (void)chatroomBeKicked:(NIMChatroomBeKickedResult *)result {
if (result.reason == 2) {
[self showErrorToast:@"您被管理员踢出直播间"];
} else if (result.reason == 5) {
[self showErrorToast:@"您已被管理员拉黑"];
}
[[RtcManager instance] exitRoom];
2021-12-02 00:09:04 +08:00
[self enterRoomFail];
}
2021-10-26 19:14:01 +08:00
#pragma mark - RoomDelegate
- (RoomInfoModel *)getRoomInfo {
return self.roomInfo;
}
- (UserInfoModel *)getUserInfo {
return self.userInfo;
}
2021-11-15 18:59:44 +08:00
- (UINavigationController *)getCurrentNav {
return self.navigationController;
}
2021-11-04 19:01:19 +08:00
- (NSMutableDictionary<NSString *,MicroQueueModel *> *)getMicroQueue {
return [self.stageView getMicroQueue];
}
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
[self.menuContainerView onMicroQueueUpdate:queue];
2021-11-04 19:01:19 +08:00
}
- (void)exitRoom {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[self dismissViewControllerAnimated:YES completion:nil];
}
2021-12-03 17:07:21 +08:00
- (void)miniRoom {
[[XPMiniRoomView shareMiniRoomView] configRoomMiniView:self.roomInfo];
2021-12-03 17:07:21 +08:00
[self.view endEditing:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (XPRoomBackContainerView *)backContainerView {
2021-11-04 17:48:32 +08:00
if (!_backContainerView) {
_backContainerView = [[XPRoomBackContainerView alloc] initWithdelegate:self];
2021-11-04 17:48:32 +08:00
}
return _backContainerView;
}
- (RoomHeaderView *)roomHeaderView {
2021-11-04 17:48:32 +08:00
if (!_roomHeaderView) {
_roomHeaderView = [[RoomHeaderView alloc] initWithDelegate:self];
}
return _roomHeaderView;
}
2021-10-26 19:14:01 +08:00
- (SocialStageView *)stageView {
2021-11-04 17:48:32 +08:00
if (!_stageView) {
_stageView = [[SocialStageView alloc] initWithDelegate:self];
}
return _stageView;
}
- (XPRoomMessageContainerView *)messageContainerView {
2021-11-04 17:48:32 +08:00
if (!_messageContainerView) {
_messageContainerView = [[XPRoomMessageContainerView alloc] initWithDelegate:self];
}
return _messageContainerView;
}
- (XPRoomMenuContainerView *)menuContainerView {
2021-11-04 17:48:32 +08:00
if (!_menuContainerView) {
_menuContainerView = [[XPRoomMenuContainerView alloc] initWithDelegate:self];
}
return _menuContainerView;
}
- (XPRoomActivityContainerView *)activityContainerView {
2021-11-04 17:48:32 +08:00
if (!_activityContainerView) {
_activityContainerView = [[XPRoomActivityContainerView alloc] init];
}
return _activityContainerView;
}
@end