Files
yinmeng-ios/xplan-ios/Main/Room/View/XPRoomViewController.m
2021-11-05 17:21:24 +08:00

241 lines
7.7 KiB
Objective-C

//
// XPRoomViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/10/11.
//
#import "XPRoomViewController.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "XPMacro.h"
#import "AccountInfoStorage.h"
#import "RtcManager.h"
///Model
#import "RoomInfoModel.h"
#import "UserInfoModel.h"
///View
#import "BaseNavigationController.h"
#import "XPRoomActivityContainerView.h"
#import "XPRoomBackContainerView.h"
#import "XPRoomMenuContainerView.h"
#import "XPRoomMessageContainerView.h"
#import "RoomHeaderView.h"
#import "SocialStageView.h"
///P
#import "XPRoomPresenter.h"
#import "XPRoomProtocol.h"
#import "RoomHostDelegate.h"
#import "RoomGuestDelegate.h"
@interface XPRoomViewController ()<XPRoomProtocol, RoomHostDelegate>
///背景
@property (nonatomic,strong) XPRoomBackContainerView *backContainerView;
///房间信息
@property (nonatomic,strong) RoomHeaderView *roomHeaderView;
///坑位信息
@property (nonatomic,strong) SocialStageView *stageView;
///公屏
@property (nonatomic,strong) XPRoomMessageContainerView *messageContainerView;
///底部操作栏
@property (nonatomic,strong) XPRoomMenuContainerView *menuContainerView;
///活动
@property (nonatomic,strong) XPRoomActivityContainerView *activityContainerView;
//房间的Uid
@property (nonatomic,copy) NSString * roomUid;
///用户信息
@property (nonatomic,strong) UserInfoModel *userInfo;
///房间信息
@property (nonatomic,strong) RoomInfoModel *roomInfo;
@end
@implementation XPRoomViewController
+ (BOOL)openRoom:(NSString *)roomUid viewController:(UIViewController *)viewController {
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;
}
- (void)dealloc {
#warning to dox - 时刻注意这个方法 功能做完的时候删除此方法
}
- (XPRoomPresenter *)createPresenter {
return [[XPRoomPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
#pragma mark - Private Method
- (void)initSubViews {
[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 {
[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);
}];
}
#pragma mark - XPRoomProtocol
- (void)initEnterRoomSuccess:(RoomInfoModel *)roomInfo user:(UserInfoModel *)userInfo {
self.roomInfo = roomInfo;
self.userInfo = userInfo;
if (roomInfo.valid) { // 房间有效,直接进入房间
// TODO: S1 没有考虑进房密码的情况
[self.roomHeaderView onRoomUpdate];
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
} 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 { // 当前用户进入别人房间
// TODO: 房主已经下线。
[self showSuccessToast:@"房主已下线"];
[self enterRoomFail];
}
}
}
- (void)openRoomSuccess:(RoomInfoModel *)roomInfo {
self.roomInfo = roomInfo;
[self.roomHeaderView onRoomUpdate];
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
- (void)enterRoomSuccess {
[self.stageView onRoomEntered];
}
- (void)enterRoomFail {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - RoomDelegate
- (RoomInfoModel *)getRoomInfo {
return self.roomInfo;
}
- (UserInfoModel *)getUserInfo {
return self.userInfo;
}
- (NSMutableDictionary<NSString *,MicroQueueModel *> *)getMicroQueue {
return [self.stageView getMicroQueue];
}
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
[self.menuContainerView onMicroQueueUpdate:queue];
}
- (void)exitRoom {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[[RtcManager instance] destory];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (XPRoomBackContainerView *)backContainerView {
if (!_backContainerView) {
_backContainerView = [[XPRoomBackContainerView alloc] init];
}
return _backContainerView;
}
- (RoomHeaderView *)roomHeaderView {
if (!_roomHeaderView) {
_roomHeaderView = [[RoomHeaderView alloc] initWithDelegate:self];
}
return _roomHeaderView;
}
- (SocialStageView *)stageView {
if (!_stageView) {
_stageView = [[SocialStageView alloc] initWithDelegate:self];
}
return _stageView;
}
- (XPRoomMessageContainerView *)messageContainerView {
if (!_messageContainerView) {
_messageContainerView = [[XPRoomMessageContainerView alloc] initWithDelegate:self];
}
return _messageContainerView;
}
- (XPRoomMenuContainerView *)menuContainerView {
if (!_menuContainerView) {
_menuContainerView = [[XPRoomMenuContainerView alloc] initWithDelegate:self];
}
return _menuContainerView;
}
- (XPRoomActivityContainerView *)activityContainerView {
if (!_activityContainerView) {
_activityContainerView = [[XPRoomActivityContainerView alloc] init];
}
return _activityContainerView;
}
@end