669 lines
26 KiB
Objective-C
669 lines
26 KiB
Objective-C
//
|
|
// MewRoomViewController.m
|
|
// mew-ios
|
|
//
|
|
// Created by 触海 on 2023/11/7.
|
|
//
|
|
|
|
|
|
///View
|
|
#import "MewRoomViewController.h"
|
|
#import "BaseNavigationController.h"
|
|
#import "MewRoomHeaderView.h"
|
|
#import "MewRoomRightView.h"
|
|
#import "MewSocialStageView.h"
|
|
#import "YMRoomMessageContainerView.h"
|
|
#import "YMRoomSendTextView.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
#import "RoomInfoModel.h"
|
|
#import "YMMessageInfoModel.h"
|
|
#import "AttachmentModel.h"
|
|
#import "MicroQueueModel.h"
|
|
#import "GiftInfoModel.h"
|
|
///Tool
|
|
#import "AccountInfoStorage.h"
|
|
#import "YMHUDTool.h"
|
|
#import "YMRoomMiniManager.h"
|
|
#import "YMMacro.h"
|
|
#import "NSArray+Safe.h"
|
|
#import "RtcManager.h"
|
|
///P
|
|
#import "YMRoomPresenter.h"
|
|
#import "YMRoomProtocol.h"
|
|
#import "RoomHostDelegate.h"
|
|
/// Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <NIMSDK/NIMSDK.h>
|
|
|
|
|
|
@interface MewRoomViewController ()<YMRoomProtocol,
|
|
NIMChatroomManagerDelegate, NIMChatManagerDelegate, NIMConversationManagerDelegate, NIMLoginManagerDelegate,
|
|
RoomHostDelegate, MewRoomRightViewDelegate, MewRoomHeaderViewDelegate>
|
|
|
|
// 背景
|
|
@property (nonatomic, strong) UIImageView *roomBgImageView;
|
|
@property (nonatomic, strong) MewRoomHeaderView *roomHeaderView;
|
|
@property (nonatomic, strong) MewRoomRightView *roomRightView;
|
|
@property (nonatomic, strong) StageView *stageView;
|
|
@property (nonatomic, strong) YMRoomMessageContainerView *messageContainerView;
|
|
@property (nonatomic, strong) UIImageView *emojiImageView;
|
|
|
|
///输入框
|
|
@property (nonatomic,strong) YMRoomSendTextView *inputTextView;
|
|
|
|
/// 房间的Uid
|
|
@property (nonatomic, strong) NSString *roomUid;
|
|
/// 跟随的
|
|
@property (nonatomic, strong) NSString *fromNick;
|
|
@property (nonatomic,assign) UserEnterRoomFromType fromType;
|
|
@property (nonatomic,copy) NSString *fromUid;
|
|
/// 用户信息
|
|
@property (nonatomic, strong) UserInfoModel *userInfo;
|
|
///房间信息
|
|
@property (nonatomic, strong) RoomInfoModel *roomInfo;
|
|
|
|
@property (nonatomic, assign) BOOL isPlayEmojiAnimation;
|
|
@property (nonatomic, copy) NSArray<NSString *> *emojiArrays;
|
|
@property (nonatomic, strong) NSMutableArray<NSString *> *playEmojiArrays;
|
|
|
|
///是否是最小化进房
|
|
@property (nonatomic,assign) BOOL isMiniEnter;
|
|
@end
|
|
|
|
@implementation MewRoomViewController
|
|
#pragma mark - Super
|
|
- (YMRoomPresenter *)createPresenter {
|
|
return [[YMRoomPresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
|
|
#pragma mark - Life Cycle
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initView];
|
|
self.emojiArrays = @[@"mew_room_emoji_deyi",@"mew_room_emoji_happy",@"mew_room_emoji_sex",@"mew_room_emoji_suprise"];
|
|
self.playEmojiArrays = [NSMutableArray array];
|
|
self.isPlayEmojiAnimation = NO;
|
|
|
|
if (self.isMiniEnter) {
|
|
//最小化进房
|
|
|
|
} else {
|
|
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
|
|
}
|
|
|
|
//监听云信消息
|
|
[[NIMSDK sharedSDK].chatroomManager addDelegate:self];
|
|
[[NIMSDK sharedSDK].chatManager addDelegate:self];
|
|
[[NIMSDK sharedSDK].loginManager addDelegate:self];
|
|
[[NIMSDK sharedSDK].conversationManager addDelegate:self];
|
|
}
|
|
|
|
#pragma mark - dealloc
|
|
- (void)dealloc {
|
|
#warning to dox - 时刻注意这个方法 功能做完的时候删除此方法
|
|
NSLog(@"房间销毁了");
|
|
[[NIMSDK sharedSDK].chatroomManager removeDelegate:self];
|
|
[[NIMSDK sharedSDK].chatManager removeDelegate:self];
|
|
[[NIMSDK sharedSDK].loginManager removeDelegate:self];
|
|
[[NIMSDK sharedSDK].conversationManager removeDelegate:self];
|
|
// [[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
}
|
|
|
|
#pragma mark - NIMChatManagerDelegate
|
|
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
|
|
for (NIMMessage * message in messages) {
|
|
///房间内收到p2p的消息 比如升级消息
|
|
if (message.session.sessionType == NIMSessionTypeP2P) {
|
|
if(message.messageType == NIMMessageTypeCustom) {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
|
|
AttachmentModel * attachment = obj.attachment;
|
|
if (attachment.first == CustomMessageType_User_UpGrade) {
|
|
// ContentLevelUpgradeModel * levelInfo = [ContentLevelUpgradeModel modelWithDictionary:attachment.data];
|
|
// if (attachment.second == Custom_Message_Sub_User_UpGrade_Exper) {
|
|
// self.userInfo.userLevelVo.experLevelSeq = levelInfo.levelSeq;
|
|
// } else if(attachment.second == Custom_Message_Sub_User_UpGrade_Charm) {
|
|
// self.userInfo.userLevelVo.charmLevelSeq = levelInfo.levelSeq;
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 非房间内消息不处理
|
|
if (message.session.sessionType != NIMSessionTypeChatroom) {
|
|
continue;
|
|
}
|
|
|
|
// 非本房间不处理
|
|
if (![message.session.sessionId isEqualToString:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]]) {
|
|
continue;
|
|
}
|
|
|
|
if (message.messageType == NIMMessageTypeNotification) {
|
|
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
|
|
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
|
|
NSInteger onLineNumber = self.roomInfo.onlineNum;
|
|
switch (content.eventType) {
|
|
case NIMChatroomEventTypeInfoUpdated: // 麦序状态更新
|
|
{
|
|
NSDictionary *data = [content.notifyExt toJSONObject];
|
|
int type = [data[@"type"] intValue];
|
|
switch (type) {
|
|
case 1:
|
|
case 3:
|
|
{
|
|
NSMutableDictionary *lastRoomInfoDic = [NSMutableDictionary dictionaryWithDictionary:[self.roomInfo model2dictionary]];
|
|
[lastRoomInfoDic addEntriesFromDictionary: ((NSString *)data[@"roomInfo"]).toJSONObject];
|
|
RoomInfoModel *newRoomInfo = [RoomInfoModel modelWithJSON:lastRoomInfoDic];
|
|
// //TODO: 从小游戏房间切换到普通房间的话 mgid不会被清除掉
|
|
// if (newRoomInfo.type != RoomType_MiniGame) {
|
|
// newRoomInfo.mgId = 0;
|
|
// }
|
|
// newRoomInfo.hasAnimationEffect = self.hasAnimationEffect;
|
|
// if (newRoomInfo.roomModeType == RoomModeType_Open_Blind && self.roomInfo.roomModeType != RoomModeType_Open_Blind) {
|
|
// ///普通房 切换为相亲房
|
|
// newRoomInfo.datingState = RoomDatingStateChangeType_Open;
|
|
// } else if(newRoomInfo.roomModeType != RoomModeType_Open_Blind && self.roomInfo.roomModeType == RoomModeType_Open_Blind) {
|
|
// ///关闭了相亲房
|
|
// newRoomInfo.datingState = RoomDatingStateChangeType_Close;
|
|
// } else {
|
|
// newRoomInfo.datingState = RoomDatingStateChangeType_Normal;
|
|
// }
|
|
//房间类型是否变更了(从个播->普通,个播->小游戏等)
|
|
// newRoomInfo.hadChangeRoomType = self.roomInfo.type != newRoomInfo.type;
|
|
// BOOL anchorToOther = newRoomInfo.type != RoomType_Anchor && self.roomInfo.type == RoomType_Anchor;//个播变其他房
|
|
self.roomInfo = newRoomInfo;
|
|
// [self.backContainerView onRoomUpdate];
|
|
// self.quickMessageContainerView.titleArray = self.roomInfo.speakTemplate;
|
|
// if (self.roomInfo.type == RoomType_Anchor && self.roomInfo.hadChangeRoomType) {///从其他房变为个播房
|
|
// [self handleInitAnchorRoom];
|
|
// [self showAnchorScrollTipView];
|
|
// } else if (anchorToOther) {
|
|
// [self.anchorScrollView removeFromSuperview];
|
|
// [self.backContainerView removeFromSuperview];
|
|
// [self.stageView removeFromSuperview];
|
|
// [self.messageContainerView removeFromSuperview];
|
|
// [self.quickMessageContainerView removeFromSuperview];
|
|
// [self.activityContainerView removeFromSuperview];
|
|
// [self.roomHeaderView removeFromSuperview];
|
|
// [self.functionView removeFromSuperview];
|
|
// [self.menuContainerView removeFromSuperview];
|
|
//
|
|
// [self.view addSubview:self.backContainerView];
|
|
// [self.view addSubview:self.stageView];
|
|
// [self.view addSubview:self.messageContainerView];
|
|
// [self.view addSubview:self.quickMessageContainerView];
|
|
// [self.view addSubview:self.activityContainerView];
|
|
// [self.view addSubview:self.roomHeaderView];
|
|
// [self.view addSubview:self.functionView];
|
|
// [self.view addSubview:self.menuContainerView];
|
|
// [self.view bringSubviewToFront:self.menuContainerView];
|
|
// [self.view bringSubviewToFront:self.animationView];
|
|
// [self initSubViewConstraints];
|
|
// [self changeStageViewOnRoomUpdate];
|
|
// [self.stageView onRoomUpdate];
|
|
// [self.menuContainerView onRoomUpdate];
|
|
// [self.functionView onRoomUpdate];
|
|
// [self.activityContainerView onRoomUpdate];
|
|
// [self.messageContainerView onRoomUpdate];
|
|
// [self.littleGameView onRoomUpdate];
|
|
// } else {
|
|
// if (self.roomInfo.type == RoomType_Anchor) {
|
|
// [self changeStageViewOnAnchorRoom];
|
|
// } else {
|
|
// [self changeStageViewOnRoomUpdate];
|
|
// }
|
|
[self.stageView onRoomUpdate];
|
|
// [self.menuContainerView onRoomUpdate];
|
|
// [self.functionView onRoomUpdate];
|
|
// [self.activityContainerView onRoomUpdate];
|
|
[self.messageContainerView onRoomUpdate];
|
|
// [self.littleGameView onRoomUpdate];
|
|
// }
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case NIMChatroomEventTypeEnter:
|
|
if (content.source.userId.integerValue != [AccountInfoStorage instance].getUid.integerValue && self.userInfo.platformRole != 1) {
|
|
// onLineNumber += 1;
|
|
}else {///如果是自己的话 如果有坐骑的话
|
|
// [self userEnterRoomSuccess];
|
|
// ///在活动页面 判断是否显示 相亲加入的按钮 所以需要等用户进房成功之后才能获取 房间角色
|
|
// [self.activityContainerView onRoomUpdate];
|
|
// [self.menuContainerView onRoomUpdate];
|
|
}
|
|
break;
|
|
case NIMChatroomEventTypeAddBlack:
|
|
case NIMChatroomEventTypeKicked:
|
|
case NIMChatroomEventTypeExit:
|
|
onLineNumber -= 1;
|
|
break;
|
|
case NIMChatroomEventTypeQueueChange: // 麦序上下麦
|
|
{
|
|
NSDictionary* data = (NSDictionary *)content.ext;
|
|
UserInfoModel* userInfo = [UserInfoModel modelWithJSON:[data objectForKey:NIMChatroomEventInfoQueueChangeItemValueKey]];
|
|
NSInteger changeType = [data[NIMChatroomEventInfoQueueChangeTypeKey] integerValue];
|
|
if (changeType == 1 && userInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
|
|
// [self cancelRoomArrangeMic];
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
self.roomInfo.onlineNum = onLineNumber;
|
|
// [self.roomHeaderView onRoomUpdate];
|
|
[self.stageView handleNIMNotificationMessage:message];
|
|
[self.messageContainerView handleNIMNotificationMessage:message];
|
|
} else if (message.messageType == NIMMessageTypeCustom) {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
|
|
AttachmentModel * attachment = obj.attachment;
|
|
[self.stageView handleNIMCustomMessage:message];
|
|
if (attachment.first == CustomMessageType_Update_RoomInfo && attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState) {
|
|
///兼容安卓和iOS 协议不同的问题
|
|
NSDictionary * dic= attachment.data[@"roomInfo"];
|
|
if (dic.allKeys.count <=0) {
|
|
dic = attachment.data;
|
|
}
|
|
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic];
|
|
// self.roomInfo.isCloseScreen = roomInfo.isCloseScreen;
|
|
// [self.menuContainerView onRoomUpdate];
|
|
}
|
|
[self.messageContainerView handleNIMCustomMessage:message];
|
|
}
|
|
} else if(message.messageType == NIMMessageTypeText) {
|
|
[self.messageContainerView handleNIMTextMessage:message];
|
|
} else if(message.messageType == NIMMessageTypeTip) {
|
|
[self.messageContainerView handleNIMTextMessage:message];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error {
|
|
if (![message.session.sessionId isEqualToString:[NSString stringWithFormat:@"%ld",self.roomInfo.roomId]]) {
|
|
return;
|
|
}
|
|
|
|
if (message.yidunAntiSpamRes) {
|
|
NSDictionary * spamRes = message.yidunAntiSpamRes.toJSONObject;
|
|
NSDictionary * spamResExt = ((NSString *)spamRes[@"ext"]).toJSONObject;
|
|
if ([spamResExt[@"antispam"][@"suggestion"] intValue] == 2) {
|
|
[self showErrorToast:@"消息中可能含有违规信息,请停止发送类似信息!"];
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (error) return;
|
|
|
|
if (message.messageType == NIMMessageTypeCustom) {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
|
|
AttachmentModel * attachment = obj.attachment;
|
|
if (attachment.first == CustomMessageType_Face && attachment.second == Custom_Message_Sub_Face_Send) {
|
|
NSLog(@"发送的表情:%@", attachment.data);
|
|
}
|
|
}
|
|
|
|
|
|
} else if(message.messageType == NIMMessageTypeText) {
|
|
[self.messageContainerView handleNIMTextMessage:message];
|
|
}
|
|
}
|
|
|
|
#pragma mark - NIMLoginManagerDelegate
|
|
- (void)onKickout:(NIMLoginKickoutResult *)result {
|
|
|
|
}
|
|
|
|
#pragma mark - NIMConversationManagerDelegate
|
|
/// 添加
|
|
- (void)didAddRecentSession:(NIMRecentSession *)recentSession
|
|
totalUnreadCount:(NSInteger)totalUnreadCount {
|
|
[self.messageContainerView addNIMRecentSession:recentSession];
|
|
}
|
|
|
|
/// 更新
|
|
- (void)didUpdateRecentSession:(NIMRecentSession *)recentSession
|
|
totalUnreadCount:(NSInteger)totalUnreadCount {
|
|
[self.messageContainerView addNIMRecentSession:recentSession];
|
|
}
|
|
|
|
/// 移除
|
|
- (void)didRemoveRecentSession:(NIMRecentSession *)recentSession
|
|
totalUnreadCount:(NSInteger)totalUnreadCount {
|
|
[self.messageContainerView removeNIMRecentSession:recentSession];
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Public Method
|
|
/// 进入房间
|
|
+ (BOOL)openRoom:(NSString *)roomUid viewController:(UIViewController *)viewController {
|
|
return [self openRoom:roomUid fromNick:nil fromType:0 fromUid:nil viewController:viewController];
|
|
}
|
|
|
|
/// 跟随进房
|
|
+ (BOOL)openRoom:(NSString *)roomUid fromNick:(NSString *)fromNick fromType:(UserEnterRoomFromType)fromType fromUid:(NSString *)fromUid viewController:(UIViewController *)viewController {
|
|
MewRoomViewController *roomVC = [[self alloc] init];
|
|
roomVC.roomUid = roomUid;
|
|
roomVC.fromNick = fromNick;
|
|
roomVC.fromType = fromType;
|
|
roomVC.fromUid = fromUid;
|
|
BaseNavigationController *baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
|
|
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
[viewController presentViewController:baseNav animated:YES completion:nil];
|
|
return YES;
|
|
}
|
|
|
|
#pragma mark - RoomHostDelegate
|
|
- (RoomInfoModel *)getRoomInfo {
|
|
return self.roomInfo;
|
|
}
|
|
|
|
- (UserInfoModel *)getUserInfo {
|
|
return self.userInfo;
|
|
}
|
|
|
|
/// 退出房间
|
|
- (void)exitRoom {
|
|
//其他模式下
|
|
|
|
// 默认模式下
|
|
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
|
|
[[RtcManager instance] exitRoom];
|
|
[self.presenter reportUserOutRoom:[NSString stringWithFormat:@"%ld",self.roomInfo.uid]];
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
- (UINavigationController *)getCurrentNav {
|
|
return self.navigationController;
|
|
}
|
|
|
|
|
|
|
|
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
|
// [self.menuContainerView onMicroQueueUpdate:queue];
|
|
// [self.functionView onRoomUpdate];
|
|
// [self.functionView onMicroQueueUpdate:queue];
|
|
|
|
BOOL isOnMic = false;
|
|
for (MicroQueueModel * info in queue.allValues) {
|
|
if (info.userInfo.uid > 0 && [AccountInfoStorage instance].getUid.integerValue == info.userInfo.uid) {
|
|
isOnMic = YES;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// if (isOnMic) {
|
|
// self.anchorScrollView.scrollEnabled = NO;
|
|
// } else {
|
|
// self.anchorScrollView.scrollEnabled = YES;
|
|
// }
|
|
}
|
|
#pragma mark - YMRoomProtocol
|
|
/// 进入房间成功
|
|
- (void)initEnterRoomSuccess:(RoomInfoModel *)roomInfo user:(UserInfoModel *)userInfo {
|
|
[YMHUDTool hideHUDInView:self.navigationController.view];
|
|
userInfo.fromUid = self.fromUid;
|
|
userInfo.fromType = self.fromType;
|
|
userInfo.fromNick = self.fromNick;
|
|
self.userInfo = userInfo;
|
|
self.roomInfo = roomInfo;
|
|
if (roomInfo.valid) {
|
|
//// if (roomInfo.room)
|
|
// //房间有密码
|
|
//
|
|
// //房间没有密码
|
|
[self.roomHeaderView onRoomEntered];
|
|
[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:@"" roomDesc:roomInfo.roomDesc backPic:@"" mgId:@""];
|
|
|
|
} else {
|
|
NSString *title = [NSString stringWithFormat:@"%@的房间",userInfo.nick];
|
|
RoomType type = RoomType_Game;
|
|
|
|
[self.presenter openRoom:title type:type roomPwd:@"" roomDesc:@"" backPic:@"" mgId:@""];
|
|
}
|
|
} else {
|
|
[self showSuccessToast:@"房主已下线"];
|
|
[self enterRoomFail:-1];
|
|
}
|
|
}
|
|
}
|
|
|
|
// 开房成功
|
|
- (void)openRoomSuccess:(RoomInfoModel *)roomInfo {
|
|
self.roomInfo = roomInfo;
|
|
[self.roomHeaderView onRoomEntered];
|
|
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
|
|
|
|
}
|
|
|
|
// IM进房成功
|
|
- (void)enterRoomSuccess:(NIMChatroom *)chatRoom {
|
|
[YMHUDTool hideHUDInView:self.navigationController.view];
|
|
[self.stageView onRoomEntered];
|
|
if (self.roomInfo != nil) {
|
|
[self.presenter reportUserInterRoom:[NSString stringWithFormat:@"%zd", self.roomInfo.uid]];
|
|
|
|
}
|
|
self.roomInfo.onlineNum = chatRoom.onlineUserCount;
|
|
|
|
}
|
|
|
|
// 进房失败
|
|
- (void)enterRoomFail:(NSInteger)code {
|
|
[YMHUDTool hideHUDInView:self.navigationController.view];
|
|
[self hideHUD];
|
|
if (code == 13003) {
|
|
[self showErrorToast:@"您已被管理员拉黑"];
|
|
}
|
|
|
|
if (code == -1) {
|
|
// 房主已下线
|
|
} else {
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
}
|
|
}
|
|
|
|
/// 送礼物成功
|
|
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo originDic:(NSDictionary *)originDic uidCount:(NSInteger)uidCount {
|
|
|
|
}
|
|
|
|
/// 送礼物失败
|
|
- (void)sendGiftFailWithCode:(NSInteger)code msg:(NSString *)msg {
|
|
|
|
}
|
|
|
|
#pragma mark - MewRoomHeaderViewDelegate (header事件回调)
|
|
- (void)didSelectMewRoomHeaderViewTarget:(NSInteger)target {
|
|
if (target == 0) {
|
|
// 收藏
|
|
|
|
} else if (target == 1) {
|
|
// 退出房间
|
|
[self exitRoom];
|
|
} else {
|
|
// 举报房间
|
|
}
|
|
}
|
|
|
|
|
|
#pragma mark - MewRoomRightViewDelegate(右边事件回调)
|
|
- (void)didSelectMewRoomRightViewWithTarget:(NSInteger)target {
|
|
if (target == 0) {
|
|
// 聊天
|
|
self.inputTextView = [YMRoomSendTextView showTextView:self.view.superview.superview delegate:self atUid:nil atNick:nil];
|
|
} else if (target == 1) {
|
|
// 表情
|
|
[self randomEmoji];
|
|
} else {
|
|
// 礼物
|
|
[self sendRoomGift];
|
|
}
|
|
}
|
|
|
|
|
|
#pragma mark - Private Method
|
|
/// 表情
|
|
- (void)randomEmoji {
|
|
int t = arc4random() % self.emojiArrays.count;
|
|
[self.playEmojiArrays addObject:self.emojiArrays[t]];
|
|
[self startPlayEmojiAnimation:self.playEmojiArrays[0]];
|
|
|
|
}
|
|
|
|
- (void)startPlayEmojiAnimation:(NSString *)emoji {
|
|
if (self.playEmojiArrays.count == 0) {
|
|
return;
|
|
};
|
|
|
|
if (self.isPlayEmojiAnimation) return;
|
|
|
|
self.isPlayEmojiAnimation = YES;
|
|
self.emojiImageView.hidden = NO;
|
|
if (self.playEmojiArrays.count > 0) {
|
|
self.emojiImageView.image = [UIImage imageNamed:self.playEmojiArrays[0]];
|
|
}
|
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
self.isPlayEmojiAnimation = NO;
|
|
self.emojiImageView.hidden = YES;
|
|
|
|
if (self.playEmojiArrays.count > 0) {
|
|
[self.playEmojiArrays removeObjectAtIndex:0];
|
|
}
|
|
|
|
if (self.playEmojiArrays.count > 0) {
|
|
[self startPlayEmojiAnimation:self.playEmojiArrays[0]];
|
|
}
|
|
});
|
|
}
|
|
|
|
/// 礼物
|
|
- (void)sendRoomGift {
|
|
MewSocialStageView *mewStageView = (MewSocialStageView *)self.stageView;
|
|
if (mewStageView.selectUid.length == 0 || [mewStageView.selectUid isEqualToString:@""]) {
|
|
[self showErrorToast:@"请至少选择一个人"];
|
|
return;
|
|
}
|
|
|
|
[self.presenter sendGift:mewStageView.selectUid roomUid:self.roomUid];
|
|
}
|
|
|
|
#pragma mark - Init
|
|
- (void)initView {
|
|
[self.view addSubview:self.roomBgImageView];
|
|
[self.view addSubview:self.roomHeaderView];
|
|
[self.view addSubview:self.stageView];
|
|
[self.view insertSubview:self.roomRightView aboveSubview:self.stageView];
|
|
[self.view addSubview:self.messageContainerView];
|
|
[self.view insertSubview:self.emojiImageView aboveSubview:self.roomRightView];
|
|
[self initLayout];
|
|
}
|
|
|
|
- (void)initLayout {
|
|
[self.roomBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.view);
|
|
}];
|
|
[self.roomHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self.view);
|
|
make.top.mas_equalTo(kStatusBarHeight+20);
|
|
make.height.mas_equalTo(28);
|
|
}];
|
|
|
|
[self.roomRightView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.roomHeaderView.mas_bottom).offset(35);
|
|
make.right.equalTo(self.view).offset(-32);
|
|
}];
|
|
|
|
[self.stageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.roomRightView);
|
|
make.left.right.equalTo(self.view);
|
|
make.height.mas_equalTo(self.stageView.heightForStageView);
|
|
}];
|
|
|
|
[self.messageContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.stageView.mas_bottom);
|
|
make.left.right.equalTo(self.view);
|
|
make.bottom.mas_equalTo(-kSafeAreaBottomHeight);
|
|
}];
|
|
|
|
[self.emojiImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self.stageView);
|
|
make.bottom.equalTo(self.stageView).offset(-60);
|
|
}];
|
|
}
|
|
|
|
|
|
#pragma mark - Get
|
|
- (UIImageView *)roomBgImageView {
|
|
if (!_roomBgImageView) {
|
|
_roomBgImageView = [[UIImageView alloc] init];
|
|
_roomBgImageView.image = [UIImage imageNamed:@"mew_home_bg"];
|
|
}
|
|
return _roomBgImageView;
|
|
}
|
|
|
|
- (MewRoomHeaderView *)roomHeaderView {
|
|
if (!_roomHeaderView) {
|
|
_roomHeaderView = [[MewRoomHeaderView alloc] initWithDelegate:self];
|
|
_roomHeaderView.delegate = self;
|
|
}
|
|
return _roomHeaderView;
|
|
}
|
|
|
|
- (MewRoomRightView *)roomRightView {
|
|
if (!_roomRightView) {
|
|
_roomRightView = [[MewRoomRightView alloc] init];
|
|
_roomRightView.delegate = self;
|
|
|
|
}
|
|
return _roomRightView;
|
|
}
|
|
|
|
- (StageView *)stageView {
|
|
if (!_stageView) {
|
|
_stageView = [[MewSocialStageView alloc] initWithDelegate:self];
|
|
}
|
|
return _stageView;
|
|
}
|
|
|
|
- (YMRoomMessageContainerView *)messageContainerView {
|
|
if (!_messageContainerView) {
|
|
_messageContainerView = [[YMRoomMessageContainerView alloc] initWithDelegate:self];
|
|
}
|
|
return _messageContainerView;
|
|
}
|
|
|
|
- (UIImageView *)emojiImageView {
|
|
if (!_emojiImageView) {
|
|
_emojiImageView = [[UIImageView alloc] init];
|
|
}
|
|
return _emojiImageView;
|
|
}
|
|
|
|
@end
|