// // XPIMRoomMicQueueImpl.m // xplan-ios // // Created by 冯硕 on 2021/10/21. // #import "XPIMRoomMicQueueImpl.h" ///Third #import ///Tool #import "XPIMManager.h" ///Model #import "MicroModel.h" #import "MicroQueueItemModel.h" #import "RoomInfoModel.h" #import "UserInfoModel.h" ///P #import "XPIMRoomMicQueueDelegate.h" #define MIC_COUNT(Type) [self roomTypecpORnormal:Type] @interface XPIMRoomMicQueueImpl () ///代理 @property (nonatomic,strong) id delegate; ///麦序的状态 <麦序 麦序上的内容> @property (nonatomic,strong) NSMutableDictionary *micQueue; @end @implementation XPIMRoomMicQueueImpl // 给宏定义赋值 -(NSInteger )roomTypecpORnormal:(RoomType )type{ if (type == RoomType_Game){ return 9; }else{ return 9; } } - (void)configDefaultMicQueue { RoomInfoModel * roomfInfo = [XPIMManager shareManager].chatRoomManager.getCurrentRoomInfo; for (int i = 0 ; i < MIC_COUNT(roomfInfo.type); i++) { MicroModel *state = [[MicroModel alloc]init]; state.posState = MicroPosStateType_Free; state.micState = MicroMicStateType_Open; MicroQueueItemModel *micSequence = [[MicroQueueItemModel alloc]init]; micSequence.microState = state; micSequence.userInfo = nil; [self.micQueue setObject:micSequence forKey:[NSString stringWithFormat:@"%d",i-1]]; } } #pragma mark - XPIMRoomMicQueueInterface ///进入房间成功之后根据扩展字段整理麦序 - (void)enterRoomRepairMicQueue:(NSDictionary *)micDictionary { [self configDefaultMicQueue]; for (NSString *position in micDictionary.allKeys) { MicroModel *state = [MicroModel modelWithJSON:micDictionary[position]]; MicroQueueItemModel *sequence = [self.micQueue objectForKey:position]; sequence.microState = state; } } ///获取房间队列 - (void)fetchRoomQueue:(NSString *)roomid { [[NIMSDK sharedSDK].chatroomManager fetchChatroomQueue:roomid completion:^(NSError * _Nullable error, NSArray *> * _Nullable info) { if (error == nil && info!= nil) { for (NSDictionary *item in info) { UserInfoModel *userInfo = [UserInfoModel modelWithJSON:item.allValues.firstObject]; NSString *position = item.allKeys.firstObject; MicroQueueItemModel *sequence = [self.micQueue objectForKey:position]; sequence.userInfo = userInfo; } if ([self.delegate respondsToSelector:@selector(onGetRoomMicroQueueSuccess:)]) { [self.delegate onGetRoomMicroQueueSuccess:self.micQueue]; } } else { NSLog(@"获取队列失败"); } }]; } ///麦序的队列 - (NSDictionary *)microQueue { return [self.microQueue copy]; } - (void)upMic:(NSString *)position { } - (void)downMic:(NSString *)position { } ///添加代理 - (void)addDelegate:(id)delegate { self.delegate = delegate; } ///移除代理 - (void)removeDelegate:(id)delegate { self.delegate = nil; } #pragma mark - Getters And Setters - (NSMutableDictionary *)micQueue { if (!_micQueue) { _micQueue= [NSMutableDictionary dictionary]; } return _micQueue; } @end