排麦模式
This commit is contained in:
@@ -8,9 +8,15 @@
|
||||
#import "MvpViewController.h"
|
||||
#import "XPArrangeMicInfoModel.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@protocol XPArrangeMicViewControllerDelegate <NSObject>
|
||||
|
||||
///用户是否在排麦中
|
||||
- (BOOL)getUserIsArrangeMicing;
|
||||
|
||||
@end
|
||||
@interface XPArrangeMicViewController : MvpViewController
|
||||
|
||||
///代理
|
||||
@property (nonatomic,weak) id<XPArrangeMicViewControllerDelegate> delegate;
|
||||
- (instancetype)initWithInfo:(XPArrangeMicInfoModel *)info;
|
||||
|
||||
@end
|
||||
|
@@ -14,10 +14,12 @@
|
||||
#import "TTPopup.h"
|
||||
#import "ThemeColor.h"
|
||||
#import "XPMacro.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "UIImage+Utils.h"
|
||||
///Model
|
||||
#import "ArrangeMicModel.h"
|
||||
#import "AttachmentModel.h"
|
||||
#import "UserInfoModel.h"
|
||||
///View
|
||||
#import "XPArrangeMicEmptyTableViewCell.h"
|
||||
#import "XPArrangeMicTableViewCell.h"
|
||||
@@ -48,6 +50,8 @@
|
||||
@property (nonatomic,strong) XPArrangeMicInfoModel *userInfo;
|
||||
///排麦的信息
|
||||
@property (nonatomic,strong) ArrangeMicModel *arrangeMicInfo;
|
||||
///需要抱上麦的
|
||||
@property (nonatomic, strong) NSMutableDictionary<NSString *, MicroQueueModel *> *micQueue;
|
||||
@end
|
||||
|
||||
@implementation XPArrangeMicViewController
|
||||
@@ -64,6 +68,7 @@
|
||||
if (self = [super init]) {
|
||||
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
||||
self.userInfo = info;
|
||||
self.micQueue = info.micQueue;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -194,6 +199,43 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 上麦操作
|
||||
//查看锁定的麦序(排麦模式中使用)
|
||||
- (NSString *)findLockPosition {
|
||||
if (self.micQueue != nil && self.micQueue.allKeys.count > 0) {
|
||||
NSArray *keys = [self.micQueue allKeys];
|
||||
NSArray *result = [keys sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
|
||||
return [obj1 compare:obj2]; //升序
|
||||
}];
|
||||
if (result.count > 0) {
|
||||
for (NSString *key in result) {
|
||||
MicroQueueModel *microQueue = [self.micQueue objectForKey:key];
|
||||
MicroStateModel * micstatus= microQueue.microState;
|
||||
if (![key isEqualToString:@"-1"] && !microQueue.userInfo && micstatus.posState == MicroPosStateType_Lock) {
|
||||
return key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
//判断是否在麦上
|
||||
- (BOOL)isOnMicro:(NSString *)uid{
|
||||
NSArray *chatRoomMicSequences = [self.micQueue allValues] ;
|
||||
if (chatRoomMicSequences != nil && chatRoomMicSequences.count > 0) {
|
||||
for (int i = 0; i < chatRoomMicSequences.count; i ++) {
|
||||
MicroQueueModel *microQueue = chatRoomMicSequences[i];
|
||||
if (microQueue.userInfo.uid == uid.integerValue) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - NIMChatManagerDelegate
|
||||
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
|
||||
for (NIMMessage * message in messages) {
|
||||
@@ -222,10 +264,83 @@
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(attachment.first == CustomMessageType_Queue) {
|
||||
if (attachment.second == Custom_Message_Sub_Queue_Invite && self.arrangeMicInfo.myPos.integerValue > 0) {
|
||||
NSDictionary *dic = attachment.data;
|
||||
NSString *uid = dic[@"uid"];
|
||||
if (uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
|
||||
[self.presenter cancelRoomArrangeMic:self.userInfo.roomUid];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(message.messageType == NIMMessageTypeNotification) {
|
||||
[self handleNIMNotificationMessage:message];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleNIMNotificationMessage:(NIMMessage *)message {
|
||||
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
|
||||
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
|
||||
switch (content.eventType) {
|
||||
case NIMChatroomEventTypeInfoUpdated: // 麦序状态更新
|
||||
{
|
||||
NSDictionary *data = [content.notifyExt toJSONObject];
|
||||
int type = [data[@"type"] intValue];
|
||||
NSArray* microStates;
|
||||
switch (type) {
|
||||
case 2:
|
||||
microStates = @[[MicroStateModel modelWithJSON:data[@"micInfo"]]];
|
||||
break;
|
||||
case 3:
|
||||
microStates = [MicroStateModel modelsWithArray:data[@"micInfo"]];
|
||||
break;
|
||||
}
|
||||
if (microStates && microStates.count > 0) {
|
||||
for (MicroStateModel *microState in microStates) {
|
||||
MicroQueueModel *micSequence = [self.micQueue objectForKey:[NSString stringWithFormat:@"%d", microState.position]];
|
||||
micSequence.microState = microState;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NIMChatroomEventTypeQueueChange: // 麦序上下麦
|
||||
{
|
||||
NSDictionary* data = (NSDictionary *)content.ext;
|
||||
NSString* position = [data objectForKey:NIMChatroomEventInfoQueueChangeItemKey];
|
||||
UserInfoModel* userInfo = [UserInfoModel modelWithJSON:[data objectForKey:NIMChatroomEventInfoQueueChangeItemValueKey]];
|
||||
NSInteger changeType = [data[NIMChatroomEventInfoQueueChangeTypeKey] integerValue];
|
||||
|
||||
// 先清除该用户旧的麦位
|
||||
for (MicroQueueModel *sequence in self.micQueue.allValues) {
|
||||
if (userInfo.uid == sequence.userInfo.uid) {
|
||||
sequence.userInfo = nil;
|
||||
}
|
||||
}
|
||||
|
||||
if (changeType == 1) { // 上麦
|
||||
MicroQueueModel *sequence = [self.micQueue objectForKey:position];
|
||||
sequence.userInfo = userInfo;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NIMChatroomEventTypeExit:
|
||||
case NIMChatroomEventTypeKicked:
|
||||
{
|
||||
for (NIMChatroomNotificationMember *member in content.targets) {
|
||||
for (MicroQueueModel *sequence in self.micQueue.allValues) {
|
||||
if (member.userId.integerValue == sequence.userInfo.uid) {
|
||||
sequence.userInfo = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - XPArrangeMicProtocol
|
||||
@@ -260,9 +375,33 @@
|
||||
- (void)cancelArrangeMicSuccess {
|
||||
[self headerRefresh];
|
||||
}
|
||||
#pragma mark - XPArrangeMicViewControllerDelegate
|
||||
- (BOOL)getUserIsArrangeMicing {
|
||||
return self.arrangeMicInfo.myPos.integerValue > 0;
|
||||
}
|
||||
#pragma mark - XPArrangeMicTableViewCellDelegate
|
||||
- (void)xPArrangeMicTableViewCell:(XPArrangeMicTableViewCell *)view inviteUser:(NSString *)uid {
|
||||
|
||||
NSString * position = [self findLockPosition];
|
||||
if ([self findLockPosition].length > 0 && uid.length > 0) {
|
||||
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
|
||||
[dic setValue:position forKey:@"micPosition"];
|
||||
[dic setValue:uid forKey:@"uid"];
|
||||
AttachmentModel *attachement = [[AttachmentModel alloc]init];
|
||||
attachement.first = CustomMessageType_Queue;
|
||||
attachement.second = Custom_Message_Sub_Queue_Invite;
|
||||
attachement.data = dic;
|
||||
|
||||
NIMMessage *message = [[NIMMessage alloc]init];
|
||||
NIMCustomObject *object = [[NIMCustomObject alloc] init];
|
||||
object.attachment = attachement;
|
||||
message.messageObject = object;
|
||||
//构造会话
|
||||
NIMSession *session = [NIMSession session:self.userInfo.roomId type:NIMSessionTypeChatroom];
|
||||
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
} else {
|
||||
[self showErrorToast:@"麦上无空位了"];
|
||||
}
|
||||
}
|
||||
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
@@ -305,7 +444,11 @@
|
||||
} cancelHandler:^{
|
||||
}];
|
||||
} else {
|
||||
[self.presenter applyRoomArrangeMic:self.userInfo.roomUid];
|
||||
if ([self isOnMicro:[AccountInfoStorage instance].getUid]) {
|
||||
[self showErrorToast:@"已经在麦上不需要报名啦"];
|
||||
} else {
|
||||
[self.presenter applyRoomArrangeMic:self.userInfo.roomUid];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@
|
||||
///占位的
|
||||
@property (nonatomic,strong) UIView * placeHolderView;
|
||||
///代理
|
||||
@property (nonatomic,weak) id<RoomHostDelegate> delegate;
|
||||
@property (nonatomic,weak) id<RoomHostDelegate, XPArrangeMicViewControllerDelegate> delegate;
|
||||
@end
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
info.micQueue = [self.delegate getMicroQueue];
|
||||
info.isManager = (member.type == NIMChatroomMemberTypeCreator || member.type == NIMChatroomMemberTypeManager);
|
||||
XPArrangeMicViewController * arrangeMicVC = [[XPArrangeMicViewController alloc] initWithInfo:info];
|
||||
arrangeMicVC.delegate = self.delegate;
|
||||
[self.delegate.getCurrentNav presentViewController:arrangeMicVC animated:YES completion:nil];
|
||||
}];
|
||||
}
|
||||
|
@@ -68,6 +68,8 @@
|
||||
return [self createKickUserAttribute:attachment info:kickModel];
|
||||
} else if(first == CustomMessageType_Candy_Tree ) {//糖果树
|
||||
return [self createCandyTreeHighLevelAttribute:attachment];
|
||||
} else if(first == CustomMessageType_Arrange_Mic) {
|
||||
return [self createArrangeMicAttribute:attachment];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
@@ -149,6 +151,30 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - 排麦
|
||||
- (NSAttributedString *)createArrangeMicAttribute:(AttachmentModel *)attachment {
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"管理员" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
if (attachment.second == Custom_Message_Sub_Arrange_Mic_Mode_Open) {
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"开启了" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"排麦模式" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
} else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Mode_Close) {
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"关闭了" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"排麦模式" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
} else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Free_Mic_Open) {
|
||||
NSDictionary * dic = attachment.data;
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"设置" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%d麦", ((NSNumber *)dic[@"micPos"]).intValue + 1 ] color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"为自由麦" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
} else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Free_Mic_Close) {
|
||||
NSDictionary * dic = attachment.data;
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"关闭了" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%d麦", ((NSNumber *)dic[@"micPos"]).intValue + 1 ] color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:@"自由麦" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
}
|
||||
return attribute;
|
||||
}
|
||||
|
||||
#pragma mark - 糖果树公屏消息
|
||||
- (NSAttributedString *)createCandyTreeHighLevelAttribute:(AttachmentModel *)attachment {
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
|
@@ -187,6 +187,13 @@
|
||||
@(Custom_Message_Sub_Candy_Tree_AllRoom_Notify),
|
||||
@(Custom_Message_Sub_Candy_Tree_InRoom_NeedAllMicSend),
|
||||
nil],
|
||||
@(CustomMessageType_Arrange_Mic):
|
||||
[NSSet setWithObjects:
|
||||
@(Custom_Message_Sub_Arrange_Mic_Mode_Open),
|
||||
@(Custom_Message_Sub_Arrange_Mic_Mode_Close),
|
||||
@(Custom_Message_Sub_Arrange_Mic_Free_Mic_Open),
|
||||
@(Custom_Message_Sub_Arrange_Mic_Free_Mic_Close),
|
||||
nil],
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,8 @@
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "RtcManager.h"
|
||||
#import "XPRoomMiniManager.h"
|
||||
#import "TTPopup.h"
|
||||
#import "Api+ArrangeMic.h"
|
||||
///Model
|
||||
#import "RoomInfoModel.h"
|
||||
#import "UserInfoModel.h"
|
||||
@@ -29,6 +31,7 @@
|
||||
#import "SocialStageView.h"
|
||||
#import "XPRoomAnimationView.h"
|
||||
#import "XPRoomFunctionContainerView.h"
|
||||
#import "XPArrangeMicViewController.h"
|
||||
///P
|
||||
#import "XPRoomPresenter.h"
|
||||
#import "XPRoomProtocol.h"
|
||||
@@ -36,7 +39,7 @@
|
||||
#import "RoomHostDelegate.h"
|
||||
#import "RoomGuestDelegate.h"
|
||||
|
||||
@interface XPRoomViewController ()<XPRoomProtocol, RoomHostDelegate, NIMChatroomManagerDelegate, NIMChatManagerDelegate, NIMLoginManagerDelegate>
|
||||
@interface XPRoomViewController ()<XPRoomProtocol, RoomHostDelegate, NIMChatroomManagerDelegate, NIMChatManagerDelegate, NIMLoginManagerDelegate,XPArrangeMicViewControllerDelegate>
|
||||
///背景
|
||||
@property (nonatomic,strong) XPRoomBackContainerView *backContainerView;
|
||||
///房间信息
|
||||
@@ -250,6 +253,14 @@
|
||||
} else if (result.reason == 5) {
|
||||
[self showErrorToast:@"您已被管理员拉黑"];
|
||||
}
|
||||
///退出排麦
|
||||
if (self.roomInfo.roomModeType == RoomModeType_Open_Micro_Mode && [self getUserIsArrangeMicing]) {
|
||||
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.roomInfo.uid];
|
||||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||||
[Api cancelArrangeMic:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
} roomUid:roomUid operUid:uid groupType:@"0"];
|
||||
}
|
||||
[[RtcManager instance] exitRoom];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
@@ -283,7 +294,9 @@
|
||||
RoomInfoModel * roomInfo =[RoomInfoModel modelWithJSON:data[@"roomInfo"]];
|
||||
self.roomInfo.leaveMode = roomInfo.leaveMode;
|
||||
self.roomInfo.showGiftValue = roomInfo.showGiftValue;
|
||||
self.roomInfo = roomInfo;
|
||||
[self.stageView onRoomUpdate];
|
||||
[self.menuContainerView onRoomUpdate];
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -347,9 +360,24 @@
|
||||
}
|
||||
|
||||
- (void)exitRoom {
|
||||
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
|
||||
[[RtcManager instance] exitRoom];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
if (self.roomInfo.roomModeType == RoomModeType_Open_Micro_Mode && [self getUserIsArrangeMicing]) {
|
||||
[TTPopup alertWithMessage:@"退出房间后将退出目前排麦,再次进入需要重新排麦,确认退出房间吗?" confirmHandler:^{
|
||||
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.roomInfo.uid];
|
||||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||||
[Api cancelArrangeMic:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
} roomUid:roomUid operUid:uid groupType:@"0"];
|
||||
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
|
||||
[[RtcManager instance] exitRoom];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
} cancelHandler:^{
|
||||
|
||||
}];
|
||||
} else {
|
||||
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
|
||||
[[RtcManager instance] exitRoom];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)miniRoom {
|
||||
|
Reference in New Issue
Block a user