Files
peko-ios/YuMi/Modules/YMRoom/View/XPRoomViewController.m

4347 lines
186 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// YMRoomViewController.m
// YUMI
//
// Created by YUMI on 2021/10/11.
//
#import "XPRoomViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
///Tool
#import "YUMIMacroUitls.h"
#import "YUMIConstant.h"
#import "AccountInfoStorage.h"
#import "RtcManager.h"
#import "XPRoomMiniManager.h"
#import "TTPopup.h"
#import "TurboModeStateManager.h"
2023-07-14 18:50:55 +08:00
#import "Api+ArrangeMic.h"
#import "Api+Room.h"
#import "DESEncrypt.h"
#import "NSArray+Safe.h"
#import "NSMutableDictionary+Saft.h"
2024-10-12 19:30:41 +08:00
#import "XPSkillCardPlayerManager.h"
2023-07-14 18:50:55 +08:00
#import "XCCurrentVCStackManager.h"
2023-09-22 15:26:19 +08:00
#import "CountDownHelper.h"
2023-07-14 18:50:55 +08:00
///Model
#import "RoomInfoModel.h"
#import "UserInfoModel.h"
#import "AttachmentModel.h"
#import "ArrangeMicModel.h"
#import "XPReleaseRadioModel.h"
#import "GuildSuperAdminInfoModel.h"
#import "XPKickUserModel.h"
#import "ContentLevelUpgradeModel.h"
#import "XPReceiveRedPacketModel.h"
#import "XPRedPacketModel.h"
2023-09-22 15:26:19 +08:00
#import "XPFreeGiftModel.h"
2023-10-26 15:20:20 +08:00
#import "XPUserCardInfoModel.h"
2023-07-14 18:50:55 +08:00
///View
#import "BaseNavigationController.h"
#import "XPRoomBackContainerView.h"
#import "XPRoomMenuContainerView.h"
#import "XPRoomQuickMessageContainView.h"
2024-05-11 10:21:48 +08:00
#import "MsRoomMessageMainView.h"
2023-07-14 18:50:55 +08:00
#import "RoomHeaderView.h"
#import "SocialStageView.h"
#import "TenMicStageView.h"
#import "FifteenMicStageView.h"
2024-12-16 19:41:23 +08:00
#import "NineteenMicStageView.h"
#import "TwentyMicStageView.h"
2023-07-14 18:50:55 +08:00
#import "DatingStageView.h"
#import "AnchorStageView.h"
#import "AnchorPkStageView.h"
2025-01-15 19:02:58 +08:00
//#import "XPRoomAnimationView.h"
#import "RoomAnimationView.h"
2023-07-14 18:50:55 +08:00
#import "XPRoomFunctionContainerView.h"
#import "XPArrangeMicViewController.h"
#import "XPRoomSettingInputView.h"
#import "AnchorRoomScrollView.h"
#import "AnchorRoomSrollTipView.h"
#import "XPReceiveRedPacketView.h"
2023-09-12 17:48:18 +08:00
#import "XPWebViewController.h"
2023-09-21 17:44:59 +08:00
#import "SessionViewController.h"
2023-09-22 15:26:19 +08:00
#import "XPFreeGiftsObtainView.h"
2024-05-21 14:17:30 +08:00
2023-07-14 18:50:55 +08:00
///P
#import "XPRoomPresenter.h"
#import "XPRoomProtocol.h"
2024-05-21 14:17:30 +08:00
#import "XPWeakTimer.h"
2023-07-14 18:50:55 +08:00
#import "RoomHostDelegate.h"
#import "RoomGuestDelegate.h"
2024-05-21 14:17:30 +08:00
#import "Api+RoomSetting.h"
2023-07-14 18:50:55 +08:00
#import "XNDJTDDLoadingTool.h"
2023-08-25 16:32:51 +08:00
#import "ClientConfig.h"
2023-08-31 16:51:40 +08:00
#import "LittleGameStageView.h"
#import "LittleGameScrollStageView.h"
#import "XPRoomLittleGameContainerView.h"
#import "StageViewManager.h"
2023-10-30 14:38:33 +08:00
#import "PIRoomEnterRedPacketView.h"
2024-05-11 10:21:48 +08:00
#import "XPIAPRechargeViewController.h"
#import "XPCandyTreeInsufficientBalanceView.h"
#import "GiftComboManager.h"
2024-09-14 18:29:36 +08:00
#import "LuckyGiftWinningFlagView.h"
2024-10-10 20:16:23 +08:00
#import "RoomBoomResultView.h"
#import "RoomBoomManager.h"
#import "RoomBoomExplosionView.h"
#import "RoomBoomResultView.h"
2024-10-12 19:30:41 +08:00
#import "XPSendGiftView.h"
2024-12-20 19:05:43 +08:00
#import "RoomSideMenu.h"
#import "RoomResourceManager.h"
2025-02-28 19:04:09 +08:00
#import "LuckyPackageLogicManager.h"
2025-01-22 21:22:58 +08:00
#import "MicCpInfoModel.h"
#import "XPMessageRemoteExtModel.h"
#import "MicMidpointRectManager.h"
// 🔧 Turbo Mode Tips
#import "XPTurboModeTipsManager.h"
#import "BuglyManager.h"
2025-01-22 21:22:58 +08:00
//#import "XPMineHallAnchorIncomeStatisViewController.h"
2023-07-14 18:50:55 +08:00
UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
UIKIT_EXTERN NSString * kNewUserRechargeKey;
UIKIT_EXTERN NSString * const kMessageFromPublicRoomWithAttachmentNotification;
2023-09-22 15:26:19 +08:00
UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
2023-07-14 18:50:55 +08:00
NSString * const kHadShowAnchorRoomTipKey = @"kHadShowAnchorRoomTipKey";//
NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//退
2024-10-10 20:16:23 +08:00
@interface XPRoomViewController ()<
XPRoomProtocol,
RoomHostDelegate,
NIMChatroomManagerDelegate,
NIMChatManagerDelegate,
NIMConversationManagerDelegate,
NIMLoginManagerDelegate,
XPRoomSettingInputViewDelegate,
AnchorRoomScrollViewDelegate,
NIMBroadcastManagerDelegate,
XPRoomLittleGameContainerViewDelegate,
CountDownHelperDelegate,
PIRoomEnterRedPacketViewDelegate,
XPReceiveRedPacketViewDelegate,
XPCandyTreeInsufficientBalanceViewDelegate>
2025-01-22 21:22:58 +08:00
2023-07-14 18:50:55 +08:00
///
@property (nonatomic,strong) XPRoomBackContainerView *backContainerView;
///view
@property (nonatomic, strong) AnchorRoomScrollView *anchorScrollView;
///
@property (nonatomic,strong) RoomHeaderView *roomHeaderView;
///
@property (nonatomic,strong) StageView *stageView;
@property (nonatomic,strong) StageViewManager *stageViewManager;
@property (nonatomic,strong) TenMicStageView *tenMicStageView;
@property (nonatomic,strong) FifteenMicStageView *fifteenMicStageView;
2024-12-16 19:41:23 +08:00
@property (nonatomic,strong) TwentyMicStageView *twentyMicStageView;
@property(nonatomic, strong) NineteenMicStageView *nineteenMicStageView;
2023-07-14 18:50:55 +08:00
///
2024-05-11 10:21:48 +08:00
@property (nonatomic,strong) MsRoomMessageMainView *messageContainerView;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic, strong) XPRoomQuickMessageContainView *quickMessageContainerView;
///
@property (nonatomic,strong) XPRoomMenuContainerView *menuContainerView;
///
2024-12-20 19:05:43 +08:00
@property(nonatomic, strong) RoomSideMenu *sideMenu;
2023-07-14 18:50:55 +08:00
///view
2025-01-15 19:02:58 +08:00
@property (nonatomic,strong) RoomAnimationView *animationView;
2023-07-14 18:50:55 +08:00
///view
@property (nonatomic,strong) XPRoomFunctionContainerView *functionView;
2023-08-31 16:51:40 +08:00
///
@property (nonatomic,strong) XPRoomLittleGameContainerView *littleGameView;
2023-10-20 19:30:20 +08:00
2023-07-14 18:50:55 +08:00
///Uid
@property (nonatomic,copy) NSString * roomUid;
///id
@property (nonatomic,copy) NSString *mgId;
///id
@property (nonatomic, copy) NSString *giftId;
///
@property (nonatomic,strong) UserInfoModel *userInfo;
///
@property (nonatomic,strong) RoomInfoModel *roomInfo;
///
@property (nonatomic,assign) BOOL hasAnimationEffect;
///
@property (nonatomic,copy) NSString *fromNick;
@property (nonatomic,assign) UserEnterRoomFromType fromType;
@property (nonatomic,copy) NSString *fromUid;
///
@property (nonatomic,strong) NSArray<GuildSuperAdminInfoModel *> *superMangerList;
///
@property (nonatomic,assign) BOOL isRequestSuperAdmin;
///
@property (nonatomic,assign) BOOL isMiniEnter;
///
@property (nonatomic, strong) AnchorRoomSrollTipView *anchorScrollTipView;
///
@property (nonatomic,strong) NSMutableArray<NSString *> *anchorRoomList;
///
@property (nonatomic,assign) NSInteger anchorIndex;
2023-09-22 15:26:19 +08:00
///
@property (nonatomic,strong) XPFreeGiftModel *freeModel;
///
@property (nonatomic,strong) XPFreeGiftsObtainView *freeView;
2023-10-27 17:21:23 +08:00
///id
@property(nonatomic,copy) NSString *redEnvelopeId;
2023-10-30 14:38:33 +08:00
///
@property(nonatomic,strong) PIRoomEnterRedPacketView *redPacketView;
2023-10-31 11:09:04 +08:00
///
@property(nonatomic,assign) BOOL isShowRedPacket;
2024-05-11 10:21:48 +08:00
@property(nonatomic,copy) NSString *releaseCoins;
// 🔧
@property (atomic, assign) BOOL isExitingRoom; // 退
@property (atomic, assign) BOOL isViewActive; // VC /
2024-05-11 10:21:48 +08:00
@property(nonatomic,copy) NSString *myCoins;
@property(nonatomic,strong) UIButton *exitGameButton;
/// 10
@property(nonatomic,strong) NSTimer *upMicAskTimer;
/// 🔧 block
@property(nonatomic,strong) id<NSObject> exchangeRoomAnimationViewObserver;
/// CPcpSVGA
@property (nonatomic, strong) NSArray<MicCpInfoModel *> *currentCpList;
@property (nonatomic, assign) BOOL currentUserMicStatusChanged; //
@property (nonatomic, assign) BOOL currentUserWasOnMic; //
@property (nonatomic, assign) NSInteger currentUserMicPosition; // -1
@property (nonatomic, assign) BOOL hasCompletedRoomInitialization; //
2023-07-14 18:50:55 +08:00
@end
@implementation XPRoomViewController
+ (BOOL)openRoom:(NSString *)roomUid viewController:(UIViewController *)viewController {
2023-10-30 14:38:33 +08:00
return [self openRoom:roomUid fromNick:nil fromType:0 fromUid:nil viewController:viewController];
2023-07-14 18:50:55 +08:00
}
2023-10-27 17:21:23 +08:00
+ (BOOL)openRoom:(NSString *)roomUid viewController:(UIViewController *)viewController redEnvelopeId:(NSString *)redEnvelopeId{
XPRoomViewController * roomVC = [[self alloc] init];
roomVC.roomUid = roomUid;
roomVC.fromUid = nil;
roomVC.fromType = 0;
roomVC.fromNick = nil;
roomVC.redEnvelopeId = redEnvelopeId;
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:baseNav animated:YES completion:nil];
return YES;
}
2024-10-10 20:16:23 +08:00
+ (BOOL)openRoom:(NSString*)roomUid fromNick:(NSString * __nullable)fromNick fromType:(UserEnterRoomFromType)fromType fromUid:(NSString * __nullable)fromUid viewController:(UIViewController*)viewController {
2023-10-30 14:38:33 +08:00
XPRoomViewController * roomVC = [[self alloc] init];
roomVC.roomUid = roomUid;
roomVC.fromUid = fromUid;
roomVC.fromType = fromType;
roomVC.fromNick = fromNick;
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:baseNav animated:YES completion:nil];
return YES;
2023-07-14 18:50:55 +08:00
}
/**
* @params roomUid uid
* @params viewController
*/
+ (BOOL)openMiniRoom:(NSString*)roomUid viewController:(UIViewController*)viewController {
2023-10-30 14:38:33 +08:00
XPRoomViewController * roomVC = [[self alloc] init];
roomVC.roomUid = roomUid;
roomVC.isMiniEnter = YES;
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:baseNav animated:YES completion:nil];
return roomVC;
2023-07-14 18:50:55 +08:00
}
2023-10-27 17:21:23 +08:00
/**
* @params roomUid uid
* @params viewController
* @params redEnvelopeId id
*/
+ (BOOL)openMiniRoom:(NSString*)roomUid viewController:(UIViewController*)viewController redEnvelopeId:(NSString *)redEnvelopeId{
XPRoomViewController * roomVC = [[self alloc] init];
roomVC.roomUid = roomUid;
roomVC.isMiniEnter = YES;
roomVC.redEnvelopeId = redEnvelopeId;
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:baseNav animated:YES completion:nil];
return roomVC;
}
2023-07-14 18:50:55 +08:00
/** XPRoomViewController init
* @params roomUid uid
* @params viewController
* @params mgId id
*/
+ (BOOL)openRoom:(NSString*)roomUid mgId:(NSString *)mgId viewController:(UIViewController*)viewController {
2023-10-30 14:38:33 +08:00
XPRoomViewController * roomVC = [[self alloc] init];
roomVC.roomUid = roomUid;
roomVC.mgId = mgId;
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:baseNav animated:YES completion:nil];
return YES;
2023-07-14 18:50:55 +08:00
}
/// h5
/// @param roomUid Uid
/// @param giftId id
/// @param viewController
+ (BOOL)openRoom:(NSString *)roomUid giftId:(NSString *)giftId viewController:(UIViewController *)viewController {
2023-10-30 14:38:33 +08:00
XPRoomViewController * roomVC = [[self alloc] init];
roomVC.roomUid = roomUid;
roomVC.giftId = giftId;
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[viewController presentViewController:baseNav animated:YES completion:nil];
return YES;
2023-07-14 18:50:55 +08:00
}
- (void)dealloc {
NSLog(@"🔄 XPRoomViewController: 开始销毁");
// 🔧 TRTC
[[RtcManager instance] exitRoom];
// 🔧 退
self.isExitingRoom = YES;
self.isViewActive = NO;
[[RoomBoomManager sharedManager] leaveRoom];
[XPSkillCardPlayerManager shareInstance].photoIdList = nil;
[XPSkillCardPlayerManager shareInstance].isInRoomVC = NO;
[XPSkillCardPlayerManager shareInstance].isInRoomFirstRecharge = NO;
[XPSkillCardPlayerManager shareInstance].isInRoom = NO;
[XPSkillCardPlayerManager shareInstance].roomUid = @"";
if([[XPRoomMiniManager shareManager] getRoomInfo]==nil){
[XPSkillCardPlayerManager shareInstance].isMineInMic = NO;
}
[[CountDownHelper shareHelper] stopCountDown];
[CountDownHelper shareHelper].delegate = nil;
[[NIMSDK sharedSDK].chatroomManager removeDelegate:self];
[[NIMSDK sharedSDK].chatManager removeDelegate:self];
[[NIMSDK sharedSDK].loginManager removeDelegate:self];
[[NIMSDK sharedSDK].conversationManager removeDelegate:self];
[[NIMSDK sharedSDK].broadcastManager removeDelegate:self];
[[RoomBoomManager sharedManager] removeEventListenerForTarget:self];
// 🔧 block
if (self.exchangeRoomAnimationViewObserver) {
[[NSNotificationCenter defaultCenter] removeObserver:self.exchangeRoomAnimationViewObserver];
self.exchangeRoomAnimationViewObserver = nil;
}
[[NSNotificationCenter defaultCenter] removeObserver:self];
// 🔧 RoomAnimationView
if (_animationView) {
NSLog(@"🔄 XPRoomViewController: 清理 RoomAnimationView");
[_animationView removeItSelf];
[_animationView removeFromSuperview];
_animationView = nil;
}
//
if (self.upMicAskTimer) {
[self.upMicAskTimer invalidate];
self.upMicAskTimer = nil;
}
NSLog(@"🔄 XPRoomViewController: 销毁完成");
2023-07-14 18:50:55 +08:00
}
- (XPRoomPresenter *)createPresenter {
2023-10-30 14:38:33 +08:00
return [[XPRoomPresenter alloc] init];
2023-07-14 18:50:55 +08:00
}
- (BOOL)isHiddenNavBar {
2023-10-30 14:38:33 +08:00
return YES;
2023-07-14 18:50:55 +08:00
}
- (void)viewDidLoad {
2023-10-30 14:38:33 +08:00
[super viewDidLoad];
2023-10-30 14:38:33 +08:00
[self exitOldRoom];
2024-10-10 20:16:23 +08:00
[self preLoadGifts];
2023-10-30 14:38:33 +08:00
[self initSubViews];
[self initSubViewConstraints];
[self setupNimSDK];
[self loadRoomDataAndUsers];
[self setupNotifications];
[self handleActivityContainerViewEvents];
2023-10-30 14:38:33 +08:00
///
[self.presenter getRoomSuperAdmin:self.roomUid];
2024-10-12 19:30:41 +08:00
[XPSkillCardPlayerManager shareInstance].isInRoom = YES;
2023-09-22 15:26:19 +08:00
[CountDownHelper shareHelper].delegate = self;
2024-10-10 20:16:23 +08:00
2024-10-12 19:30:41 +08:00
[self setupForBoom];
2024-10-10 20:16:23 +08:00
2024-12-03 17:40:29 +08:00
[self handleGiftComboCallBack];
[self setupStageViewManager];
// 🔧 Turbo Mode Tips
[[XPTurboModeTipsManager sharedManager] startTipsMonitoringInRoom];
}
2025-01-22 21:22:58 +08:00
//- (void)test {
// XPMineHallAnchorIncomeStatisViewController *vc = [[XPMineHallAnchorIncomeStatisViewController alloc] init];
// [self.navigationController pushViewController:vc animated:YES];
//}
2024-12-03 17:40:29 +08:00
- (void)handleGiftComboCallBack {
@kWeakify(self);
[[GiftComboManager sharedManager] setHandleRoomUIChanged:^(BOOL comboViewDisplay) {
@kStrongify(self);
2024-12-06 14:38:45 +08:00
dispatch_async(dispatch_get_main_queue(), ^{
2024-12-20 19:05:43 +08:00
self.sideMenu.hidden = comboViewDisplay;
2024-12-06 14:38:45 +08:00
self.menuContainerView.hidden = comboViewDisplay;
// UI
if (comboViewDisplay && ![[GiftComboManager sharedManager] isActive]) {
NSLog(@"⚠️ 检测到UI隐藏请求但连击未进行执行强制重置");
[self forceBoomStateReset];
}
2024-12-06 14:38:45 +08:00
});
2024-12-03 17:40:29 +08:00
}];
}
2024-10-12 19:30:41 +08:00
- (void)setupForBoom {
2024-10-10 20:16:23 +08:00
@kWeakify(self);
[[RoomBoomManager sharedManager] registerBoomExplosion:^(id _Nonnull sth) {
@kStrongify(self);
2025-03-25 15:22:01 +08:00
[self.presenter getBoomDetail:self.roomUid];
if (![sth isKindOfClass:[NSArray class]]) {
return;
}
2024-10-10 20:16:23 +08:00
dispatch_async(dispatch_get_main_queue(), ^{
2025-03-25 15:22:01 +08:00
[RoomBoomExplosionView display:self.view with:sth complete:^{ }];
2024-10-10 20:16:23 +08:00
});
} target:self];
[[RoomBoomManager sharedManager] registerBoomGiftDisplay:^(id _Nonnull sth) {
@kStrongify(self);
dispatch_async(dispatch_get_main_queue(), ^{
2024-10-11 12:31:37 +08:00
[RoomBoomResultView display:self.view attachment:sth];
2024-10-10 20:16:23 +08:00
});
} target:self];
[[RoomBoomManager sharedManager] registerBoomEnterRoomExplosion:^(id _Nonnull sth) {
@kStrongify(self);
2025-03-25 15:22:01 +08:00
if (![sth isKindOfClass:[NSArray class]]) {
return;
}
2024-10-10 20:16:23 +08:00
dispatch_async(dispatch_get_main_queue(), ^{
[RoomBoomExplosionView display:self.view with:sth complete:^{
}];
});
} target:self];
}
- (void)requestBoomData {
[self.presenter getBoomRocketAnimationInfo:self.roomUid];
[self.presenter getBoomDetail:self.roomUid];
}
- (void)loadRoomDataAndUsers {
[XNDJTDDLoadingTool showAnchorLoading:self.navigationController.view];
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
}
- (void)setupNotifications {
2023-10-30 14:38:33 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myGiftEffectUpdate:) name:kRoomGiftEffectUpdateNotificationKey object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openRedPacketNotification:) name:@"kOpenRedPacketNotification" object:nil];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePublicRoomMessageForward:)
name:@"MessageFromPublicRoomWithAttachmentNotification"
object:nil];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
@kWeakify(self);
// 🔧 block
self.exchangeRoomAnimationViewObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"kExchangeRoomAnimationViewAndGameViewIndex"
object:nil
queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification * _Nonnull notification) {
@kStrongify(self);
if (self.view.subviews.count > 0) {
UIView *topView = self.view.subviews.lastObject;
UIView *secondView = [self.view.subviews xpSafeObjectAtIndex:self.view.subviews.count-2];
if (secondView && secondView.tag == 913) {
NSInteger index1 = [self.view.subviews indexOfObject:topView];
NSInteger index2 = [self.view.subviews indexOfObject:secondView];
[self.view exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2];
}
}
}];
}
- (void)setupNimSDK {
//
[[NIMSDK sharedSDK].chatroomManager addDelegate:self];
[[NIMSDK sharedSDK].chatManager addDelegate:self];
[[NIMSDK sharedSDK].loginManager addDelegate:self];
[[NIMSDK sharedSDK].conversationManager addDelegate:self];
[[NIMSDK sharedSDK].broadcastManager addDelegate:self];
}
/// -2: roomUid
- (void)preLoadGifts {
[self.presenter getNormalGiftList:self.roomUid];
///
[self.presenter getFreeGiftData];
2025-03-06 15:26:44 +08:00
if(![NSString isEmpty:self.redEnvelopeId]){
[self.presenter getRedPacketInft:self.redEnvelopeId];
}
2024-05-11 10:21:48 +08:00
}
#pragma mark - MSSessionReleaseHeadlinesViewDelegate
2024-05-11 10:21:48 +08:00
-(void)releaseHeadlinesWithText:(NSString *)text{
XPCandyTreeInsufficientBalanceView *balanceView = [[XPCandyTreeInsufficientBalanceView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
balanceView.delegate = self;
[self.view addSubview:balanceView];
}
#pragma mark - XPCandyTreeInsufficientBalanceViewDelegate
2024-05-11 10:21:48 +08:00
- (void)payBalanceAction{
XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init];
webVC.type = @"4";
[self.navigationController pushViewController:webVC animated:YES];
2023-10-26 15:20:20 +08:00
}
///
-(void)openRedPacketNotification:(NSNotification *)not{
NSDictionary *redPacketDic = not.userInfo;
NSInteger type = [redPacketDic[@"type"] integerValue];
NSInteger userId = [redPacketDic[@"uid"] integerValue];
2023-10-30 14:38:33 +08:00
// NSString *roomUid = redPacketDic[@"roomUId"];
2023-10-26 15:20:20 +08:00
if(type == 2){
[self.messageContainerView showUserCard:userId];
}else if (type == 3){
// [self.roomHeaderView showSharePanel];
2023-10-26 15:20:20 +08:00
}else if (type == 4){
NSString *scrolling = redPacketDic[@"scrolling"];
[self.menuContainerView showInputView:scrolling];
}
2023-07-14 18:50:55 +08:00
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
2023-10-30 14:38:33 +08:00
[self.menuContainerView menuResignFirstResponder];
2023-07-14 18:50:55 +08:00
}
- (void)viewWillAppear:(BOOL)animated {
2023-10-30 14:38:33 +08:00
[super viewWillAppear:animated];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
2024-10-15 20:56:25 +08:00
[self.menuContainerView recheckMicState];
2023-07-14 18:50:55 +08:00
}
2023-09-22 15:26:19 +08:00
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.freeView.hidden = YES;
// 🔧 VC
self.isViewActive = NO;
// 🔧 VC dismiss TRTC
if (self.isMovingFromParentViewController || self.isBeingDismissed) {
[[RtcManager instance] exitRoom];
self.isExitingRoom = YES;
}
//
if ([[GiftComboManager sharedManager] isActive]) {
NSLog(@"📱 房间即将退出,检查连击状态");
[self forceBoomStateReset];
}
2023-09-22 15:26:19 +08:00
}
2023-09-27 20:17:09 +08:00
2023-07-21 18:53:10 +08:00
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
2023-09-27 20:17:09 +08:00
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
2024-10-12 19:30:41 +08:00
[XPSkillCardPlayerManager shareInstance].isInRoomVC = NO;
// 🔧
self.isViewActive = NO;
// 🔧 退 BuglyManager 退
[[NSNotificationCenter defaultCenter] postNotificationName:@"RoomDidExit"
object:nil
userInfo:@{@"roomId": self.roomUid ?: @"unknown"}];
NSLog(@"🎮 房间退出通知已发送 - RoomID: %@", self.roomUid);
2023-07-21 18:53:10 +08:00
}
2023-07-14 18:50:55 +08:00
- (void)viewDidAppear:(BOOL)animated {
2023-10-30 14:38:33 +08:00
[super viewDidAppear:animated];
2023-09-22 15:26:19 +08:00
self.freeView.hidden = NO;
2023-09-27 20:17:09 +08:00
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
2024-10-12 19:30:41 +08:00
[XPSkillCardPlayerManager shareInstance].isInRoomVC = YES;
// 🔧 VC
self.isViewActive = YES;
// 🔧 BuglyManager
[[NSNotificationCenter defaultCenter] postNotificationName:@"RoomDidEnter"
object:nil
userInfo:@{@"roomId": self.roomUid ?: @"unknown"}];
NSLog(@"🎮 房间进入通知已发送 - RoomID: %@", self.roomUid);
2023-07-14 18:50:55 +08:00
}
#pragma mark -
// UI
- (void)forceBoomStateReset {
NSLog(@"🔧 XPRoomViewController 强制重置连击状态");
// 1.
[[GiftComboManager sharedManager] forceBoomStateReset];
// 2. UI
dispatch_async(dispatch_get_main_queue(), ^{
self.sideMenu.hidden = NO;
self.menuContainerView.hidden = NO;
NSLog(@"🔄 强制恢复底部操作栏和侧栏显示");
});
}
//
- (void)applicationDidEnterBackground:(NSNotification *)notification {
if ([[GiftComboManager sharedManager] isActive]) {
NSLog(@"📱 应用进入后台,检查连击状态");
[self forceBoomStateReset];
}
}
//
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
if ([[GiftComboManager sharedManager] isActive]) {
NSLog(@"⚠️ 收到内存警告,检查连击状态");
[self forceBoomStateReset];
}
}
2023-07-14 18:50:55 +08:00
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor darkGrayColor];
2023-10-30 14:38:33 +08:00
[self.view addSubview:self.backContainerView];
2023-08-31 16:51:40 +08:00
[self.view addSubview:self.littleGameView];
2023-10-30 14:38:33 +08:00
[self.view addSubview:self.messageContainerView];
2024-05-16 14:30:21 +08:00
2023-10-30 14:38:33 +08:00
[self.view addSubview:self.quickMessageContainerView];
[self.view addSubview:self.menuContainerView];
2024-12-20 19:05:43 +08:00
[self.view addSubview:self.sideMenu];
2023-10-30 14:38:33 +08:00
[self.view addSubview:self.redPacketView];
[self.view addSubview:self.roomHeaderView];
[self.view addSubview:self.functionView];
[self.view addSubview:self.animationView];
2023-07-14 18:50:55 +08:00
}
2024-12-16 19:41:23 +08:00
- (void)__layoutTwentyMicStage {
[self.stageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
}
- (void)__layoutNineteenMicStage {
[self.stageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
}
- (void)__layoutFifteenMicStage {
[self.stageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
}
- (void)__layoutTenMicStage {
[self.stageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
}
2023-07-14 18:50:55 +08:00
- (void)initSubViewConstraints {
2023-10-30 14:38:33 +08:00
[self.backContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
2023-08-31 16:51:40 +08:00
[self.littleGameView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
2023-10-30 14:38:33 +08:00
[self.roomHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.trailing.top.mas_equalTo(self.view);
2023-10-30 14:38:33 +08:00
make.height.mas_equalTo(kNavigationHeight);
}];
[self.messageContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.roomHeaderView.mas_bottom);
2023-10-30 14:38:33 +08:00
make.bottom.equalTo(self.quickMessageContainerView.mas_top).offset(-5);
2024-04-11 17:05:27 +08:00
make.leading.equalTo(self.view);
2024-12-20 19:05:43 +08:00
make.trailing.equalTo(self.sideMenu.mas_leading).offset(-10);
2023-10-30 14:38:33 +08:00
}];
CGFloat quickMsgHeight = 30;
//
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *closeCount = [defaults objectForKey:kRoomQuickMessageCloseCount];
if (closeCount.intValue > 3) {
quickMsgHeight = 0;
} else {
quickMsgHeight = 30;
}
[self.quickMessageContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-10-12 19:30:41 +08:00
make.bottom.mas_equalTo(self.view).offset(- 52 - kSafeAreaBottomHeight);
2024-06-04 14:54:51 +08:00
make.height.mas_equalTo(0);
2024-04-11 17:05:27 +08:00
make.leading.trailing.mas_equalTo(self.view);
2023-10-30 14:38:33 +08:00
}];
[self.menuContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-10-15 20:56:25 +08:00
make.leading.trailing.mas_equalTo(self.view);
if (iPhoneXSeries) {
make.bottom.mas_equalTo(self.view);
} else {
make.bottom.mas_equalTo(-10);
}
2023-09-28 18:29:41 +08:00
make.height.mas_equalTo(52 + kSafeAreaBottomHeight);
2023-10-30 14:38:33 +08:00
}];
2024-12-20 19:05:43 +08:00
[self.sideMenu mas_makeConstraints:^(MASConstraintMaker *make) {
2023-10-30 14:38:33 +08:00
make.top.mas_equalTo(self.messageContainerView);
2024-04-11 17:05:27 +08:00
make.trailing.mas_equalTo(self.view);
2023-10-30 14:38:33 +08:00
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).offset(-5);
2024-02-21 10:18:59 +08:00
make.width.mas_equalTo(87);
2023-10-30 14:38:33 +08:00
}];
[self.redPacketView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(58));
make.trailing.mas_equalTo(-kGetScaleWidth(6));
make.bottom.mas_equalTo(-160);
}];
[self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self.functionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
2023-07-14 18:50:55 +08:00
}
- (void)updateViewConstraintsOnAnchorRoom {
2023-10-30 14:38:33 +08:00
[self.anchorScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self.backContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.anchorScrollView.middleImageView);
}];
[self.roomHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.trailing.top.mas_equalTo(self.anchorScrollView.middleImageView);
2023-10-30 14:38:33 +08:00
make.height.mas_equalTo(kNavigationHeight);
}];
[self.stageView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.trailing.mas_equalTo(self.anchorScrollView.middleImageView);
2023-10-30 14:38:33 +08:00
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
[self.messageContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.stageView.mas_bottom);
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).mas_offset(-5);
2024-04-11 17:05:27 +08:00
make.leading.equalTo(self.anchorScrollView.middleImageView);
2024-12-20 19:05:43 +08:00
make.trailing.equalTo(self.sideMenu.mas_leading).offset(-10);
2023-10-30 14:38:33 +08:00
}];
[self.quickMessageContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-06-04 14:54:51 +08:00
make.height.mas_equalTo(0);
2023-10-30 14:38:33 +08:00
make.bottom.mas_equalTo(self.backContainerView).mas_offset(-5-40-8-kSafeAreaBottomHeight);
2024-04-11 17:05:27 +08:00
make.leading.equalTo(self.anchorScrollView.middleImageView);
2024-12-20 19:05:43 +08:00
make.trailing.equalTo(self.sideMenu.mas_leading).offset(-10);
2023-10-30 14:38:33 +08:00
}];
[self.menuContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.anchorScrollView.middleImageView);
if (iPhoneXSeries) {
make.bottom.mas_equalTo(self.view);
} else {
make.bottom.mas_equalTo(self.view).offset(-10);
}
2023-09-28 18:29:41 +08:00
make.height.mas_equalTo(52 + kSafeAreaBottomHeight);
2023-10-30 14:38:33 +08:00
}];
2024-12-20 19:05:43 +08:00
[self.sideMenu mas_makeConstraints:^(MASConstraintMaker *make) {
2023-10-30 14:38:33 +08:00
make.top.mas_equalTo(self.messageContainerView);
2024-04-11 17:05:27 +08:00
make.trailing.mas_equalTo(self.anchorScrollView.middleImageView);
2023-10-30 14:38:33 +08:00
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).mas_offset(-5);
2024-02-21 10:18:59 +08:00
make.width.mas_equalTo(87);
2023-10-30 14:38:33 +08:00
}];
2023-10-20 19:30:20 +08:00
2023-10-30 14:38:33 +08:00
[self.functionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.anchorScrollView.middleImageView);
}];
2023-07-14 18:50:55 +08:00
}
- (void)handleActivityContainerViewEvents {
@kWeakify(self);
2024-12-20 19:05:43 +08:00
self.sideMenu.openRedPacketHandle = ^(XPRedPacketModel * _Nullable redModel,RoomType type,BOOL isChangeRoom) {
@kStrongify(self);
if(isChangeRoom == YES){
self.redPacketView.type = type;
2024-12-20 19:05:43 +08:00
self.redPacketView.redPacketList = self.sideMenu.redPacketList;
return;
}
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
view.delegate = self;
self.isShowRedPacket = YES;
view.receiveModel = redModel;
for (UIView *subView in self.view.subviews) {
if([subView isKindOfClass:[XPReceiveRedPacketView class]]) {
view.alphaView.backgroundColor = [UIColor clearColor];
break;
}
}
[self.view addSubview:view];
[self.view bringSubviewToFront:view];
};
2024-10-12 19:30:41 +08:00
2024-12-20 19:05:43 +08:00
self.sideMenu.showSendGiftView = ^{
2024-10-12 19:30:41 +08:00
@kStrongify(self);
NSString * roomUid = [NSString stringWithFormat:@"%ld", [self getRoomInfo].uid];
XPSendGiftView * giftView = [[XPSendGiftView alloc] initWithType:SendGiftType_Room uid:roomUid];
giftView.delegate = self;
NSArray * giftUses = [self configGiftUsers:[self getMicroQueue]];
[giftView configGiftUsers:giftUses];
[self.getCurrentNav presentViewController:giftView animated:YES completion:nil];
};
}
- (NSArray<XPGiftUserInfoModel *> *)configGiftUsers:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSMutableArray * array = [NSMutableArray array];
for (MicroQueueModel * microModel in queue.allValues) {
if (microModel.userInfo && microModel.userInfo.uid >0) {
UserInfoModel * userInfo = microModel.userInfo;
XPGiftUserInfoModel * userModel = [[XPGiftUserInfoModel alloc] init];
userModel.avatar = userInfo.avatar;
userModel.vipMic = userInfo.vipMic;
userModel.position = [NSString stringWithFormat:@"%d", microModel.microState.position];
userModel.uid = userInfo.uid;
if (self.getRoomInfo.type == RoomType_Anchor && microModel.microState.position == -1) {///
continue;
}
[array addObject:userModel];
}
}
if (self.getRoomInfo.leaveMode) {
RoomInfoModel * roomInfo= self.getRoomInfo;
XPGiftUserInfoModel * userModel = [[XPGiftUserInfoModel alloc] init];
userModel.avatar = roomInfo.avatar;
userModel.position = @"-1";
userModel.uid = roomInfo.uid;
[array addObject:userModel];
} else if (self.getRoomInfo.type == RoomType_Anchor) {
RoomInfoModel * roomInfo= self.getRoomInfo;
BOOL hadContainerOwner = NO;
for (UserInfoModel *userModel in array) {
if (userModel.uid == roomInfo.uid) {
hadContainerOwner = YES;
break;
}
}
if (!hadContainerOwner) {
XPGiftUserInfoModel * userModel = [[XPGiftUserInfoModel alloc] init];
userModel.avatar = roomInfo.avatar;
userModel.position = @"-1";
userModel.uid = roomInfo.uid;
[array addObject:userModel];
}
}
return array;
}
2023-07-14 18:50:55 +08:00
- (void)exitOldRoom {
2023-10-30 14:38:33 +08:00
NSString * roomUid = [NSString stringWithFormat:@"%ld", [XPRoomMiniManager shareManager].getRoomInfo.uid];
2024-10-17 16:05:02 +08:00
if (roomUid.integerValue > 0) {
if ([roomUid isEqualToString:self.roomUid]) {
self.isMiniEnter = YES;
} else {
// 退
NSString * roomId = [NSString stringWithFormat:@"%ld", [XPRoomMiniManager shareManager].getRoomInfo.roomId];
[self.presenter exitNIMRoom:roomId];
[[RtcManager instance] exitRoom];
[[XPRoomMiniManager shareManager] resetLocalMessage];
[self.presenter reportUserOutRoom:roomUid];
[XPSkillCardPlayerManager shareInstance].micState = MICState_None;
}
2023-10-30 14:38:33 +08:00
}
2023-07-14 18:50:55 +08:00
}
2024-04-01 10:32:18 +08:00
-(BOOL)getIsMiniEnter{
return self.isMiniEnter;
}
2023-07-14 18:50:55 +08:00
- (void)userEnterRoomSuccess {
2023-10-30 14:38:33 +08:00
AttachmentModel *attachment = [[AttachmentModel alloc]init];
attachment.first = CustomMessageType_Car_Notify;
attachment.second = Custom_Message_Sub_Car_EnterRoom;
NSMutableDictionary *att = [NSMutableDictionary dictionary];
2024-04-11 15:47:44 +08:00
if (self.userInfo.userVipInfoVO.enterHide) {///VIP,
2023-10-30 14:38:33 +08:00
return;
}
2025-01-22 21:22:58 +08:00
if (self.userInfo.platformRole == 1) {
return;
}
2023-10-30 14:38:33 +08:00
if (self.userInfo.viewUrl.length > 0) {
[att safeSetObject:self.userInfo.nick forKey:@"nick"];
[att safeSetObject:self.userInfo.viewUrl forKey:@"viewUrl"];
[att safeSetObject:@(self.userInfo.otherViewType) forKey:@"otherViewType"];
} else if (self.userInfo.carEffect.length > 0) {
[att safeSetObject:self.userInfo.carEffect forKey:@"effect"];
[att safeSetObject:self.userInfo.nick forKey:@"nick"];
} else {
return;
}
attachment.data = att;
NSString *sessionID = [NSString stringWithFormat:@"%ld",self.roomInfo.roomId];
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
message.messageObject = object;
//
NIMSession *session = [NIMSession session:sessionID type:NIMSessionTypeChatroom];
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
2023-07-14 18:50:55 +08:00
}
- (BOOL)updateStageView {
NSLog(@"🔄 updateStageView: 开始更新 stageView当前 alpha = %.2f", self.stageView.alpha);
// 使 StageViewManager stageView
if (self.stageViewManager) {
NSLog(@"🔧 updateStageView: 使用 StageViewManager");
BOOL success = [self.stageViewManager updateStageViewForRoomType:self.roomInfo.type
roomInfo:self.roomInfo
container:self.view
delegate:self];
if (success) {
self.stageView = self.stageViewManager.currentStageView;
if (self.stageView) {
NSLog(@"🔧 updateStageView: StageViewManager 设置 alpha = 0 (之前 = %.2f)", self.stageView.alpha);
self.stageView.alpha = 0;
NSLog(@"✅ StageViewManager 成功更新 stageView: %@", NSStringFromClass([self.stageView class]));
return YES;
}
}
NSLog(@"⚠️ StageViewManager 更新失败,降级到原有逻辑");
}
//
// NSLog(@"🔧 updateStageView: 使用降级逻辑");
// Class stageViewClass = [self stageViewClassForRoomInfo:self.roomInfo];
// if (stageViewClass) { //&& ![self.stageView isKindOfClass:stageViewClass]) {
// NSLog(@"🔧 updateStageView: 创建新的 stageView: %@", NSStringFromClass(stageViewClass));
// [self.stageView removeFromSuperview];
// self.stageView = nil;
// self.stageView = [[stageViewClass alloc] initWithDelegate:self];
// NSLog(@"🔧 updateStageView: 降级逻辑设置 alpha = 0 (之前 = %.2f)", self.stageView.alpha);
// self.stageView.alpha = 0;
// NSLog(@"✅ 降级逻辑成功更新 stageView: %@", NSStringFromClass([self.stageView class]));
// return YES;
// }
NSLog(@"❌ 所有 stageView 更新方法都失败了");
return NO;
}
- (Class)stageViewClassForRoomInfo:(RoomInfoModel *)roomInfo {
if (roomInfo.roomModeType == RoomModeType_Open_Blind) {
return [DatingStageView class];
}
if (roomInfo.datingState == RoomDatingStateChangeType_Close &&
![self.stageView isKindOfClass:[SocialStageView class]]) {
return [SocialStageView class];
}
if (roomInfo.type == RoomType_Anchor) {
if (roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode &&
![self.stageView isKindOfClass:[AnchorPKStageView class]]) {
return [AnchorPKStageView class];
} else if (roomInfo.roomModeType == RoomModeType_Normal_Mode &&
![self.stageView isKindOfClass:[AnchorStageView class]]) {
return [AnchorStageView class];
2023-10-30 14:38:33 +08:00
}
} else if (roomInfo.type == RoomType_MiniGame) {
return [LittleGameScrollStageView class];
} else if (roomInfo.type == RoomType_19Mic) {
return [NineteenMicStageView class];
} else if (roomInfo.type == RoomType_20Mic) {
return [TwentyMicStageView class];
} else if (roomInfo.type == RoomType_15Mic) {
return [FifteenMicStageView class];
} else if (roomInfo.type == RoomType_10Mic) {
return [TenMicStageView class];
} else if (roomInfo.hadChangeRoomType && ![self.stageView isKindOfClass:[SocialStageView class]]) {
return [SocialStageView class];
}
return [SocialStageView class];
}
- (void)changeStageViewOnRoomUpdate {
NSLog(@"🔄 changeStageViewOnRoomUpdate: 开始更新 stageView");
if (![self updateStageView]) {
NSLog(@"❌ changeStageViewOnRoomUpdate: updateStageView 失败");
2023-10-30 14:38:33 +08:00
return;
}
NSLog(@"✅ changeStageViewOnRoomUpdate: updateStageView 成功,当前 alpha = %.2f", self.stageView.alpha);
// 🔧
[[NSNotificationCenter defaultCenter] postNotificationName:@"RoomTypeChanged"
object:nil
userInfo:@{@"roomType": @(self.roomInfo.type)}];
2023-10-30 14:38:33 +08:00
if (!self.stageView.superview) {
NSLog(@"🔧 changeStageViewOnRoomUpdate: 添加 stageView 到视图层级");
[self.view insertSubview:self.stageView
belowSubview:self.roomHeaderView];
//
NSInteger index_sideMenu = -1;
NSInteger index_stageView = -1;
for (UIView *view in self.view.subviews) {
if (index_sideMenu == -1 || index_stageView == -1) {
if (view == self.sideMenu) {
index_sideMenu = [self.view.subviews indexOfObject:view];
}
if (view == self.stageView) {
index_stageView = [self.view.subviews indexOfObject:view];
}
} else {
[self.view exchangeSubviewAtIndex:index_sideMenu withSubviewAtIndex:index_stageView];
break;
}
}
}
NSLog(@"🔧 changeStageViewOnRoomUpdate: 设置 stageView.alpha = 1 (之前 = %.2f)", self.stageView.alpha);
self.stageView.alpha = 1;
NSLog(@"✅ changeStageViewOnRoomUpdate: stageView.alpha 已设置为 1");
//
[self debugStageViewStatus];
// 🔧 SocialStageView
[self drawSocialStageMidpointRects];
// 🔧 CPAPI
[self callMicCpListByRoomUidAfterRoomEntered];
// 🔧 stage viewCPAPI
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
[self callMicCpListByUidListWithQueue:currentQueue];
// 🔧 19 micposition 6
[self checkCentralPositionUserQualification:currentQueue];
[self addExitGameButton];
self.quickMessageContainerView.hidden = YES;
[self.quickMessageContainerView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0);
}];
switch (self.roomInfo.type) {
case RoomType_MiniGame: {
[self.stageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom).offset(26 + 4);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
CGFloat height = 80;
if (iPhoneXSeries) {
height = 100;
}
[self.messageContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(height);
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).offset(-5);
make.leading.mas_equalTo(self.view);
2024-12-20 19:05:43 +08:00
make.trailing.mas_equalTo(self.sideMenu.mas_leading).offset(-10);
}];
[self.sideMenu displayForMiniGame];
2024-12-20 19:05:43 +08:00
[self.sideMenu mas_remakeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).offset(-5);
make.width.mas_equalTo(87);
}];
2023-09-27 16:06:18 +08:00
}
break;
default: {
[self.stageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
[self.messageContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.stageView.mas_bottom);
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).offset(-5);
make.leading.mas_equalTo(self.view);
2024-12-20 19:05:43 +08:00
make.trailing.mas_equalTo(self.sideMenu.mas_leading).offset(-10);
}];
if (self.roomInfo.type == RoomType_19Mic || self.roomInfo.type == RoomType_20Mic) {
[self.sideMenu mas_remakeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(160);
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).offset(-5);
make.width.mas_equalTo(87);
}];
} else {
[self.sideMenu mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.messageContainerView);
make.trailing.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).offset(-5);
make.width.mas_equalTo(87);
}];
2025-01-09 14:22:59 +08:00
}
}
break;
2023-10-30 14:38:33 +08:00
}
2023-07-14 18:50:55 +08:00
}
- (void)changeStageViewOnAnchorRoom {
2023-10-30 14:38:33 +08:00
if (self.roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode && ![self.stageView isKindOfClass:[AnchorPKStageView class]]) {
[self.stageView removeFromSuperview];
self.stageView = nil;
self.stageView = [[AnchorPKStageView alloc] initWithDelegate:self];
} else if(self.roomInfo.roomModeType == RoomModeType_Normal_Mode && ![self.stageView isKindOfClass:[AnchorStageView class]]) {
[self.stageView removeFromSuperview];
self.stageView = nil;
self.stageView = [[AnchorStageView alloc] initWithDelegate:self];
}
if (!self.stageView.superview) {
[self.anchorScrollView insertSubview:self.stageView belowSubview:self.roomHeaderView];
}
[self.stageView mas_remakeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.trailing.mas_equalTo(self.anchorScrollView.middleImageView);
2023-10-30 14:38:33 +08:00
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
[self.messageContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.stageView.mas_bottom);
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).mas_offset(-5);
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(self.anchorScrollView.middleImageView);
2024-12-20 19:05:43 +08:00
make.trailing.mas_equalTo(self.sideMenu.mas_leading).offset(-10);
2023-10-30 14:38:33 +08:00
}];
CGFloat quickMsgHeight = 30;
//
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *closeCount = [defaults objectForKey:kRoomQuickMessageCloseCount];
if (closeCount.intValue > 3 || self.roomInfo.speakTemplate.count <=0) {
quickMsgHeight = 0;
} else {
quickMsgHeight = 30;
}
self.quickMessageContainerView.titleArray = self.roomInfo.speakTemplate;
[self.quickMessageContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
2024-06-04 14:54:51 +08:00
make.height.mas_equalTo(0);
2023-10-30 14:38:33 +08:00
make.bottom.mas_equalTo(self.backContainerView).mas_offset(-5-40-8-kSafeAreaBottomHeight);
2024-04-11 17:05:27 +08:00
make.leading.trailing.mas_equalTo(self.anchorScrollView.middleImageView);
2023-10-30 14:38:33 +08:00
}];
2024-12-20 19:05:43 +08:00
[self.sideMenu mas_remakeConstraints:^(MASConstraintMaker *make) {
2023-10-30 14:38:33 +08:00
make.top.mas_equalTo(self.messageContainerView);
2024-04-11 17:05:27 +08:00
make.trailing.mas_equalTo(self.anchorScrollView.middleImageView);
2023-10-30 14:38:33 +08:00
make.bottom.mas_equalTo(self.quickMessageContainerView.mas_top).mas_offset(-5);
2024-02-21 10:18:59 +08:00
make.width.mas_equalTo(87);
2023-10-30 14:38:33 +08:00
}];
}
- (void)setRoomInfo:(RoomInfoModel *)roomInfo {
if (_roomInfo == roomInfo) {
return;
}
_roomInfo = roomInfo;
NSString *roomId = @(self.roomInfo.roomId).stringValue;
NSLog(@"🎮 设置房间ID: %@", roomId);
[[TurboModeStateManager sharedManager] setCurrentRoomId:roomId];
[[LuckyPackageLogicManager sharedInstance] setRoomUid:@(roomInfo.uid).stringValue];
[[RoomResourceManager sharedManager] updateCurrentSkinID:roomInfo.usedMicSkinId
effectID:roomInfo.usedMicEffectId];
2024-12-20 19:05:43 +08:00
[self.sideMenu updateView];
}
#pragma mark - Game Switch
- (void)addExitGameButton {
[self removeExitGameButton];
2023-10-20 19:30:20 +08:00
if (self.roomInfo.type != RoomType_MiniGame) {
return;
}
if (_exitGameButton == nil) {
_exitGameButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_exitGameButton setTitle:@"切换" forState:UIControlStateNormal];
[_exitGameButton setImage:[UIImage imageNamed:@"ms_room_game_switch_button"] forState:UIControlStateNormal];
[_exitGameButton addTarget:self action:@selector(didTapExitGameButton) forControlEvents:UIControlEventTouchUpInside];
}
[self.view addSubview:self.exitGameButton];
[self.exitGameButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.stageView.mas_bottom).offset(10);
make.leading.mas_equalTo(self.view).offset(12);
make.width.height.equalTo(@21);
}];
2023-07-14 18:50:55 +08:00
}
- (void)removeExitGameButton {
[self.exitGameButton removeFromSuperview];
}
- (void)didTapExitGameButton {
if ([self.littleGameView isInSudGame]) {
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPRoomFunctionContainerView19")];
} else {
@kWeakify(self);
[TTPopup alertWithMessage:YMLocalizedString(@"XPRoomFunctionContainerView20") confirmHandler:^{
@kStrongify(self);
[XNDJTDDLoadingTool showLoading];
[self exitLittleGame];
} cancelHandler:^{ }];
}
}
- (void)exitLittleGame {
RoomInfoModel * roomInfo = self.getRoomInfo;
NSMutableDictionary * params = [NSMutableDictionary dictionary];
NSString * ticket = [AccountInfoStorage instance].getTicket;
[params setObject:ticket forKey:@"ticket"];
2024-06-06 17:10:28 +08:00
[params setObject:@(roomInfo.uid).stringValue forKey:@"uid"];
[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.uid] forKey:@"roomUid"];
if (roomInfo.title.length > 0) {
[params setObject:roomInfo.title forKey:@"title"];
}
if (roomInfo.roomPwd.length > 0) {
[params setObject:roomInfo.roomPwd forKey:@"roomPwd"];
} else{
[params setObject:@"" forKey:@"roomPwd"];
}
if (roomInfo.tagId > 0) {
[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.tagId] forKey:@"tagId"];
}
if (self.roomInfo.oldType == 0) {
self.roomInfo.oldType = RoomType_Room;
}
[params setObject:@(self.roomInfo.oldType) forKey:@"type"];
[params setObject:@"0" forKey:@"mgId"];
[params setObject:@(roomInfo.hasAnimationEffect) forKey:@"hasAnimationEffect"];
[Api ownerUpdateRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
[XNDJTDDLoadingTool hideHUD];
} else {
[XNDJTDDLoadingTool showErrorWithMessage:msg];
}
} params:params];
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
}
2023-10-31 11:09:04 +08:00
#pragma mark- XPReceiveRedPacketViewDelegate
- (void)closeViewAction{
self.isShowRedPacket = NO;
}
2023-10-30 14:38:33 +08:00
#pragma mark- PIRoomEnterRedPacketViewDelegate
- (void)openRedPacketWithModel:(XPRedPacketModel *)redModel{
2023-10-30 14:38:33 +08:00
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
view.receiveModel = redModel;
2023-10-31 11:09:04 +08:00
view.delegate = self;
self.isShowRedPacket = YES;
2023-10-30 14:38:33 +08:00
for (UIView *subView in self.view.subviews) {
if([subView isKindOfClass:[XPReceiveRedPacketView class]]) {
view.alphaView.backgroundColor = [UIColor clearColor];
break;
}
}
[self.view addSubview:view];
[self.view bringSubviewToFront:view];
}
2023-09-22 15:26:19 +08:00
#pragma mark - CountDownHelperDelegate
- (void)onCountdownFinish {
[[NSNotificationCenter defaultCenter]postNotificationName:kFreeGiftCountdownNotification object:nil userInfo:@{@"isCountdownFinish":@(YES)}];
if(self.freeModel.curStage.integerValue < self.freeModel.maxStage.integerValue){
[self.presenter getFreeGiftData];
}
if(self.freeModel.curStage.intValue == 0){
self.freeView.freeModel = self.freeModel;
if(!self.freeView.superview){
2023-10-30 14:38:33 +08:00
[kWindow addSubview:self.freeView];
2023-09-22 15:26:19 +08:00
}
}
}
2023-09-22 15:26:19 +08:00
- (void)onCountdownOpen:(int)time {
NSInteger seconds = time;
int hours = (seconds)%(24*3600)/3600;
int minutes = (seconds)%3600/60;
int second = (seconds)%60;
[[NSNotificationCenter defaultCenter] postNotificationName:kFreeGiftCountdownNotification
object:nil
userInfo:@{@"text": [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, second],
@"isCountdownFinish": @(NO)}];
2023-07-14 18:50:55 +08:00
}
2023-07-14 18:50:55 +08:00
- (void)cancelRoomArrangeMic {
2023-10-30 14:38:33 +08:00
///退
if (self.roomInfo.roomModeType == RoomModeType_Open_Micro_Mode || self.roomInfo.roomModeType == RoomModeType_Open_Blind) {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.roomInfo.uid];
NSString * uid = [AccountInfoStorage instance].getUid;
[Api getRoomArrangeMicList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
ArrangeMicModel * arrangeMicModel= [ArrangeMicModel modelWithJSON:data.data];
if (arrangeMicModel.myPos.intValue > 0) {
__block NSString * grouptype = @"0";
if (self.roomInfo.roomModeType == RoomModeType_Open_Blind) {
[arrangeMicModel.queue enumerateObjectsUsingBlock:^(ArrangeMicUserModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
grouptype = [NSString stringWithFormat:@"%ld", obj.groupType];
*stop = YES;
}
}];
}
[Api cancelArrangeMic:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {} roomUid:roomUid operUid:uid groupType:grouptype];
}
}
} roomUid:roomUid operUid:uid page:@"1" pageSize:@"50"];
}else if(self.roomInfo.roomModeType == RoomModeType_Open_PK_Mode) {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.roomInfo.uid];
NSString * uid = [AccountInfoStorage instance].getUid;
[Api getRoomPKUserList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
ArrangeMicModel * arrangeMicModel= [ArrangeMicModel modelWithJSON:data.data];
if (arrangeMicModel.myPos.intValue > 0) {
__block NSString * grouptype = @"0";
[arrangeMicModel.queue enumerateObjectsUsingBlock:^(ArrangeMicUserModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
grouptype = [NSString stringWithFormat:@"%ld", obj.groupType];
*stop = YES;
}
}];
[Api cancelRoomPKArrangeMic:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
} roomUid:roomUid operUid:uid groupType:grouptype];
}
}
} roomUid:roomUid operUid:uid page:@"1" pageSize:@"50"];
}
2023-07-14 18:50:55 +08:00
}
///
- (void)superAdminEnterPwdRoom:(RoomInfoModel *)roomInfo {
2023-10-30 14:38:33 +08:00
__block BOOL isSuperAdmin = NO;
[self.superMangerList enumerateObjectsUsingBlock:^(GuildSuperAdminInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.uid isEqualToString:[AccountInfoStorage instance].getUid]) {
isSuperAdmin = YES;
*stop = YES;
}
}];
2025-01-22 21:22:58 +08:00
if (!isSuperAdmin) {
isSuperAdmin = self.userInfo.platformRole == 1;
}
2023-10-30 14:38:33 +08:00
if (!isSuperAdmin) {
XPRoomSettingInputView * titleView = [[XPRoomSettingInputView alloc] init];
titleView.maxCount = 15;
titleView.delegate = self;
titleView.type = RoomSettingInputType_Input_Pwd;
TTPopupConfig * config = [[TTPopupConfig alloc] init];
config.contentView = titleView;
config.maskBackgroundAlpha = 1;
config.shouldDismissOnBackgroundTouch = NO;
[TTPopup popupWithConfig:config];
} else {
self.roomInfo.datingState = roomInfo.roomModeType == RoomModeType_Open_Blind ? RoomDatingStateChangeType_Open : RoomDatingStateChangeType_Normal;
[self changeStageViewOnRoomUpdate];
[self.roomHeaderView onRoomEntered];
2024-12-20 19:05:43 +08:00
[self.sideMenu onRoomEntered];
2024-10-17 16:05:02 +08:00
2023-10-30 14:38:33 +08:00
[self.backContainerView onRoomEntered];
2023-08-31 16:51:40 +08:00
[self.littleGameView onRoomEntered];
2023-10-30 14:38:33 +08:00
if ([XPRoomMiniManager shareManager].getRoomInfo.uid != self.roomUid.integerValue) {// 退
// 🔧
if (!self.isExitingRoom && self.isViewActive) {
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2023-10-30 14:38:33 +08:00
[self.functionView onRoomEntered];
[self.messageContainerView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomEntered];
2023-10-30 14:38:33 +08:00
} else {
//退
[self.stageView onRoomMiniEntered];
[self.messageContainerView onRoomMiniEntered];
[self.functionView onRoomMiniEntered];
[self.functionView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomMiniEntered];
// 🔧
[self initializeCurrentUserMicStatusForMiniEnter];
2023-10-30 14:38:33 +08:00
}
[[XPRoomMiniManager shareManager] configRoomInfo:nil];
[[XPRoomMiniManager shareManager] configUserInfo:nil];
[[XPRoomMiniManager shareManager] configCurrentMusic:nil isPlaying:NO];
}
2023-07-14 18:50:55 +08:00
}
///
- (void)handleSuperManagerEnterAnchorRoom:(RoomInfoModel *)roomInfo {
2023-10-30 14:38:33 +08:00
__block BOOL isSuperAdmin = NO;
[self.superMangerList enumerateObjectsUsingBlock:^(GuildSuperAdminInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.uid isEqualToString:[AccountInfoStorage instance].getUid]) {
isSuperAdmin = YES;
*stop = YES;
}
}];
2025-01-22 21:22:58 +08:00
if (!isSuperAdmin) {
isSuperAdmin = self.userInfo.platformRole == 1;
}
2023-10-30 14:38:33 +08:00
if (!isSuperAdmin) {
XPRoomSettingInputView * titleView = [[XPRoomSettingInputView alloc] init];
titleView.maxCount = 15;
titleView.delegate = self;
titleView.type = RoomSettingInputType_Input_Pwd;
TTPopupConfig * config = [[TTPopupConfig alloc] init];
config.contentView = titleView;
config.maskBackgroundAlpha = 1;
config.shouldDismissOnBackgroundTouch = NO;
[TTPopup popupWithConfig:config];
} else {
self.roomInfo.datingState = roomInfo.roomModeType == RoomModeType_Open_Blind ? RoomDatingStateChangeType_Open : RoomDatingStateChangeType_Normal;
if (!self.anchorScrollView.superview) {
[self.view insertSubview:self.anchorScrollView belowSubview:self.menuContainerView];
}
[self.backContainerView removeFromSuperview];
[self.stageView removeFromSuperview];
[self.messageContainerView removeFromSuperview];
[self.quickMessageContainerView removeFromSuperview];
2024-12-20 19:05:43 +08:00
[self.sideMenu removeFromSuperview];
2023-10-30 14:38:33 +08:00
[self.roomHeaderView removeFromSuperview];
[self.functionView removeFromSuperview];
[self.anchorScrollView addSubview:self.backContainerView];
[self.anchorScrollView addSubview:self.stageView];
[self.anchorScrollView addSubview:self.messageContainerView];
[self.anchorScrollView addSubview:self.quickMessageContainerView];
2024-12-20 19:05:43 +08:00
[self.anchorScrollView addSubview:self.sideMenu];
2023-10-30 14:38:33 +08:00
[self.anchorScrollView addSubview:self.roomHeaderView];
if (!self.menuContainerView.superview) {
[self.view addSubview:self.menuContainerView];
}
[self.anchorScrollView addSubview:self.functionView];
2023-10-30 14:38:33 +08:00
[self.view bringSubviewToFront:self.animationView];
[self updateViewConstraintsOnAnchorRoom];
[self changeStageViewOnAnchorRoom];
[self.roomHeaderView onRoomEntered];
2024-12-20 19:05:43 +08:00
[self.sideMenu onRoomEntered];
2023-10-30 14:38:33 +08:00
2024-10-17 16:05:02 +08:00
2023-10-30 14:38:33 +08:00
[self.backContainerView onRoomEntered];
2023-08-31 16:51:40 +08:00
[self.littleGameView onRoomEntered];
2023-10-30 14:38:33 +08:00
if ([XPRoomMiniManager shareManager].getRoomInfo.uid != self.roomUid.integerValue) {// 退
// 🔧
if (!self.isExitingRoom && self.isViewActive) {
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2023-10-30 14:38:33 +08:00
[self.functionView onRoomEntered];
[self.messageContainerView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomEntered];
2023-10-30 14:38:33 +08:00
} else {
//退
[self.stageView onRoomMiniEntered];
[self.messageContainerView onRoomMiniEntered];
[self.functionView onRoomMiniEntered];
[self.functionView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomMiniEntered];
// 🔧
[self initializeCurrentUserMicStatusForMiniEnter];
2023-10-30 14:38:33 +08:00
}
[[XPRoomMiniManager shareManager] configRoomInfo:nil];
[[XPRoomMiniManager shareManager] configUserInfo:nil];
[[XPRoomMiniManager shareManager] configCurrentMusic:nil isPlaying:NO];
}
2023-07-14 18:50:55 +08:00
}
///
- (void)showAnchorScrollTipView {
2023-10-30 14:38:33 +08:00
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *anchoScrollTip = [defaults objectForKey:kHadShowAnchorRoomTipKey];
if (!anchoScrollTip) {
UIWindow *window = [UIApplication sharedApplication].delegate.window;
[window addSubview:self.anchorScrollTipView];
[window bringSubviewToFront:self.anchorScrollTipView];
}
2023-07-14 18:50:55 +08:00
}
2023-09-22 17:43:21 +08:00
-(void)requesstShieldingAction{
[self.presenter requestShieldingWithType:@"1" objId:[NSString stringWithFormat:@"%ld",self.roomInfo.uid]];
2023-09-22 17:43:21 +08:00
}
-(void)requestShieldingSuccess{
2023-10-17 18:30:14 +08:00
[self showErrorToast:YMLocalizedString(@"RoomHeaderView11")];
[self exitRoom];
}
2023-07-14 18:50:55 +08:00
#pragma mark -
- (void)myGiftEffectUpdate:(NSNotification *)notification {
2023-10-30 14:38:33 +08:00
NSDictionary * dic = notification.object;
self.roomInfo.hasAnimationEffect = ((NSNumber *)dic[@"hasAnimationEffect"]).boolValue;
self.hasAnimationEffect = self.roomInfo.hasAnimationEffect;
[self.roomHeaderView onRoomUpdate];
2023-07-14 18:50:55 +08:00
}
#pragma mark - XPRoomProtocol
2023-10-17 18:30:14 +08:00
///id
-(void)getUnlockRoomAlbumPhotoListSuccessWithList:(NSArray *)list{}
2023-11-28 16:50:45 +08:00
///
-(void)getKickUserListSuccessWithList:(NSArray *)list{
NSString *uid = [[AccountInfoStorage instance]getUid];
for (id obj in list) {
if([obj integerValue] == [uid integerValue]){
2023-11-30 16:41:28 +08:00
[self exitRoom];
2023-11-28 16:50:45 +08:00
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPRoomViewController0")];
break;
}
}
}
- (void)handleRoomWithPasswordAfterInitRoom {
if (!self.isRequestSuperAdmin) {
@kWeakify(self);
[Api getRoomSuperAdminList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
NSArray<GuildSuperAdminInfoModel *> * array = [GuildSuperAdminInfoModel modelsWithArray:data.data];
self.superMangerList = array;
[self superAdminEnterPwdRoom:self.roomInfo];
} roomUid:self.roomUid];
} else {
[self superAdminEnterPwdRoom:self.roomInfo];
}
}
- (void)handleRoomWithoutPasswordAfterInitRoom {
NSLog(@"🔄 handleRoomWithoutPasswordAfterInitRoom: 开始处理无密码房间");
self.roomInfo.datingState = (self.roomInfo.roomModeType == RoomModeType_Open_Blind) ?
RoomDatingStateChangeType_Open :
RoomDatingStateChangeType_Normal;
NSLog(@"🔧 handleRoomWithoutPasswordAfterInitRoom: 调用 changeStageViewOnRoomUpdate");
[self changeStageViewOnRoomUpdate];
NSLog(@"✅ handleRoomWithoutPasswordAfterInitRoom: changeStageViewOnRoomUpdate 完成");
[self.roomHeaderView onRoomEntered];
2024-12-20 19:05:43 +08:00
[self.sideMenu onRoomEntered];
[self.backContainerView onRoomEntered];
[self.littleGameView onRoomEntered];
self.quickMessageContainerView.titleArray = self.roomInfo.speakTemplate;
if ([XPRoomMiniManager shareManager].getRoomInfo.uid != self.roomUid.integerValue) {
[self.functionView onRoomEntered];
[self.messageContainerView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomEntered];
//
[self.presenter enterNIMRoom:@(self.roomInfo.roomId).stringValue
user:self.userInfo];
} else {
//退
[self.stageView onRoomMiniEntered];
[self.functionView onRoomMiniEntered];
2025-03-06 15:26:44 +08:00
[self.sideMenu onRoomMiniEntered];
[self.functionView onRoomEntered];
2025-01-22 21:22:58 +08:00
[self.menuContainerView onRoomMiniEntered];
2024-10-17 16:05:02 +08:00
// PK 仿 2 roominfo functionView
if (self.roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode ||
self.roomInfo.roomModeType == RoomModeType_Open_PK_Mode) {
[self.functionView onRoomEntered];
}
[self.messageContainerView onRoomMiniEntered];
// 🔧
[self initializeCurrentUserMicStatusForMiniEnter];
}
[self cleanMiniRoomStatues];
}
- (void)enterMyRoom {
if (self.roomInfo.roomId > 0) { // 使
if (self.roomInfo.type == RoomType_MiniGame &&
self.roomInfo.mgId > 0) {
self.mgId = [NSString stringWithFormat:@"%lld", self.roomInfo.mgId];
}
[self.presenter openRoom:self.roomInfo.title
type:self.roomInfo.type
roomPwd:self.roomInfo.roomPwd
roomDesc:self.roomInfo.roomDesc
backPic:@""
mgId:self.mgId];
} else { //
NSString* title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomViewController1"), self.userInfo.nick];
RoomType type = RoomType_Room;
if (self.mgId.length > 0) {
type = RoomType_MiniGame;
}
[self.presenter openRoom:title
type:type
roomPwd:@""
roomDesc:@""
backPic:@""
mgId:self.mgId];
}
}
- (void)cleanMiniRoomStatues {
[[XPRoomMiniManager shareManager] configRoomInfo:nil];
[[XPRoomMiniManager shareManager] configUserInfo:nil];
[[XPRoomMiniManager shareManager] configCurrentMusic:nil isPlaying:NO];
}
2024-01-11 17:57:06 +08:00
- (void)initEnterRoomSuccess:(RoomInfoModel *)roomInfo user:(UserInfoModel *)userInfo {
[XNDJTDDLoadingTool hideHUDInView:self.navigationController.view];
2024-10-12 19:30:41 +08:00
[XPSkillCardPlayerManager shareInstance].roomUid = @(roomInfo.uid).stringValue;
2023-10-30 14:38:33 +08:00
userInfo.fromUid = self.fromUid;
userInfo.fromType = self.fromType;
userInfo.fromNick = self.fromNick;
2023-10-30 14:38:33 +08:00
self.hasAnimationEffect = roomInfo.hasAnimationEffect;
self.roomInfo = roomInfo;
self.userInfo = userInfo;
// roominfo
NSString *roomId = @(roomInfo.roomId).stringValue;
[[TurboModeStateManager sharedManager] updateGiftEffectsForRoom:roomId
enabled:roomInfo.hasAnimationEffect];
[self requestBoomData];
2024-09-14 18:29:36 +08:00
@kWeakify(self);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
@kStrongify(self);
2023-10-30 15:41:21 +08:00
//
[self.presenter getRedPacket:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
[self getOnlineCount];
2023-10-30 15:41:21 +08:00
});
switch (roomInfo.type) {
case RoomType_Anchor:
[self handleInitAnchorRoom];
[self showAnchorScrollTipView];
break;
default: {
if (roomInfo.valid) { //
if (roomInfo.roomPwd.length > 0 &&
roomInfo.uid != [AccountInfoStorage instance].getUid.integerValue &&
[XPRoomMiniManager shareManager].getRoomInfo.uid != self.roomUid.integerValue) {//
[self handleRoomWithPasswordAfterInitRoom];
} else {
[self handleRoomWithoutPasswordAfterInitRoom];
}
} else { //
if ([self.roomUid isEqualToString:[NSString stringWithFormat:@"%ld", userInfo.uid]]) {
//
[self enterMyRoom];
} else { //
[self showSuccessToast:YMLocalizedString(@"XPRoomViewController2")];
[self enterRoomFail:0];
}
} }
break;
2023-10-30 14:38:33 +08:00
}
2024-10-17 16:05:02 +08:00
[self.menuContainerView recheckMicState];
2023-07-14 18:50:55 +08:00
}
- (void)openRoomSuccess:(RoomInfoModel *)roomInfo {
2023-10-30 14:38:33 +08:00
[XNDJTDDLoadingTool hideHUDInView:self.navigationController.view];
2023-10-30 14:38:33 +08:00
self.roomInfo = roomInfo;
[XPSkillCardPlayerManager shareInstance].is9Mic = roomInfo.type == RoomType_Room;
2025-01-22 21:22:58 +08:00
2023-10-30 14:38:33 +08:00
if (roomInfo.type == RoomType_Anchor) {
[self handleInitAnchorRoom];
[self showAnchorScrollTipView];
return;
}
2023-10-30 14:38:33 +08:00
[self changeStageViewOnRoomUpdate];
[self.roomHeaderView onRoomEntered];
2024-12-20 19:05:43 +08:00
[self.sideMenu onRoomEntered];
2023-10-30 14:38:33 +08:00
[self.backContainerView onRoomEntered];
2023-08-31 16:51:40 +08:00
[self.littleGameView onRoomEntered];
2023-10-30 14:38:33 +08:00
[self.functionView onRoomEntered];
[self.messageContainerView onRoomEntered];
2023-10-30 14:38:33 +08:00
self.quickMessageContainerView.titleArray = self.roomInfo.speakTemplate;
// 🔧
if (!self.isExitingRoom && self.isViewActive) {
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2023-07-14 18:50:55 +08:00
}
- (void)enterRoomSuccess:(NIMChatroom *)chatRoom {
2023-10-30 14:38:33 +08:00
[XNDJTDDLoadingTool hideHUDInView:self.navigationController.view];
2025-01-22 21:22:58 +08:00
// 🔧 VC
if (self.isExitingRoom || !self.isViewActive) {
NSLog(@"🔧 enterRoomSuccess: VC 已退出或不可见,忽略回调");
return;
}
2024-05-21 14:17:30 +08:00
2023-10-30 14:38:33 +08:00
[self.stageView onRoomEntered];
[self.functionView onRoomEntered];
// 🔧
[self initializeCurrentUserMicStatus];
2023-10-30 14:38:33 +08:00
//
if (self.roomInfo != nil) {
[self.presenter reportUserInterRoom:[NSString stringWithFormat:@"%zd", self.roomInfo.uid]];
}
if (self.giftId.length) {
///
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"kShowGiftView" object:@{@"giftId": self.giftId}];
});
}
2023-07-14 18:50:55 +08:00
}
2023-07-14 18:50:55 +08:00
- (void)enterRoomFail:(NSInteger)code {
2023-10-30 14:38:33 +08:00
[XNDJTDDLoadingTool hideHUDInView:self.navigationController.view];
[self hideHUD];
// 🔧 VC
if (self.isExitingRoom || !self.isViewActive) {
NSLog(@"🔧 enterRoomFail: VC 已退出或不可见,忽略回调 (code: %ld)", (long)code);
return;
}
2023-10-30 14:38:33 +08:00
if (code == 13003) {
[self showErrorToast:YMLocalizedString(@"XPRoomViewController3")];
}
[self dismissViewControllerAnimated:YES completion:nil];
2023-07-14 18:50:55 +08:00
}
2024-05-21 14:17:30 +08:00
-(void)getOnlineCount{
@kWeakify(self);
2024-05-21 14:17:30 +08:00
[Api requestRoomOnlineUserList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
2024-05-21 14:17:30 +08:00
if(code == 200){
2025-01-22 21:22:58 +08:00
NSMutableArray *temp = @[].mutableCopy;
2024-05-21 14:17:30 +08:00
NSArray *list = [XPMessageRemoteExtModel modelsWithArray:data.data];
2025-01-22 21:22:58 +08:00
for (XPMessageRemoteExtModel *model in list) {
if (model.platformRole != 1) {
[temp addObject:model];
}
}
self.roomInfo.onlineNum = temp.count;
[self.functionView updateOnlineCount:[NSString stringWithFormat:@"%ld",temp.count] countList:temp.copy isUpdateCount:NO];
2024-05-21 14:17:30 +08:00
}
2025-01-22 21:22:58 +08:00
//
@kWeakify(self);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(60 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@kStrongify(self);
if (self) {
[self getOnlineCount];
}
});
2024-05-21 14:17:30 +08:00
} roomUid:self.roomUid];
}
2023-07-14 18:50:55 +08:00
///
///roominfo userinfo
- (void)getRoomSuperAdminSuccess:(NSArray *)list {
2023-10-30 14:38:33 +08:00
self.isRequestSuperAdmin = YES;
self.superMangerList = list;
2023-07-14 18:50:55 +08:00
}
///)
- (void)getNextAnchorRoomSuccess:(RoomInfoModel *)roomInfo {
2023-10-30 14:38:33 +08:00
[self hideHUD];
if (roomInfo) { //
if (![self.anchorRoomList containsObject:self.roomUid]) {
[self.anchorRoomList addObject:self.roomUid];
}
self.anchorIndex = self.anchorRoomList.count -1;
//1退
self.anchorScrollView.isCanScrollTop = YES;
self.anchorScrollView.contentOffset = CGPointMake(0, KScreenHeight);
self.isRequestSuperAdmin = NO;
[self exitOldRoom];
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[XPRoomMiniManager shareManager] resetLocalMessage];
[[RtcManager instance] exitRoom];
[self.presenter reportUserOutRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
[self.functionView onRoomChange];
//2
[self.stageView removeFromSuperview];
[self.messageContainerView removeFromSuperview];
[self.quickMessageContainerView removeFromSuperview];
2024-12-20 19:05:43 +08:00
[self.sideMenu removeFromSuperview];
2023-10-30 14:38:33 +08:00
[self.roomHeaderView removeFromSuperview];
[self.functionView removeFromSuperview];
self.functionView = nil;
self.messageContainerView = nil;
self.stageView = nil;
[self.menuContainerView removeFromSuperview];
self.menuContainerView = nil;
//3
self.roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
///
[self.presenter getNormalGiftList:self.roomUid];
///
[self.presenter getRoomSuperAdmin:self.roomUid];
} else {
if (self.anchorScrollView.isCanScrollTop) {
self.anchorScrollView.contentOffset = CGPointMake(0, KScreenHeight);
} else {
self.anchorScrollView.contentOffset = CGPointMake(0, 0);
}
[self showErrorToast:YMLocalizedString(@"XPRoomViewController4")];
}
2023-07-14 18:50:55 +08:00
}
- (void)getCurrentRoomInfoSuccess:(RoomInfoModel *)roomInfo {
2023-10-30 14:38:33 +08:00
[self hideHUD];
self.anchorScrollView.contentOffset = CGPointMake(0, KScreenHeight);
if (roomInfo && roomInfo.valid) {
//1退
self.isRequestSuperAdmin = NO;
[self exitOldRoom];
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[XPRoomMiniManager shareManager] resetLocalMessage];
[[RtcManager instance] exitRoom];
[self.presenter reportUserOutRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
//2
// [self.backContainerView removeFromSuperview];
[self.stageView removeFromSuperview];
[self.messageContainerView removeFromSuperview];
[self.quickMessageContainerView removeFromSuperview];
2024-12-20 19:05:43 +08:00
[self.sideMenu removeFromSuperview];
2023-10-30 14:38:33 +08:00
[self.roomHeaderView removeFromSuperview];
[self.functionView removeFromSuperview];
self.functionView = nil;
self.messageContainerView = nil;
self.stageView = nil;
[self.menuContainerView removeFromSuperview];
self.menuContainerView = nil;
//3
self.roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
///
[self.presenter getNormalGiftList:self.roomUid];
///
[self.presenter getRoomSuperAdmin:self.roomUid];
} else {
[self showErrorToast:YMLocalizedString(@"XPRoomViewController5")];
}
2023-07-14 18:50:55 +08:00
}
///
- (void)handleInitAnchorRoom {
2023-10-30 14:38:33 +08:00
if (self.roomInfo.valid) { //
2025-01-22 21:22:58 +08:00
if (self.roomInfo.roomPwd.length > 0 &&
self.roomInfo.uid != [AccountInfoStorage instance].getUid.integerValue &&
[XPRoomMiniManager shareManager].getRoomInfo.uid != self.roomUid.integerValue) {//
2023-10-30 14:38:33 +08:00
if (!self.isRequestSuperAdmin) {
@kWeakify(self);
2023-10-30 14:38:33 +08:00
[Api getRoomSuperAdminList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
2023-10-30 14:38:33 +08:00
NSArray<GuildSuperAdminInfoModel *> * array = [GuildSuperAdminInfoModel modelsWithArray:data.data];
self.superMangerList = array;
[self handleSuperManagerEnterAnchorRoom:self.roomInfo];
} roomUid:self.roomUid];
} else {
[self handleSuperManagerEnterAnchorRoom:self.roomInfo];
}
} else {
self.roomInfo.datingState = self.roomInfo.roomModeType == RoomModeType_Open_Blind ? RoomDatingStateChangeType_Open : RoomDatingStateChangeType_Normal;
[self __removeAllViews];
2023-10-30 14:38:33 +08:00
if (!self.anchorScrollView.superview) {
[self.view addSubview:self.anchorScrollView];
}
2023-10-30 14:38:33 +08:00
[self.anchorScrollView addSubview:self.backContainerView];
[self.anchorScrollView addSubview:self.stageView];
[self.anchorScrollView addSubview:self.messageContainerView];
[self.anchorScrollView addSubview:self.quickMessageContainerView];
2024-12-20 19:05:43 +08:00
[self.anchorScrollView addSubview:self.sideMenu];
2023-10-30 14:38:33 +08:00
[self.anchorScrollView addSubview:self.roomHeaderView];
[self.anchorScrollView addSubview:self.menuContainerView];
[self.anchorScrollView addSubview:self.functionView];
2023-10-30 14:38:33 +08:00
[self.view bringSubviewToFront:self.animationView];
[self updateViewConstraintsOnAnchorRoom];
[self changeStageViewOnAnchorRoom];
[self.roomHeaderView onRoomEntered];
2024-12-20 19:05:43 +08:00
[self.sideMenu onRoomEntered];
2023-10-30 14:38:33 +08:00
2024-10-17 16:05:02 +08:00
2023-10-30 14:38:33 +08:00
[self.backContainerView onRoomEntered];
2023-08-31 16:51:40 +08:00
[self.littleGameView onRoomEntered];
2023-10-30 14:38:33 +08:00
if ([XPRoomMiniManager shareManager].getRoomInfo.uid != self.roomUid.integerValue) {// 退
// 🔧
if (!self.isExitingRoom && self.isViewActive) {
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2023-10-30 14:38:33 +08:00
[self.functionView onRoomEntered];
[self.messageContainerView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomEntered];
2023-10-30 14:38:33 +08:00
} else {
//退
[self.stageView onRoomMiniEntered];
[self.messageContainerView onRoomMiniEntered];
[self.functionView onRoomMiniEntered];
[self.functionView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomMiniEntered];
// 🔧
[self initializeCurrentUserMicStatusForMiniEnter];
2023-10-30 14:38:33 +08:00
}
[self cleanMiniRoomStatues];
2023-10-30 14:38:33 +08:00
}
} else { //
if ([self.roomUid isEqualToString:[NSString stringWithFormat:@"%ld", self.userInfo.uid]]) { //
if (self.roomInfo.roomId > 0) { // 使
if (self.roomInfo.type == RoomType_MiniGame && self.roomInfo.mgId > 0) {
self.mgId = [NSString stringWithFormat:@"%lld", self.roomInfo.mgId];
}
[self.presenter openRoom:self.roomInfo.title type:self.roomInfo.type roomPwd:self.roomInfo.roomPwd roomDesc:self.roomInfo.roomDesc backPic:@"" mgId:self.mgId];
} else { //
NSString* title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomViewController6"), self.userInfo.nick];
RoomType type = RoomType_Room;
2023-10-30 14:38:33 +08:00
if (self.mgId.length > 0) {
type = RoomType_MiniGame;
}
[self.presenter openRoom:title type:type roomPwd:@"" roomDesc:@"" backPic:@"" mgId:self.mgId];
}
} else { //
[self showSuccessToast:YMLocalizedString(@"XPRoomViewController7")];
[self enterRoomFail:0];
}
}
2023-07-14 18:50:55 +08:00
}
- (void)getRedPacketInfoSuccess:(XPRedPacketModel *)redInfo{
2023-10-27 17:21:23 +08:00
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
2023-10-31 11:09:04 +08:00
view.delegate = self;
self.isShowRedPacket = YES;
2023-10-27 17:21:23 +08:00
redInfo.validityType = 0;
redInfo.kind = 1;
view.receiveModel = redInfo;
view.inAllPacketRoom = YES;
for (UIView *subView in self.view.subviews) {
if([subView isKindOfClass:[XPReceiveRedPacketView class]]) {
view.alphaView.backgroundColor = [UIColor clearColor];
break;
}
}
[self.view addSubview:view];
[self.view bringSubviewToFront:view];
}
2023-07-14 18:50:55 +08:00
- (void)getRedPacketSuccess:(NSArray *)list {
2023-10-25 19:26:20 +08:00
if(list.count > 0){
2024-12-20 19:05:43 +08:00
self.sideMenu.redPacketList = [NSMutableArray arrayWithArray:list];
2023-10-25 19:26:20 +08:00
}
2023-07-14 18:50:55 +08:00
}
2023-09-22 15:26:19 +08:00
-(void)getFreeGiftDataSuccess:(XPFreeGiftModel *)freeModel{
self.freeModel = freeModel;
self.menuContainerView.freeModel = freeModel;
if(self.freeModel.curStage.integerValue < self.freeModel.maxStage.integerValue){
[CountDownHelper shareHelper].isCountdownFinish = NO;
[[CountDownHelper shareHelper] openCountdownWithTime:freeModel.curStageSecond.intValue];
}else{
if([CountDownHelper shareHelper].isCountdownFinish == NO){
[CountDownHelper shareHelper].isCountdownFinish = YES;
}
[[NSNotificationCenter defaultCenter]postNotificationName:kFreeGiftCountdownNotification object:nil userInfo:@{@"isHiddenCountdown":@(YES)}];
[[CountDownHelper shareHelper] stopCountDown];
}
if(self.freeModel.curStage.intValue > 0 && [[XPRoomMiniManager shareManager].curState isEqualToString:@"0"]){
self.freeView.freeModel = self.freeModel;
if(!self.freeView.superview){
2023-10-30 14:38:33 +08:00
[kWindow addSubview:self.freeView];
2023-09-22 15:26:19 +08:00
}
[XPRoomMiniManager shareManager].curState = nil;
}
}
2023-07-14 18:50:55 +08:00
#pragma mark - NIMChatroomManagerDelegate
- (void)chatroomBeKicked:(NIMChatroomBeKickedResult *)result {
2023-11-13 16:42:34 +08:00
2023-11-28 16:50:45 +08:00
if (result.reason == 5) {
2023-10-30 14:38:33 +08:00
[self showErrorToast:YMLocalizedString(@"XPRoomViewController9")];
}
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[XPRoomMiniManager shareManager] resetLocalMessage];
[self cancelRoomArrangeMic];
[[RtcManager instance] exitRoom];
[self.presenter reportUserOutRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
2023-08-31 16:51:40 +08:00
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
2023-10-30 14:38:33 +08:00
[self dismissViewControllerAnimated:YES completion:nil];
2023-07-14 18:50:55 +08:00
}
#pragma mark - NIMChatManagerDelegate
- (void)__removeAllViews {
[self.anchorScrollView removeFromSuperview];
[self.backContainerView removeFromSuperview];
[self.stageView removeFromSuperview];
[self.messageContainerView removeFromSuperview];
[self.quickMessageContainerView removeFromSuperview];
2024-12-20 19:05:43 +08:00
[self.sideMenu removeFromSuperview];
[self.roomHeaderView removeFromSuperview];
[self.functionView removeFromSuperview];
[self.menuContainerView removeFromSuperview];
}
2023-07-14 18:50:55 +08:00
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
// 线
2023-10-30 14:38:33 +08:00
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 = (AttachmentModel *)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;
}
}
}
}
}
//
2023-10-30 14:38:33 +08:00
if (message.session.sessionType != NIMSessionTypeChatroom) {
NSLog(@"[Recv] ⛔️ 过滤:非聊天室消息 | type=%ld | sid=%@",
(long)message.session.sessionType, message.session.sessionId);
2023-10-30 14:38:33 +08:00
continue;
}
if (![message.session.sessionId isEqualToString:@(self.roomInfo.roomId).stringValue]) {
NSLog(@"[Recv] ⛔️ 过滤:房间不匹配 | msg.sid=%@ | curRoomId=%@",
message.session.sessionId, @(self.roomInfo.roomId).stringValue);
continue;
2024-05-16 14:30:21 +08:00
}
NSLog(@"[Recv] --- Message Raw Attach Content: %@, %@, %ld", @(message.senderClientType), message.rawAttachContent, (long)message.messageType);
2025-01-07 20:07:54 +08:00
// / TurboModeStateManager
NSString *currentRoomIdForTurbo = @(self.roomInfo.roomId).stringValue;
BOOL containsAllRoomMsg = [message.rawAttachContent containsString:@"\"allRoomMsg\":1"]; //
BOOL containsAllGameMsg = [message.rawAttachContent containsString:@"\"allGameMsg\":1"]; //
if (containsAllRoomMsg || containsAllGameMsg) {
BOOL allowGiftScreen = [[TurboModeStateManager sharedManager] isGlobalGiftScreenEnabledForRoom:currentRoomIdForTurbo];
BOOL allowGameScreen = [[TurboModeStateManager sharedManager] isGlobalGameScreenEnabledForRoom:currentRoomIdForTurbo];
if ((containsAllRoomMsg && !allowGiftScreen) || (containsAllGameMsg && !allowGameScreen)) {
NSLog(@"[Recv] ⛔️ 按 TurboMode 屏蔽全服飘屏 | gift=%@ game=%@ | roomId=%@",
allowGiftScreen ? @"ON" : @"OFF",
allowGameScreen ? @"ON" : @"OFF",
currentRoomIdForTurbo);
continue;
}
}
2023-10-30 14:38:33 +08:00
if (message.messageType == NIMMessageTypeNotification) {
[self handleNIMNotificationTypeMessage:message];
2023-10-30 14:38:33 +08:00
} else if (message.messageType == NIMMessageTypeCustom) {
[self handleNimCustomTypeMessage:message];
} else if(message.messageType == NIMMessageTypeText) {
[self.messageContainerView handleNIMTextMessage:message];
[self.littleGameView handleNIMTextMessage:message];
} else if(message.messageType == NIMMessageTypeTip) {
[self.messageContainerView handleNIMTextMessage:message];
}else if(message.messageType == NIMMessageTypeImage){
[self.messageContainerView handleNIMImageMessage:message];
}
}
}
- (void)handleNIMNotificationTypeMessage:(NIMMessage *)message {
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
if (![notiMsg.content isKindOfClass:[NIMChatroomNotificationContent class]]) {
// content
return;
}
NSInteger onLineNumber = self.roomInfo.onlineNum;
switch (content.eventType) {
case NIMChatroomEventTypeInfoUpdated: //
{
NSDictionary *data = [content.notifyExt toJSONObject];
[self handleSwitchRoomType:data];
}
break;
case NIMChatroomEventTypeEnter:
{
if (content.source.userId.integerValue == [AccountInfoStorage instance].getUid.integerValue){
[self.presenter getKickUserListWithRoomUid:@(self.roomInfo.uid).stringValue];
}
if (content.source.userId.integerValue != [AccountInfoStorage instance].getUid.integerValue && self.userInfo.platformRole != 1) {
onLineNumber += 1;
}else {
///
[self userEnterRoomSuccess];
///
[self.sideMenu onRoomUpdate];
[self.menuContainerView onRoomUpdate];
}
break;
}
case NIMChatroomEventTypeAddBlack:
case NIMChatroomEventTypeKicked:
case NIMChatroomEventTypeExit:
onLineNumber -= 1;
// 🔧 退CPCP SVGA
if (content.source && content.source.userId.length > 0) {
NSInteger exitUid = content.source.userId.integerValue;
if (exitUid > 0) {
[self removeCpDataForUids:@[@(exitUid)]];
// CP
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (currentQueue) {
NSMutableArray<NSString *> *remainingUids = [NSMutableArray array];
for (NSString *positionKey in currentQueue.allKeys) {
MicroQueueModel *micModel = currentQueue[positionKey];
NSInteger uid = micModel.userInfo.uid;
if (uid > 0 && uid != exitUid) {
[remainingUids addObject:[NSString stringWithFormat:@"%ld", (long)uid]];
}
}
if (remainingUids.count > 0) {
[self.presenter micCpListByUidList:remainingUids];
}
}
[self drawSocialStageMidpointRects];
}
}
break;
case NIMChatroomEventTypeQueueChange: //
{
NSDictionary* data = (NSDictionary *)content.ext;
UserInfoModel* userInfo = [UserInfoModel modelWithJSON:[data objectForKey:NIMChatroomEventInfoQueueChangeItemValueKey]];
NSInteger changeType = [data[NIMChatroomEventInfoQueueChangeTypeKey] integerValue];
NSLog(@"🔧 接收到麦序变化通知:用户 %ld变化类型 %ld", (long)userInfo.uid, (long)changeType);
//
if (changeType == 1 && userInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
[self cancelRoomArrangeMic];
}
// CP
if (changeType == 1 && userInfo.uid != [AccountInfoStorage instance].getUid.integerValue) {
// 🔧
[self handleOtherUserMicChange:userInfo changeType:changeType];
} else {
// API
if (changeType == 2 && userInfo.uid != [AccountInfoStorage instance].getUid.integerValue) {
// 🔧 mic
[self handleOtherUserMicChange:userInfo changeType:changeType];
} else {
NSNumber *key = nil;
if ([notiMsg respondsToSelector:@selector(attachContent)]) {
NSString *jsonString = (NSString *)[notiMsg performSelector:@selector(attachContent)];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *attachData = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (!error) {
NSDictionary *dataDic = [attachData objectForKey:@"data"];
NSString *queueChange = [dataDic objectForKey:@"queueChange"];
if (![NSString isEmpty:queueChange]) {
jsonData = [queueChange dataUsingEncoding:NSUTF8StringEncoding];
NSError *e = nil;
NSDictionary *queueChangeData = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (!e) {
key = [queueChangeData objectForKey:@"key"];
}
}
}
}
if (key) {
// key
NSInteger position = key.integerValue;
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (currentQueue) {
for (NSString *key in [currentQueue allKeys]) {
if (key.integerValue == position) {
MicroQueueModel *model = [currentQueue objectForKey:key];
if (changeType == 2) {
// mic
model.userInfo = nil;
} else {
// mic
model.userInfo = userInfo;
}
break;
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self handleMicChangeForCP:currentQueue];
});
}
} else {
//
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (currentQueue) {
[self handleMicChangeForCP:currentQueue];
}
});
}
}
}
}
break;
case NIMChatroomEventTypeAddManager: {
NIMChatroomNotificationMember *targets = [content.targets firstObject];
if (targets.userId.integerValue == self.userInfo.uid) {
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"1.0.34_text_15")];
}
}
break;
case NIMChatroomEventTypeRemoveManager: {
NIMChatroomNotificationMember *targets = [content.targets firstObject];
if (targets.userId.integerValue == self.userInfo.uid) {
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"1.0.34_text_16")];
}
}
break;
default:
break;
}
self.roomInfo.onlineNum = onLineNumber;
[self.functionView updateOnlineCount:[NSString stringWithFormat:@"%ld",onLineNumber] countList:@[] isUpdateCount:YES];
[self.roomHeaderView onRoomUpdate];
[self.stageView handleNIMNotificationMessage:message];
[self.animationView handleNIMNotificationMessage:message];
[self.messageContainerView handleNIMNotificationMessage:message];
[self.sideMenu handleNIMNotificationMessage:message];
[self.menuContainerView handleNIMNotificationMessage:message];
[self.functionView handleNIMNotificationMessage:message];
[self.littleGameView handleNIMNotificationMessage:message];
if([self.stageView findMicroViewByUid:@(self.userInfo.uid).stringValue] != nil){
[XPSkillCardPlayerManager shareInstance].isMineInMic = YES;
}else{
[XPSkillCardPlayerManager shareInstance].isMineInMic = NO;
};
}
- (void)handleSwitchRoomType:(NSDictionary *)data {
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];
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 __removeAllViews];
[self.view addSubview:self.backContainerView];
[self.view addSubview:self.stageView];
[self.view addSubview:self.messageContainerView];
[self.view addSubview:self.quickMessageContainerView];
[self.view addSubview:self.menuContainerView];
[self.view addSubview:self.sideMenu];
[self.view addSubview:self.roomHeaderView];
[self.view bringSubviewToFront:self.menuContainerView];
[self.view addSubview:self.functionView];
[self.view bringSubviewToFront:self.animationView];
[self initSubViewConstraints];
[self changeStageViewOnRoomUpdate];
[self.stageView onRoomUpdate];
[self.menuContainerView onRoomUpdate];
[self.functionView onRoomUpdate];
[self.sideMenu onRoomUpdate];
[self.messageContainerView onRoomUpdate];
[self.littleGameView onRoomUpdate];
} else {
if (self.roomInfo.type == RoomType_Anchor) {
[self changeStageViewOnAnchorRoom];
} else if (self.roomInfo.type == RoomType_20Mic) {
[self __layoutTwentyMicStage];
[self changeStageViewOnRoomUpdate];
[self.twentyMicStageView onRoomUpdate];
} else if (self.roomInfo.type == RoomType_19Mic) {
[self __layoutNineteenMicStage];
[self changeStageViewOnRoomUpdate];
[self.nineteenMicStageView onRoomUpdate];
} else if (self.roomInfo.type == RoomType_15Mic) {
[self __layoutFifteenMicStage];
[self changeStageViewOnRoomUpdate];
[self.fifteenMicStageView onRoomUpdate];
} else if (self.roomInfo.type == RoomType_10Mic) {
[self __layoutTenMicStage];
[self changeStageViewOnRoomUpdate];
[self.tenMicStageView onRoomUpdate];
} else {
[self changeStageViewOnRoomUpdate];
}
[self.stageView onRoomUpdate];
[self.menuContainerView onRoomUpdate];
[self.functionView onRoomUpdate];
[self.sideMenu onRoomUpdate];
[self.messageContainerView onRoomUpdate];
[self.littleGameView onRoomUpdate];
}
}
break;
}
}
- (void)handleNimCustomTypeMessage:(NIMMessage *)message {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel * attachment = (AttachmentModel *)obj.attachment;
[self.stageView handleNIMCustomMessage:message];
[self.animationView handleNIMCustomMessage:message];
[self.menuContainerView handleNIMCustomMessage:message];
[self.sideMenu handleNIMCustomMessage:message];
[self.functionView handleNIMCustomMessage:message];
[self.littleGameView handleNIMCustomMessage:message];
[self.messageContainerView handleNIMCustomMessage:message];
switch (attachment.first) {
case ClientMessage_Type:
switch (attachment.second) {
case ClientMessage_UpMic_Ask:
[self handleUpMicAsk:attachment];
break;
case ClientMessage_UpMic_Agree:
[self handleUpMicAgree:attachment];
break;
case ClientMessage_UpMic_Reject:
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"20.20.62_text_4")];
break;
}
break;
case CustomMessageType_First_Recharge_Reward:
switch (attachment.second) {
case Custom_Message_Sub_Room_First_Recharge_Reward:
self.userInfo.isFirstCharge = NO;
[self.menuContainerView onRoomUpdate];
[self.sideMenu onRoomUpdate];
break;
}
break;
case CustomMessageType_Update_RoomInfo:
switch (attachment.second) {
case 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];
2023-10-30 14:38:33 +08:00
}
break;
case Custom_Message_Sub_Update_RoomInfo_AnimateEffect: {
2024-05-21 14:17:30 +08:00
NSDictionary * dic= attachment.data[@"roomInfo"];
if (dic.allKeys.count <=0) {
dic = attachment.data;
}
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic];
self.roomInfo.hasAnimationEffect = roomInfo.hasAnimationEffect;
[self.roomHeaderView onRoomUpdate];
}
break;
2024-05-21 14:17:30 +08:00
}
break;
case CustomMessageType_Queue:
switch (attachment.second) {
case Custom_Message_Sub_Queue_Invite: {
NSDictionary *dic = attachment.data;
NSString *uid = dic[@"uid"];
if (uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
[self cancelRoomArrangeMic];
}
2023-10-30 14:38:33 +08:00
}
break;
}
break;
case CustomMessageType_Hall_Super_Admin:
switch (attachment.second) {
case Custom_Message_Sub_Hall_Super_Admin_Kick_Manager_Out_Room: {
XPKickUserModel * userInfo = [XPKickUserModel modelWithJSON:attachment.data];
if (userInfo.targetUid == [AccountInfoStorage instance].getUid.integerValue) {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[XPRoomMiniManager shareManager] resetLocalMessage];
[self cancelRoomArrangeMic];
[[RtcManager instance] exitRoom];
[self.presenter reportUserOutRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
}
2023-10-30 14:38:33 +08:00
}
break;
}
break;
case CustomMessageType_RedPacket:
switch (attachment.second) {
case Custom_Message_Sub_RoomDiamandRedPacket: {
2023-10-30 14:38:33 +08:00
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
2023-10-26 15:20:20 +08:00
XPRedPacketModel *data = [XPRedPacketModel modelWithJSON:attachment.data];
2023-10-31 11:09:04 +08:00
view.delegate = self;
self.isShowRedPacket = YES;
2023-10-26 15:20:20 +08:00
data.validityType = 0;
data.kind = 1;
2023-10-27 16:17:05 +08:00
data.redEnvelopeId = attachment.data[@"redEnvelopeId"];
2023-10-30 14:38:33 +08:00
view.receiveModel = data;
for (UIView *subView in self.view.subviews) {
if([subView isKindOfClass:[XPReceiveRedPacketView class]]) {
view.alphaView.backgroundColor = [UIColor clearColor];
break;
}
}
[self.view addSubview:view];
[self.view bringSubviewToFront:view];
2024-12-20 19:05:43 +08:00
if(self.sideMenu.redPacketList == nil){
self.sideMenu.redPacketList = [NSMutableArray array];
2023-10-31 11:09:04 +08:00
}
2024-12-20 19:05:43 +08:00
NSMutableArray *redPacketList = [NSMutableArray arrayWithArray:self.sideMenu.redPacketList];
2023-10-31 11:09:04 +08:00
[redPacketList insertObject:data atIndex:0];
2024-12-20 19:05:43 +08:00
self.sideMenu.redPacketList = redPacketList;
}
break;
case Custom_Message_Sub_NewRoomDiamandRedPacket: {
2023-10-27 16:17:05 +08:00
XPRedPacketModel *curData = [XPRedPacketModel modelWithJSON:attachment.data];
2024-12-20 19:05:43 +08:00
if(self.sideMenu.redPacketList == nil){
self.sideMenu.redPacketList = [NSMutableArray array];
2023-10-31 18:02:12 +08:00
}
2024-12-20 19:05:43 +08:00
NSMutableArray *redPacketList = [NSMutableArray arrayWithArray:self.sideMenu.redPacketList];
2023-10-31 18:02:12 +08:00
[redPacketList insertObject:curData atIndex:0];
if(self.roomInfo.uid > 0 && curData.redEnvelopeNum.integerValue != redPacketList.count){
[self.presenter getRedPacket:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
return;
}
2023-10-27 16:17:05 +08:00
curData.redEnvelopeId = attachment.data[@"redEnvelopeId"];
if(curData.validityType == 0){
2023-10-26 15:20:20 +08:00
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
2023-10-31 11:09:04 +08:00
view.delegate = self;
self.isShowRedPacket = YES;
2023-10-27 16:17:05 +08:00
view.receiveModel = curData;
2023-10-26 15:20:20 +08:00
for (UIView *subView in self.view.subviews) {
if([subView isKindOfClass:[XPReceiveRedPacketView class]]) {
view.alphaView.backgroundColor = [UIColor clearColor];
break;
}
}
[self.view addSubview:view];
[self.view bringSubviewToFront:view];
}
2024-12-20 19:05:43 +08:00
self.sideMenu.redPacketList = redPacketList;
2023-10-26 15:20:20 +08:00
}
break;
}
break;
case CustomMessageType_Free_Gift_Star_Reset_Time:
switch (attachment.second) {
case Custom_Message_Sub_Free_Gift_Star_Reset_Time:
2023-09-22 15:26:19 +08:00
[self.presenter getFreeGiftData];
[[NSNotificationCenter defaultCenter]postNotificationName:kFreeGiftCountdownNotification object:nil userInfo:@{@"isReset":@(YES)}];
break;
case Custom_Message_Sub_Update_Gift_Information:
2023-09-22 15:26:19 +08:00
[self.presenter getFreeGiftData];
[[NSNotificationCenter defaultCenter]postNotificationName:kFreeGiftCountdownNotification object:nil userInfo:@{@"updateGiftInfo":attachment.data ?: @""}];
break;
}
break;
case CustomMessageType_Custom_Room_Background:
switch (attachment.second) {
case Custom_Message_Sub_Custom_Room_Background:
2024-11-06 17:57:32 +08:00
if ([attachment.data isKindOfClass:[NSDictionary class]]) {
NSString *url = attachment.data[@"url"];
if (![NSString isEmpty:url]) {
self.roomInfo.backPic = url;//@"https://tva1.moyu.im/mw600/9f0b0dd5ly1hvacrep5fhj20jg0t60w4.jpg";
[self.backContainerView onRoomUpdate];
}
}
break;
}
break;
case CustomMessageType_RoomLevel_Update:
switch (attachment.second) {
case Custom_Message_Sub_RoomLevel_Update:
if ([attachment.data isKindOfClass:[NSDictionary class]]) {
NSString *url = attachment.data[@"roomLevelIcon"];
NSNumber *roomLevel = attachment.data[@"roomLevel"];
if (![NSString isEmpty:url] && roomLevel.integerValue > self.roomHeaderView.tag) {
self.roomHeaderView.tag = roomLevel.integerValue;
[self.roomHeaderView updateLevel:url];
self.roomInfo.roomLevelIcon = url;
}
}
break;
2023-09-22 15:26:19 +08:00
}
break;
case MicRelationship_Type:
switch (attachment.second) {
case MicRelationship_CP:
[self handleMicRelationshipCPMessage:attachment];
break;
}
break;
case CustomMessageType_CP:
switch (attachment.second) {
case Custom_Message_Sub_CP_Binding:
case Custom_Message_Sub_CP_Upgrade:
[self handleCPBindingOrUpgradeMessage:attachment];
break;
}
break;
2023-10-30 14:38:33 +08:00
}
}
2023-07-14 18:50:55 +08:00
}
/// CP
- (void)handleCPBindingOrUpgradeMessage:(AttachmentModel *)attachment {
NSLog(@"🔧 处理CP绑定或升级消息first=%ld, second=%ld", (long)attachment.first, (long)attachment.second);
// CP
if (!self.hasCompletedRoomInitialization) {
NSLog(@"🔧 进房初始化中跳过CP绑定/升级处理");
return;
}
//
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (!currentQueue) {
NSLog(@"⚠️ 无法获取当前麦位队列跳过CP绑定/升级处理");
return;
}
// 使 MicMidpointRectManager CP/
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (manager) {
//
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
[manager handleCPBindingOrUpgradeMessageWithStageView:self.stageView
micCount:micCount
queue:currentQueue];
}
// CP API
[self callMicCpListByUidListWithQueue:currentQueue];
NSLog(@"✅ CP绑定/升级消息处理完成");
}
/// CP
- (void)handleMicChangeForCP:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSLog(@"🔧 处理麦位变化相关的CP逻辑");
//
[self updateCurrentUserMicStatus:queue];
// CP
if (self.hasCompletedRoomInitialization) {
// 使 MicMidpointRectManager CP
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (manager) {
//
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
[manager handleMicChangeForCPWithStageView:self.stageView
micCount:micCount
queue:queue
currentUserUid:[AccountInfoStorage instance].getUid.integerValue
roomType:self.roomInfo.type];
}
// CP API
[self callMicCpListByUidListWithQueue:queue];
// 🔧 19 mic
[self checkCentralPositionUserQualification:queue];
} else {
NSLog(@"🔧 进房初始化中跳过CP相关处理");
}
}
/// CP
- (void)handleMicRelationshipCPMessage:(AttachmentModel *)attachment {
NSLog(@"🔧 接收到麦位关系CP消息");
if (!attachment.data) {
NSLog(@"⚠️ 麦位关系CP消息data格式错误跳过处理");
return;
}
//
// 1) attachment.data NSDictionary key "data" NSString(JSON) NSArray
// 2) attachment.data NSArray
// 3) attachment.data NSString(JSON)
NSArray *dataArray = nil;
id raw = attachment.data;
if ([raw isKindOfClass:[NSDictionary class]]) {
id inner = [(NSDictionary *)raw objectForKey:@"data"];
if ([inner isKindOfClass:[NSArray class]]) {
dataArray = (NSArray *)inner;
} else if ([inner isKindOfClass:[NSString class]]) {
NSData *jsonData = [(NSString *)inner dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
NSError *err = nil;
id parsed = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&err];
if (!err && [parsed isKindOfClass:[NSArray class]]) {
dataArray = (NSArray *)parsed;
}
}
}
} else if ([raw isKindOfClass:[NSArray class]]) {
dataArray = (NSArray *)raw;
} else if ([raw isKindOfClass:[NSString class]]) {
NSData *jsonData = [(NSString *)raw dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
NSError *err = nil;
id parsed = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&err];
if (!err && [parsed isKindOfClass:[NSArray class]]) {
dataArray = (NSArray *)parsed;
}
}
}
if (![dataArray isKindOfClass:[NSArray class]]) {
NSLog(@"⚠️ 麦位关系CP消息未能解析为数组跳过处理");
return;
}
// CP
NSMutableArray<MicCpInfoModel *> *cpList = [NSMutableArray array];
for (id item in dataArray) {
if ([item isKindOfClass:[NSDictionary class]]) {
NSDictionary *cpDict = (NSDictionary *)item;
MicCpInfoModel *cpInfo = [[MicCpInfoModel alloc] init];
cpInfo.uid = [cpDict[@"uid"] integerValue];
cpInfo.loverUid = [cpDict[@"loverUid"] integerValue];
cpInfo.cpLevel = [cpDict[@"cpLevel"] integerValue];
[cpList addObject:cpInfo];
}
}
NSLog(@"🔧 麦位关系CP消息解析到 %lu 条CP数据", (unsigned long)cpList.count);
// CP
self.currentCpList = cpList.copy;
// 使 MicMidpointRectManager
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (manager) {
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
[manager updateCpListCacheAndRedraw:cpList
stageView:self.stageView
micCount:micCount
roomType:self.roomInfo.type];
} else {
// 退
[self drawSocialStageMidpointRects];
}
// 🔧 CP a-b b-c 10011CP
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (currentQueue) {
[self callMicCpListByUidListWithQueue:currentQueue];
}
NSLog(@"🔧 麦位关系CP消息处理完成");
}
- (void)handleUpMicAsk:(AttachmentModel *)attachment {
NSNumber *targetUid = [attachment.data objectForKey:@"targetUid"];
if (!targetUid || ![targetUid.stringValue isEqualToString:[AccountInfoStorage instance].getUid]) {
return;
}
//
if (self.upMicAskTimer) {
[self.upMicAskTimer invalidate];
self.upMicAskTimer = nil;
}
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = YMLocalizedString(@"20.20.62_text_1");
config.message = YMLocalizedString(@"20.20.62_text_2");
config.actionStyle = TTAlertActionBothStyle;
//
config.confirmButtonConfig.title = YMLocalizedString(@"MessageContentGuildView5");
config.cancelButtonConfig.title = YMLocalizedString(@"MessageContentGuildView4");
// clean
[TTPopup dismiss];
[self removeUpMicAskTimer];
@kWeakify(self);
[TTPopup alertWithConfig:config
confirmHandler:^{
@kStrongify(self);
//
[self removeUpMicAskTimer];
[self sendResponseUpMicMessage:attachment.data isAgree:YES];
} cancelHandler:^{
@kStrongify(self);
//
[self removeUpMicAskTimer];
[self sendResponseUpMicMessage:attachment.data isAgree:NO];
}];
// 10
self.upMicAskTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(autoDismissUpMicAskPopup)
userInfo:nil
repeats:NO];
}
- (void)removeUpMicAskTimer {
if (self.upMicAskTimer) {
[self.upMicAskTimer invalidate];
self.upMicAskTimer = nil;
}
}
/**
10
*/
- (void)autoDismissUpMicAskPopup {
//
[TTPopup dismiss];
//
if (self.upMicAskTimer) {
[self.upMicAskTimer invalidate];
self.upMicAskTimer = nil;
}
NSLog(@"⏰ 上麦请求弹窗已自动移除10秒超时");
}
- (void)handleUpMicAgree:(AttachmentModel *)attachment {
NSDictionary *originalData = attachment.data;
NSNumber *position = [originalData objectForKey:@"position"];
NSNumber *targetUid = [originalData objectForKey:@"targetUid"];
if (!position || !targetUid) {
return;
}
NSNumber *sendTime = [originalData objectForKey:@"sendTime"];
if (!sendTime) {
return;
} else {
int64_t nowMillis = (int64_t)([[NSDate date] timeIntervalSince1970] * 1000);
if (nowMillis - sendTime.doubleValue > 10 * 1000) {
// 10
return;
}
}
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
[dic setValue:position forKey:@"micPosition"];
[dic setValue:targetUid 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.roomInfo.roomId).stringValue
type:NIMSessionTypeChatroom];
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
}
- (void)sendResponseUpMicMessage:(NSDictionary *)originalData isAgree:(BOOL)isAgree {
AttachmentModel *attachment = [[AttachmentModel alloc] init];
attachment.first = ClientMessage_Type;
attachment.second = isAgree ? ClientMessage_UpMic_Agree : ClientMessage_UpMic_Reject;
attachment.data = originalData;
NSString *sessionID = @(self.roomInfo.roomId).stringValue;
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
message.messageObject = object;
NIMSessionType sessionType = NIMSessionTypeChatroom;
//
NIMSession *session = [NIMSession session:sessionID type:sessionType];
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session completion:^(NSError * _Nullable error) {
BOOL onMain = [NSThread isMainThread];
if (error) {
NSLog(@"[[Send] ❌ 发送失败 | sessionId=%@ | code=%ld | desc=%@ | main=%@ | ts=%.3f",
sessionID, (long)error.code, error.localizedDescription, onMain ? @"YES" : @"NO", [[NSDate date] timeIntervalSince1970]);
} else {
NSLog(@"[Send] ✅ 发送成功 | sessionId=%@ | main=%@ | ts=%.3f",
sessionID, onMain ? @"YES" : @"NO", [[NSDate date] timeIntervalSince1970]);
}
}];
}
2023-08-25 16:32:51 +08:00
#pragma mark - NIMBroadcastDelegate
// 广
- (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage{
if (broadcastMessage.content) {
NSDictionary *msgDictionary = [broadcastMessage.content toJSONObject];
AttachmentModel *attachment = [AttachmentModel modelWithJSON:msgDictionary[@"body"]];
2024-04-24 20:08:24 +08:00
NSString *partitionId = [NSString stringWithFormat:@"%@",attachment.data[@"partitionId"]];
if(![partitionId isEqualToString:self.getUserInfo.partitionId]){
return;
}
2023-08-31 17:08:59 +08:00
BOOL isHave = NO;
2024-05-16 14:30:21 +08:00
if(attachment.first == CustomMessageType_Look_Love && attachment.second == Custom_Message_Sub_Look_Love_InRoom_NeedAllMicSend){
2024-02-21 17:22:50 +08:00
isHave = YES;
2025-04-02 11:04:07 +08:00
}else if(attachment.first == CustomMessageType_Super_Gift &&
(attachment.second == Custom_Message_Sub_Super_Gift || attachment.second == Custom_Message_Sub_Super_Gift_Room_Message)){
2024-03-25 14:39:36 +08:00
isHave = YES;
2024-02-23 14:40:10 +08:00
}else if(attachment.first == CustomMessageType_General_Public_Screen && attachment.second == Custom_Message_Sub_General_Public_Screen_All_Room){
isHave = YES;
2023-09-26 17:57:39 +08:00
}else if (attachment.first == CustomMessageType_Tarot && (attachment.second == Custom_Message_Sub_Tarot_Advanced || attachment.second == Custom_Message_Sub_Tarot_Intermediate)){
isHave = YES;
2024-05-07 19:40:21 +08:00
}else if(attachment.first == CustomMessageType_LuckyBag && attachment.second == Custom_Message_Sub_Room_Gift_LuckBag_FullScree){
isHave = YES;
}
// TurboModeStateManager
if (isHave && (attachment.first == CustomMessageType_General_Public_Screen && attachment.second == Custom_Message_Sub_General_Public_Screen_All_Room)) {
NSString *currentRoomIdForTurbo = @(self.roomInfo.roomId).stringValue;
BOOL allowGiftScreen = [[TurboModeStateManager sharedManager] isGlobalGiftScreenEnabledForRoom:currentRoomIdForTurbo];
if (!allowGiftScreen) {
NSLog(@"[Broadcast] ⛔️ 按 TurboMode 屏蔽全服礼物飘屏 | roomId=%@", currentRoomIdForTurbo);
return;
}
}
2024-05-07 19:40:21 +08:00
if (attachment.first == CustomMessageType_RedPacket && attachment.second == Custom_Message_Sub_AllDiamandRedPacket) {
2023-10-31 11:09:04 +08:00
if(self.isShowRedPacket == YES)return;
2023-10-27 19:30:45 +08:00
XPRedPacketModel *data = [XPRedPacketModel modelWithDictionary:attachment.data];
data.validityType = 0;
data.kind = 1;
data.redEnvelopeId = attachment.data[@"redEnvelopeId"];
RoomInfoModel *roomInfo = self.roomInfo;
2023-10-30 14:38:33 +08:00
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
2023-10-31 11:09:04 +08:00
view.delegate = self;
self.isShowRedPacket = YES;
2023-10-27 19:30:45 +08:00
if (roomInfo.uid == data.roomUid.integerValue) {
view.inAllPacketRoom = YES;
} else {
view.inAllPacketRoom = NO;
}
2023-10-30 14:38:33 +08:00
view.receiveModel = data;
2023-10-27 19:30:45 +08:00
[self.view addSubview:view];
[self.view bringSubviewToFront:view];
2023-08-31 17:08:59 +08:00
}
if(isHave == NO)return;
2023-08-25 16:32:51 +08:00
attachment.isBroadcast = YES;
NIMMessage *message = [NIMMessage new];
NIMCustomObject *object = [NIMCustomObject new];
object.attachment = attachment;
message.messageObject = object;
[self.messageContainerView handleNIMTextMessage:message];
}
}
2023-07-14 18:50:55 +08:00
//
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error {
2023-10-30 14:38:33 +08:00
if (message.yidunAntiSpamRes) {
NSDictionary * spamRes = message.yidunAntiSpamRes.toJSONObject;
2024-07-06 16:36:47 +08:00
id spamResExt = ((NSString *)spamRes[@"ext"]).toJSONObject;
NSDictionary *antispamDic = nil;
if ([spamResExt isKindOfClass:[NSArray class]]) {
antispamDic = [spamResExt xpSafeObjectAtIndex:0];
} else if ([spamResExt isKindOfClass:[NSDictionary class]]) {
antispamDic = spamResExt[@"antispam"];
}
NSDictionary *realAntiDic = nil;
if ([[antispamDic allKeys] containsObject:@"antispam"]) {
realAntiDic = antispamDic[@"antispam"];;
} else {
realAntiDic = antispamDic;
}
if (realAntiDic) {
NSInteger suggestion = [realAntiDic[@"suggestion"] integerValue];
if (suggestion == 2) {
[self showErrorToast:YMLocalizedString(@"XPRoomViewController10")];
}
2023-10-30 14:38:33 +08:00
}
}
2024-07-06 16:36:47 +08:00
2024-07-15 11:17:04 +08:00
if (![message.session.sessionId isEqualToString:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]]) {
return;
}
2025-01-22 21:22:58 +08:00
if (error) {
NSLog(@"%@", error);
return;
};
2023-10-30 14:38:33 +08:00
if (message.messageType == NIMMessageTypeCustom) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel * attachment = (AttachmentModel *)obj.attachment;
[self.stageView handleNIMCustomMessage:message];
[self.animationView handleNIMCustomMessage:message];
[self.functionView handleNIMCustomMessage:message];
if (attachment.first == CustomMessageType_Update_RoomInfo && attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState) {
2024-05-22 12:06:48 +08:00
NSDictionary * dic= attachment.data[@"roomInfo"];
if (dic.allKeys.count <=0) {
dic = attachment.data;
}
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic];
2023-10-30 14:38:33 +08:00
self.roomInfo.isCloseScreen = roomInfo.isCloseScreen;
[self.menuContainerView onRoomUpdate];
2024-05-21 14:17:30 +08:00
}else if(attachment.first == CustomMessageType_Update_RoomInfo && attachment.second == Custom_Message_Sub_Update_RoomInfo_AnimateEffect){
NSDictionary * dic= attachment.data[@"roomInfo"];
if (dic.allKeys.count <= 0) {
dic = attachment.data;
}
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic];
self.roomInfo.hasAnimationEffect = roomInfo.hasAnimationEffect;
}
2024-05-22 19:36:51 +08:00
[self.roomHeaderView onRoomUpdate];
2023-10-30 14:38:33 +08:00
[self.messageContainerView handleNIMCustomMessage:message];
}
}else if(message.messageType == NIMMessageTypeText) {
[self.messageContainerView handleNIMTextMessage:message];;
}
2023-07-14 18:50:55 +08:00
}
#pragma mark - NIMLoginManagerDelegate
- (void)onKickout:(NIMLoginKickoutResult *)result {
// [self exitRoom];
2023-10-30 14:38:33 +08:00
[self dismissViewControllerAnimated:YES completion:nil];
2023-07-14 18:50:55 +08:00
}
2023-07-14 18:50:55 +08:00
#pragma mark - NIMConversationManagerDelegate
- (void)didAddRecentSession:(NIMRecentSession *)recentSession
2023-10-30 14:38:33 +08:00
totalUnreadCount:(NSInteger)totalUnreadCount {
[self.menuContainerView addNIMRecentSession:recentSession];
2023-07-14 18:50:55 +08:00
}
- (void)didUpdateRecentSession:(NIMRecentSession *)recentSession
2023-10-30 14:38:33 +08:00
totalUnreadCount:(NSInteger)totalUnreadCount {
[self.menuContainerView addNIMRecentSession:recentSession];
2023-07-14 18:50:55 +08:00
}
- (void)didRemoveRecentSession:(NIMRecentSession *)recentSession
2023-10-30 14:38:33 +08:00
totalUnreadCount:(NSInteger)totalUnreadCount {
[self.menuContainerView removeNIMRecentSession:recentSession];
2023-07-14 18:50:55 +08:00
}
#pragma mark - RoomDelegate
- (RoomInfoModel *)getRoomInfo {
2023-10-30 14:38:33 +08:00
return self.roomInfo;
2023-07-14 18:50:55 +08:00
}
- (UserInfoModel *)getUserInfo {
2023-10-30 14:38:33 +08:00
return self.userInfo;
2023-07-14 18:50:55 +08:00
}
- (BOOL)isManagerOrOwner {
return self.roomUid.integerValue == self.userInfo.uid ||
[self.superMangerList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"uid == %d", self.userInfo.uid]] > 0;
}
2024-04-30 19:30:11 +08:00
-(NSMutableArray *)getPlayList{
2024-12-20 19:05:43 +08:00
return self.sideMenu.playList;
2024-04-30 19:30:11 +08:00
}
-(NSMutableArray *)getLittleGameList {
2024-12-20 19:05:43 +08:00
return self.sideMenu.littleGameList;
}
2023-07-14 18:50:55 +08:00
- (void)exitRoom {
2025-02-28 19:04:09 +08:00
[XNDJTDDLoadingTool showLoading];
// 🔧 退
self.isExitingRoom = YES;
2024-10-17 16:05:02 +08:00
[XPSkillCardPlayerManager shareInstance].micState = MICState_None;
2025-02-28 19:04:09 +08:00
[self.stageView exitNIMRoom];
2023-10-30 14:38:33 +08:00
[self.menuContainerView menuResignFirstResponder];
2025-01-15 19:02:58 +08:00
[self.animationView resumeTimer];
2025-01-15 19:02:58 +08:00
2025-02-28 19:04:09 +08:00
switch (self.roomInfo.roomModeType) {
case RoomModeType_Open_Micro_Mode:
case RoomModeType_Open_Blind:
[self exitRoomAndCancelArrangeMic];
break;
case RoomModeType_Open_PK_Mode:
[self exitRoomWhenPKing];
break;
case RoomType_MiniGame:
[self exitRoomWhenPlayMiniGame];
break;
default:
[self exitRoomPage];
break;
}
}
2025-03-21 16:19:07 +08:00
- (BOOL)isSameRoom:(NSString *)targetUid {
return [self.roomUid isEqualToString:targetUid];
}
2025-02-28 19:04:09 +08:00
- (void)exitRoomAndCancelArrangeMic {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.roomInfo.uid];
NSString * uid = [AccountInfoStorage instance].getUid;
[Api getRoomArrangeMicList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
ArrangeMicModel * arrangeMicModel= [ArrangeMicModel modelWithJSON:data.data];
if (arrangeMicModel.myPos.intValue > 0) {
[TTPopup alertWithMessage:YMLocalizedString(@"XPRoomViewController11") confirmHandler:^{
__block NSString * grouptype = @"0";
if (self.roomInfo.roomModeType == RoomModeType_Open_Blind) {
2023-10-30 14:38:33 +08:00
[arrangeMicModel.queue enumerateObjectsUsingBlock:^(ArrangeMicUserModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
grouptype = [NSString stringWithFormat:@"%ld", obj.groupType];
*stop = YES;
}
}];
2025-02-28 19:04:09 +08:00
}
[Api cancelArrangeMic:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
2023-10-30 14:38:33 +08:00
2025-02-28 19:04:09 +08:00
} roomUid:roomUid operUid:uid groupType:grouptype];
[self exitRoomPage];
} cancelHandler:^{
}];
return;
}
}
[self exitRoomPage];
} roomUid:roomUid operUid:uid page:@"1" pageSize:@"50"];
}
- (void)exitRoomWhenPKing {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.roomInfo.uid];
NSString * uid = [AccountInfoStorage instance].getUid;
[Api getRoomPKUserList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
ArrangeMicModel * arrangeMicModel= [ArrangeMicModel modelWithJSON:data.data];
if (arrangeMicModel.myPos.intValue > 0) {
[TTPopup alertWithMessage:YMLocalizedString(@"XPRoomViewController11") confirmHandler:^{
__block NSString * grouptype = @"0";
[arrangeMicModel.queue enumerateObjectsUsingBlock:^(ArrangeMicUserModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
grouptype = [NSString stringWithFormat:@"%ld", obj.groupType];
*stop = YES;
}
2023-10-30 14:38:33 +08:00
}];
2025-02-28 19:04:09 +08:00
[Api cancelRoomPKArrangeMic:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
} roomUid:roomUid operUid:uid groupType:grouptype];
[self exitRoomPage];
} cancelHandler:^{
}];
return;
2023-10-30 14:38:33 +08:00
}
2023-09-01 14:29:14 +08:00
}
2025-02-28 19:04:09 +08:00
[self exitRoomPage];
} roomUid:roomUid operUid:uid page:@"1" pageSize:@"50"];
}
- (void)exitRoomWhenPlayMiniGame {
if ([self.littleGameView isInSudGame]) {
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.cancelButtonConfig.title = YMLocalizedString(@"XPRoomSettingInputView4");
config.confirmButtonConfig.title = YMLocalizedString(@"TTAlertConfig0");
config.message = YMLocalizedString(@"XPRoomViewController14");
@kWeakify(self);
[TTPopup alertWithConfig:config confirmHandler:^{ //
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@kStrongify(self);
[self exitRoomPage];
});
} cancelHandler:^{
}];
} else {
[self exitRoomPage];
2023-09-01 14:29:14 +08:00
}
2025-02-28 19:04:09 +08:00
}
- (void)exitRoomPage {
if (self.roomInfo.type == RoomType_MiniGame) {
2025-02-28 19:04:09 +08:00
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
2023-10-30 14:38:33 +08:00
}
2025-02-28 19:04:09 +08:00
[[XPRoomMiniManager shareManager] resetLocalMessage];
// 🔧 TRTC 退
2025-02-28 19:04:09 +08:00
[[RtcManager instance] exitRoom];
// 🔧 退
self.isExitingRoom = YES;
self.isViewActive = NO;
2025-02-28 19:04:09 +08:00
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[self.presenter reportUserOutRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
[self handleFirstOutRoom];
[self dismissViewControllerAnimated:YES completion:^{
[XNDJTDDLoadingTool hideHUD];
}];
2023-07-14 18:50:55 +08:00
}
- (void)miniRoom {
2023-09-22 15:26:19 +08:00
if(self.freeModel != nil){
[XPRoomMiniManager shareManager].curState = self.freeModel.curStage;
}
2024-10-15 20:56:25 +08:00
2023-09-01 14:29:14 +08:00
[self.menuContainerView menuResignFirstResponder];
2023-09-01 14:29:14 +08:00
NSDictionary *roomInfoDic = self.roomInfo.model2dictionary != nil ? self.roomInfo.model2dictionary : @{};
NSDictionary *userInfoDic = self.userInfo.model2dictionary != nil ? self.userInfo.model2dictionary : @{};
NSMutableDictionary *queueDic = self.getMicroQueue != nil ? self.getMicroQueue : [@{} mutableCopy];
if(self.roomInfo.type == RoomType_MiniGame) {
2023-10-30 14:38:33 +08:00
if ([self.littleGameView isInSudGame]) {
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.cancelButtonConfig.title = YMLocalizedString(@"XPRoomViewController15");
config.confirmButtonConfig.title = YMLocalizedString(@"XPRoomViewController16");
config.message = YMLocalizedString(@"XPRoomViewController17");
2024-12-03 17:40:29 +08:00
@kWeakify(self);
2023-10-30 14:38:33 +08:00
[TTPopup alertWithConfig:config confirmHandler:^{ //
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
2024-12-03 17:40:29 +08:00
@kStrongify(self);
2023-10-30 14:38:33 +08:00
[[XPRoomMiniManager shareManager] configRoomInfo:self.roomInfo];
[[XPRoomMiniManager shareManager] configUserInfo:self.userInfo];
[[XPRoomMiniManager shareManager] configCurrentMusic:self.functionView.getCurrentMusic isPlaying:self.functionView.isPlaying];
NSDictionary * dic = @{@"roomInfo":roomInfoDic, @"userInfo":userInfoDic, @"microQueue":queueDic};
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomMiniNotificationKey object:nil userInfo:dic];
[self.view endEditing:YES];
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
[self handleFirstOutRoom];
[self dismissViewControllerAnimated:YES completion:nil];
});
} cancelHandler:^{
}];
} else {
[[XPRoomMiniManager shareManager] configRoomInfo:self.roomInfo];
[[XPRoomMiniManager shareManager] configUserInfo:self.userInfo];
[[XPRoomMiniManager shareManager] configCurrentMusic:self.functionView.getCurrentMusic isPlaying:self.functionView.isPlaying];
NSDictionary * dic = @{@"roomInfo":roomInfoDic, @"userInfo":userInfoDic, @"microQueue":queueDic};
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomMiniNotificationKey object:nil userInfo:dic];
[self.view endEditing:YES];
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
[self handleFirstOutRoom];
[self dismissViewControllerAnimated:YES completion:nil];
}
2023-09-01 14:29:14 +08:00
}else {
[[XPRoomMiniManager shareManager] configRoomInfo:self.roomInfo];
[[XPRoomMiniManager shareManager] configUserInfo:self.userInfo];
[[XPRoomMiniManager shareManager] configCurrentMusic:self.functionView.getCurrentMusic isPlaying:self.functionView.isPlaying];
NSDictionary * dic = @{@"roomInfo":roomInfoDic, @"userInfo":userInfoDic, @"microQueue":queueDic};
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomMiniNotificationKey object:nil userInfo:dic];
[self.view endEditing:YES];
[self handleFirstOutRoom];
[self dismissViewControllerAnimated:YES completion:nil];
}
2023-07-14 18:50:55 +08:00
}
- (void)showPKPanel {
[self.functionView showPKPanelView];
}
2023-07-14 18:50:55 +08:00
- (UINavigationController *)getCurrentNav {
2023-10-30 14:38:33 +08:00
return self.navigationController;
2023-07-14 18:50:55 +08:00
}
2024-02-21 10:18:59 +08:00
-(UIView *)getSuperView{
return self.view;
}
2023-07-14 18:50:55 +08:00
- (NSMutableDictionary<NSString *,MicroQueueModel *> *)getMicroQueue {
2023-10-30 14:38:33 +08:00
return [self.stageView getMicroQueue];
2023-07-14 18:50:55 +08:00
}
- (NSArray *)getRoomSuperAdminList {
2023-10-30 14:38:33 +08:00
return self.superMangerList;
2023-07-14 18:50:55 +08:00
}
- (NSArray *)getRoomPKGroupTeamList {
2023-10-30 14:38:33 +08:00
return [self.functionView getRoomPKGroupTeamList];
2023-07-14 18:50:55 +08:00
}
- (BOOL)isRoomPKPlaying {
2023-10-30 14:38:33 +08:00
return [self.functionView isRoomPKPlaying];
2023-07-14 18:50:55 +08:00
}
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
2023-10-30 14:38:33 +08:00
[self.menuContainerView onMicroQueueUpdate:queue];
[self.functionView onRoomUpdate];
[self.functionView onMicroQueueUpdate:queue];
//
NSDictionary *currentStatus = [self getCurrentUserMicStatus:queue];
BOOL isOnMic = [currentStatus[@"isOnMic"] boolValue];
2023-10-30 14:38:33 +08:00
if (isOnMic) {
self.anchorScrollView.scrollEnabled = NO;
} else {
self.anchorScrollView.scrollEnabled = YES;
}
// 🔧 CP NIMChatroomEventTypeQueueChange
// UICP
2023-07-14 18:50:55 +08:00
}
- (CGPoint)animationPointAtStageViewByUid:(NSString *)uid {
2023-10-30 14:38:33 +08:00
return [self.stageView animationPointAtStageViewByUid:uid];
2023-07-14 18:50:55 +08:00
}
- (CGPoint)animationPointAtStageViewByIndex:(NSInteger)index {
return [self.stageView animationPointAtStageViewByIndex:index];
}
2024-10-10 20:16:23 +08:00
- (void)getRoomBoomInfoSuccess:(NSArray <BoomDetailModel*> *)models {
[[RoomBoomManager sharedManager] updateBoomDetailArray:models];
2024-12-20 19:05:43 +08:00
[self.sideMenu updateForBoomDetailArray:models];
2024-10-10 20:16:23 +08:00
}
- (void)getRoomBoomExplosionSuccess:(BoomInfoModel *)model {
[[RoomBoomManager sharedManager] receiveEnterRoomBoom:model];
2024-10-10 20:16:23 +08:00
}
/// CP API
- (void)handleMicCpListSuccess:(NSArray<MicCpInfoModel *> *)cpList {
NSLog(@"🔧 CP API成功回调接收到 %lu 条CP数据", (unsigned long)cpList.count);
self.currentCpList = cpList;
// 使 MicMidpointRectManager CP
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (manager) {
//
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
[manager updateCpListCacheAndRedraw:cpList
stageView:self.stageView
micCount:micCount
roomType:self.roomInfo.type];
}
// NIM message
if (self.currentUserMicStatusChanged) {
[self sendMicRelationshipNIMessage:cpList];
self.currentUserMicStatusChanged = NO; //
}
NSLog(@"🔧 CP API成功回调处理完成");
}
/// UIDCP
- (void)getMicCpListByRoomUidSuccess:(NSArray <MicCpInfoModel *> *)cpList {
NSLog(@"🔧 按房间UID获取CP列表成功接收到 %lu 条CP数据", (unsigned long)cpList.count);
[self handleMicCpListSuccess:cpList];
}
/// UIDCP
- (void)getMicCpListByUidListSuccess:(NSArray<MicCpInfoModel *> *)cpList {
NSLog(@"🔧 按用户UID列表获取CP列表成功接收到 %lu 条CP数据", (unsigned long)cpList.count);
[self handleMicCpListSuccess:cpList];
}
2023-07-14 18:50:55 +08:00
#pragma mark - 退
- (void)handleFirstOutRoom {
2023-10-30 14:38:33 +08:00
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults boolForKey:kHadQuitOtherRoomKey] && self.userInfo.uid != self.roomInfo.uid && self.userInfo.showLimitCharge) {
[defaults setBool:YES forKey:kHadQuitOtherRoomKey];
[defaults synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:kNewUserRechargeKey object:nil];
}
2023-07-14 18:50:55 +08:00
}
2023-09-01 14:29:14 +08:00
#pragma mark - XPRoomLittleGameContainerViewDelegate
- (void)hiddenSudGamePostionView {
[self.functionView hiddenSudGamePostionView];
}
2023-07-14 18:50:55 +08:00
#pragma mark - AnchorRoomScrollViewDelegate
- (void)anchorScrollViewScrollToNext:(AnchorRoomScrollView *)anchorScrollView {
2023-10-30 14:38:33 +08:00
if (!self) {
return;
}
[self.view endEditing:YES];
[self showAnchorLoading];
[self.presenter getCycleAnchorRoomList:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
2023-07-14 18:50:55 +08:00
}
- (void)anchorScrollViewScrollToPrevious:(AnchorRoomScrollView *)anchorScrollView {
2023-10-30 14:38:33 +08:00
if (!self || self.anchorRoomList.count <= 0) {
return;
}
[self.view endEditing:YES];
[self showAnchorLoading];
if (self.anchorIndex < self.anchorRoomList.count) {
NSString * roomUid = [self.anchorRoomList xpSafeObjectAtIndex:self.anchorIndex];
2023-10-30 14:38:33 +08:00
[self.presenter getCurrentRoomInfo:roomUid];
self.anchorIndex --;
}else {
[self showErrorToast:YMLocalizedString(@"XPRoomViewController13")];
self.anchorScrollView.contentOffset = CGPointMake(0, KScreenHeight);
}
2023-07-14 18:50:55 +08:00
}
#pragma mark - XPRoomSettingInputViewDelegate
///
- (void)xPRoomSettingInputView:(XPRoomSettingInputView *)view didClickConfirm:(NSString *)text type:(RoomSettingInputType)type {
2023-10-30 14:38:33 +08:00
NSString *pwdDes = [DESEncrypt encryptUseDES:text key:KeyWithType(KeyType_PasswordEncode)];
if ([pwdDes isEqualToString:self.roomInfo.roomPwd]) {
[TTPopup dismiss];
view.isPwdError = NO;
if (self.roomInfo.type == RoomType_Anchor) {
[self __removeAllViews];
2023-10-30 14:38:33 +08:00
if (!self.anchorScrollView.superview) {
[self.view insertSubview:self.anchorScrollView belowSubview:self.menuContainerView];
}
[self.anchorScrollView addSubview:self.backContainerView];
[self.anchorScrollView addSubview:self.stageView];
[self.anchorScrollView addSubview:self.messageContainerView];
[self.anchorScrollView addSubview:self.quickMessageContainerView];
2024-12-20 19:05:43 +08:00
[self.anchorScrollView addSubview:self.sideMenu];
2023-10-30 14:38:33 +08:00
[self.anchorScrollView addSubview:self.roomHeaderView];
if (!self.menuContainerView.superview) {
[self.view addSubview:self.menuContainerView];
}
[self.anchorScrollView addSubview:self.functionView];
2023-10-30 14:38:33 +08:00
[self.view bringSubviewToFront:self.animationView];
[self updateViewConstraintsOnAnchorRoom];
[self changeStageViewOnAnchorRoom];
[self.roomHeaderView onRoomEntered];
2024-12-20 19:05:43 +08:00
[self.sideMenu onRoomEntered];
2023-10-30 14:38:33 +08:00
2024-10-17 16:05:02 +08:00
2023-10-30 14:38:33 +08:00
[self.backContainerView onRoomEntered];
2023-09-01 14:29:14 +08:00
[self.littleGameView onRoomEntered];
2023-08-31 16:51:40 +08:00
[self.littleGameView onRoomEntered];
2023-10-30 14:38:33 +08:00
if ([XPRoomMiniManager shareManager].getRoomInfo.uid != self.roomUid.integerValue) {// 退
// 🔧
if (!self.isExitingRoom && self.isViewActive) {
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2023-10-30 14:38:33 +08:00
[self.functionView onRoomEntered];
[self.messageContainerView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomEntered];
2023-10-30 14:38:33 +08:00
} else {
//退
[self.stageView onRoomMiniEntered];
[self.messageContainerView onRoomMiniEntered];
[self.functionView onRoomMiniEntered];
[self.functionView onRoomEntered];
2024-10-17 16:05:02 +08:00
[self.menuContainerView onRoomMiniEntered];
// 🔧
[self initializeCurrentUserMicStatusForMiniEnter];
2023-10-30 14:38:33 +08:00
}
[[XPRoomMiniManager shareManager] configRoomInfo:nil];
[[XPRoomMiniManager shareManager] configUserInfo:nil];
[[XPRoomMiniManager shareManager] configCurrentMusic:nil isPlaying:NO];
} else {
[self.roomHeaderView onRoomEntered];
2024-12-20 19:05:43 +08:00
[self.sideMenu onRoomEntered];
2023-10-30 14:38:33 +08:00
[self.menuContainerView onRoomEntered];
[self changeStageViewOnRoomUpdate];
[self.backContainerView onRoomEntered];
2023-08-31 16:51:40 +08:00
[self.littleGameView onRoomEntered];
2023-10-30 14:38:33 +08:00
[self.functionView onRoomEntered];
// 🔧
if (!self.isExitingRoom && self.isViewActive) {
[self.presenter enterNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId] user:self.userInfo];
}
2023-10-30 14:38:33 +08:00
[self.messageContainerView onRoomEntered];
2023-09-01 14:29:14 +08:00
[self.littleGameView onRoomEntered];
2023-10-30 14:38:33 +08:00
[[XPRoomMiniManager shareManager] configRoomInfo:nil];
[[XPRoomMiniManager shareManager] configUserInfo:nil];
[[XPRoomMiniManager shareManager] configCurrentMusic:nil isPlaying:NO];
}
} else {
view.isPwdError = YES;
}
2023-07-14 18:50:55 +08:00
}
- (void)didClickCancel:(RoomSettingInputType)type {
2023-10-30 14:38:33 +08:00
if (type == RoomSettingInputType_Input_Pwd) {
[self enterRoomFail:0];
}
2023-07-14 18:50:55 +08:00
}
2024-05-11 10:21:48 +08:00
-(NSInteger)getPublicScreenType{
return self.messageContainerView.type;
}
2023-09-12 17:48:18 +08:00
- (void)displayMusicPanel {
[self.functionView showMusicPanel];
}
- (void)updateScreenMessageState:(BOOL)isClose {
self.roomInfo.isCloseScreen = isClose;
}
2023-09-12 17:48:18 +08:00
#pragma mark - XPFirstRechargeViewDelegate
2024-09-12 14:01:12 +08:00
-(void)rechargeHandle{}
2023-09-21 17:44:59 +08:00
-(void)contactCustomerService{
TTAlertConfig *config = [[TTAlertConfig alloc]init];
config.title = YMLocalizedString(@"XPIAPRechargeViewController7");
config.message = YMLocalizedString(@"XPIAPRechargeViewController8");
TTAlertButtonConfig *confirmButtonConfig = [[TTAlertButtonConfig alloc]init];
confirmButtonConfig.title = YMLocalizedString(@"XPIAPRechargeViewController9");
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x13E2F5),UIColorFromRGB(0x9DB4FF),UIColorFromRGB(0xCC67FF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(200, 200)];
confirmButtonConfig.backgroundColor = [UIColor colorWithPatternImage:image];
confirmButtonConfig.cornerRadius = 38/2;
config.confirmButtonConfig = confirmButtonConfig;
@kWeakify(self);
2023-09-21 17:44:59 +08:00
[TTPopup alertWithConfig:config confirmHandler:^{
@kStrongify(self);
2023-09-21 17:44:59 +08:00
[self requestContactCustomerService];
} cancelHandler:^{
}];
}
-(void)requestContactCustomerService{
[XNDJTDDLoadingTool showLoading];
[Api requestContactCustomerServiceCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
[XNDJTDDLoadingTool hideHUD];
if(code == 200){
NSString *uid = [NSString stringWithFormat:@"%@",data.data];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P];
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
[self.getCurrentNav pushViewController:sessionVC animated:YES];
});
}
}];
}
2023-07-14 18:50:55 +08:00
- (XPRoomBackContainerView *)backContainerView {
2023-10-30 14:38:33 +08:00
if (!_backContainerView) {
_backContainerView = [[XPRoomBackContainerView alloc] initWithdelegate:self];
}
return _backContainerView;
2023-07-14 18:50:55 +08:00
}
- (RoomHeaderView *)roomHeaderView {
2023-10-30 14:38:33 +08:00
if (!_roomHeaderView) {
_roomHeaderView = [[RoomHeaderView alloc] initWithDelegate:self];
}
return _roomHeaderView;
2023-07-14 18:50:55 +08:00
}
2024-05-11 10:21:48 +08:00
- (MsRoomMessageMainView *)messageContainerView {
2023-10-30 14:38:33 +08:00
if (!_messageContainerView) {
2024-05-11 10:21:48 +08:00
_messageContainerView = [[MsRoomMessageMainView alloc] initWithDelegate:self];
2023-10-30 14:38:33 +08:00
}
return _messageContainerView;
2023-07-14 18:50:55 +08:00
}
- (XPRoomQuickMessageContainView *)quickMessageContainerView {
2023-10-30 14:38:33 +08:00
if(!_quickMessageContainerView) {
_quickMessageContainerView = [[XPRoomQuickMessageContainView alloc] initWithDelegate:self];
}
return _quickMessageContainerView;
2023-07-14 18:50:55 +08:00
}
- (XPRoomMenuContainerView *)menuContainerView {
2023-10-30 14:38:33 +08:00
if (!_menuContainerView) {
_menuContainerView = [[XPRoomMenuContainerView alloc] initWithDelegate:self];
2024-10-12 19:30:41 +08:00
@kWeakify(self);
[_menuContainerView setUpdateHeight:^(CGFloat height) {
@kStrongify(self);
[self.menuContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
if (iPhoneXSeries) {
make.bottom.mas_equalTo(self.view);
} else {
make.bottom.mas_equalTo(self.view).offset(-10);
}
2024-10-12 19:30:41 +08:00
make.height.mas_equalTo(height + kSafeAreaBottomHeight);
}];
}];
2023-10-30 14:38:33 +08:00
}
return _menuContainerView;
2023-07-14 18:50:55 +08:00
}
2024-12-20 19:05:43 +08:00
- (RoomSideMenu *)sideMenu {
if (!_sideMenu) {
_sideMenu = [[RoomSideMenu alloc] initWithDelegate:self];
2023-10-30 14:38:33 +08:00
}
2024-12-20 19:05:43 +08:00
return _sideMenu;
2023-07-14 18:50:55 +08:00
}
2025-01-15 19:02:58 +08:00
- (RoomAnimationView *)animationView {
2023-10-30 14:38:33 +08:00
if (!_animationView) {
2025-01-15 19:02:58 +08:00
_animationView = [[RoomAnimationView alloc] initWithHostDelegate:self];
2023-10-30 14:38:33 +08:00
}
return _animationView;
2023-07-14 18:50:55 +08:00
}
- (XPRoomFunctionContainerView *)functionView {
2023-10-30 14:38:33 +08:00
if (!_functionView) {
_functionView = [[XPRoomFunctionContainerView alloc] initWithDelegate:self];
2023-10-30 14:38:33 +08:00
}
return _functionView;
2023-07-14 18:50:55 +08:00
}
- (StageView *)stageView {
// 🔧 StageViewManager stageView
if (self.stageViewManager && self.stageViewManager.currentStageView) {
return self.stageViewManager.currentStageView;
}
// 🔧 StageViewManager SocialStageView
2023-10-30 14:38:33 +08:00
if (!_stageView) {
_stageView = [[SocialStageView alloc] initWithDelegate:self];
_stageView.alpha = 0;
NSLog(@"⚠️ 使用降级 stageView: SocialStageView");
2023-10-30 14:38:33 +08:00
}
return _stageView;
2023-07-14 18:50:55 +08:00
}
- (TenMicStageView *)tenMicStageView {
if (!_tenMicStageView) {
_tenMicStageView = [[TenMicStageView alloc] initWithDelegate:self];
}
return _tenMicStageView;
}
2024-12-16 19:41:23 +08:00
- (NineteenMicStageView *)nineteenMicStageView {
if (!_nineteenMicStageView) {
_nineteenMicStageView = [[NineteenMicStageView alloc] initWithDelegate:self];
}
return _nineteenMicStageView;
}
- (TwentyMicStageView *)twentyMicStageView {
if (!_twentyMicStageView) {
_twentyMicStageView = [[TwentyMicStageView alloc] initWithDelegate:self];
}
return _twentyMicStageView;
}
- (FifteenMicStageView *)fifteenMicStageView {
if (!_fifteenMicStageView) {
_fifteenMicStageView = [[FifteenMicStageView alloc] initWithDelegate:self];
}
return _fifteenMicStageView;
}
2023-09-01 14:29:14 +08:00
- (XPRoomLittleGameContainerView *)littleGameView {
if (!_littleGameView) {
_littleGameView = [[XPRoomLittleGameContainerView alloc] initWithDelegate:self];
_littleGameView.delegate = self;
}
return _littleGameView;
}
2023-07-14 18:50:55 +08:00
- (AnchorRoomScrollView *)anchorScrollView {
2023-10-30 14:38:33 +08:00
if (!_anchorScrollView) {
_anchorScrollView = [[AnchorRoomScrollView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_anchorScrollView.anchorScrollDelegate = self;
_anchorScrollView.hostDelegate = self;
if (@available(iOS 11.0, *)) {
_anchorScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
return _anchorScrollView;
2023-07-14 18:50:55 +08:00
}
- (AnchorRoomSrollTipView *)anchorScrollTipView {
2023-10-30 14:38:33 +08:00
if (!_anchorScrollTipView) {
_anchorScrollTipView = [[AnchorRoomSrollTipView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
}
return _anchorScrollTipView;
2023-07-14 18:50:55 +08:00
}
- (NSMutableArray<NSString *> *)anchorRoomList {
2023-10-30 14:38:33 +08:00
if (!_anchorRoomList) {
_anchorRoomList = [NSMutableArray array];
}
return _anchorRoomList;
2023-07-14 18:50:55 +08:00
}
2023-09-22 15:26:19 +08:00
-(XPFreeGiftsObtainView *)freeView{
if (!_freeView){
_freeView = [[XPFreeGiftsObtainView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
}
return _freeView;
}
2023-10-30 14:38:33 +08:00
- (PIRoomEnterRedPacketView *)redPacketView{
if(!_redPacketView){
_redPacketView = [[PIRoomEnterRedPacketView alloc]initWithFrame:CGRectZero];
_redPacketView.hidden = YES;
_redPacketView.isInRoom = YES;
_redPacketView.delegate = self;
}
return _redPacketView;
}
#pragma mark -
- (void)handlePublicRoomMessageForward:(NSNotification *)notification {
NIMMessage *message = notification.object;
if (![message isKindOfClass:[NIMMessage class]]) {
NSLog(@"XPRoomViewController: 收到无效的公共房间转发消息");
return;
}
//
if (!self.roomInfo || !self.messageContainerView) {
NSLog(@"XPRoomViewController: 房间未就绪,忽略公共房间转发消息");
return;
}
if ([message.messageObject isKindOfClass:[NIMNotificationObject class]]) {
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
if ([notiMsg respondsToSelector:@selector(content)]) {
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
if (content.eventType == NIMChatroomEventTypeExit || content.eventType == NIMChatroomEventTypeKicked) {
return;
}
}
}
switch (message.messageType) {
case NIMMessageTypeNotification:
break;
case NIMMessageTypeCustom:
[self handleNimCustomTypeMessage:message];
break;
case NIMMessageTypeText:
[self.messageContainerView handleNIMTextMessage:message];
[self.littleGameView handleNIMTextMessage:message];
break;
case NIMMessageTypeTip:
[self.messageContainerView handleNIMTextMessage:message];
break;
case NIMMessageTypeImage:
[self.messageContainerView handleNIMImageMessage:message];
break;
default:
break;
}
}
// StageViewManager
- (StageViewManager *)stageViewManager {
if (!_stageViewManager) {
_stageViewManager = [[StageViewManager alloc] init];
NSLog(@"✅ StageViewManager 懒加载初始化成功");
}
return _stageViewManager;
}
// StageViewManager
- (void)setupStageViewManager {
//
[self stageViewManager];
NSLog(@"✅ StageViewManager 设置完成");
}
// stageView
- (void)debugStageViewStatus {
NSLog(@"🔍 DEBUG: stageView 状态检查");
NSLog(@" - stageView: %@", self.stageView);
NSLog(@" - stageView.alpha: %.2f", self.stageView.alpha);
NSLog(@" - stageView.hidden: %@", self.stageView.hidden ? @"YES" : @"NO");
NSLog(@" - stageView.superview: %@", self.stageView.superview);
NSLog(@" - stageView.frame: %@", NSStringFromCGRect(self.stageView.frame));
NSLog(@" - stageView.class: %@", NSStringFromClass([self.stageView class]));
}
/// StageView
- (void)drawSocialStageMidpointRects {
if (!self.stageView) {
NSLog(@"🔧 当前没有 stageView跳过中点矩形绘制");
return;
}
// 使 MicMidpointRectManager
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (manager) {
//
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
[manager drawSocialStageMidpointRectsWithStageView:self.stageView
micCount:micCount
roomType:self.roomInfo.type];
} else {
NSLog(@"🔧 无法获取 midpointRectManager跳过中点矩形绘制");
}
}
/// CPAPI
- (void)callMicCpListByRoomUidAfterRoomEntered {
NSLog(@"🔧 进房成功:开始调用 micCpListByRoomUid API");
if (!self.roomInfo) {
NSLog(@"⚠️ 进房成功roomInfo为空跳过CP API调用");
return;
}
NSString *roomUid = [NSString stringWithFormat:@"%ld", (long)self.roomInfo.uid];
NSLog(@"🔧 进房成功房间UID: %@, 房间类型: %ld", roomUid, (long)self.roomInfo.type);
// micCpListByRoomUid
if ([self.presenter respondsToSelector:@selector(micCpListByRoomUid:)]) {
NSLog(@"🔧 进房成功:调用 micCpListByRoomUid: %@", roomUid);
[self.presenter micCpListByRoomUid:roomUid];
} else {
NSLog(@"⚠️ 进房成功presenter不支持micCpListByRoomUid方法");
}
NSLog(@"🔧 进房成功micCpListByRoomUid API调用完成");
}
/// uid3
- (NSArray<NSString *> *)getAllMicUserUidsWithQueue:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSMutableArray<NSString *> *micUserUids = [NSMutableArray array];
if (!self.roomInfo) {
NSLog(@"⚠️ 获取mic用户列表roomInfo为空");
return micUserUids;
}
//
NSInteger currentUserMicPosition = self.currentUserMicPosition;
if (currentUserMicPosition == -1) {
NSLog(@"🔧 获取mic用户列表当前用户不在麦上返回空数据");
// manager UID
NSInteger currentUid = [AccountInfoStorage instance].getUid.integerValue;
[self removeCpDataForUids:@[@(currentUid)]];
return micUserUids;
}
//
NSInteger maxMicCount = 0;
switch (self.roomInfo.type) {
case RoomType_Room:
maxMicCount = 9;
break;
case RoomType_10Mic:
maxMicCount = 10;
break;
case RoomType_15Mic:
maxMicCount = 15;
break;
case RoomType_19Mic:
maxMicCount = 19;
break;
case RoomType_20Mic:
maxMicCount = 20;
break;
default:
maxMicCount = 9; // 9
break;
}
// UID
NSInteger leftPosition = currentUserMicPosition - 1;
NSInteger rightPosition = currentUserMicPosition + 1;
//
if (leftPosition >= 0) {
NSString *leftPositionKey = [NSString stringWithFormat:@"%ld", (long)leftPosition];
MicroQueueModel *leftMicModel = queue[leftPositionKey];
if (leftMicModel && leftMicModel.userInfo && leftMicModel.userInfo.uid > 0) {
[micUserUids addObject:[NSString stringWithFormat:@"%ld", (long)leftMicModel.userInfo.uid]];
}
}
//
NSString *currentPositionKey = [NSString stringWithFormat:@"%ld", (long)currentUserMicPosition];
MicroQueueModel *currentMicModel = queue[currentPositionKey];
if (currentMicModel && currentMicModel.userInfo && currentMicModel.userInfo.uid > 0) {
[micUserUids addObject:[NSString stringWithFormat:@"%ld", (long)currentMicModel.userInfo.uid]];
}
//
if (rightPosition < maxMicCount) {
NSString *rightPositionKey = [NSString stringWithFormat:@"%ld", (long)rightPosition];
MicroQueueModel *rightMicModel = queue[rightPositionKey];
if (rightMicModel && rightMicModel.userInfo && rightMicModel.userInfo.uid > 0) {
[micUserUids addObject:[NSString stringWithFormat:@"%ld", (long)rightMicModel.userInfo.uid]];
}
}
// 🔧 使UIDNIM message
if (micUserUids.count == 1) {
NSLog(@"🔧 获取mic用户列表只有当前用户一个人但仍需发送NIM message");
// UIDCP APINIM message
}
NSLog(@"🔧 获取mic用户列表当前用户麦位 %ld找到 %lu 个相关用户: %@",
(long)currentUserMicPosition, (unsigned long)micUserUids.count, micUserUids);
return micUserUids;
}
/// mic
- (void)handleOtherUserMicChange:(UserInfoModel *)userInfo changeType:(NSInteger)changeType {
if (!self.stageView || ![self.stageView respondsToSelector:@selector(midpointRectManager)]) {
NSLog(@"🔧 处理其他用户mic变化stageView 不支持 midpointRectManager跳过处理");
return;
}
//
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (!currentQueue) {
NSLog(@"🔧 处理其他用户mic变化无法获取当前麦位队列跳过处理");
return;
}
// 使 MicMidpointRectManager mic
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (manager) {
//
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
[manager handleOtherUserMicChange:userInfo
changeType:changeType
stageView:self.stageView
micCount:micCount
queue:currentQueue
roomType:self.roomInfo.type];
}
// API
if (changeType == 2) { //
//
NSMutableArray<NSString *> *remainingUids = [NSMutableArray array];
for (NSString *positionKey in currentQueue.allKeys) {
MicroQueueModel *micModel = currentQueue[positionKey];
if (micModel && micModel.userInfo && micModel.userInfo.uid > 0) {
[remainingUids addObject:[NSString stringWithFormat:@"%ld", (long)micModel.userInfo.uid]];
}
}
// APICP
if (remainingUids.count > 0) {
[self.presenter micCpListByUidList:remainingUids];
}
//
[self drawSocialStageMidpointRects];
} else if (changeType == 1) { //
// CP API
[self callMicCpListByUidListWithQueue:currentQueue];
// CP
[self drawSocialStageMidpointRects];
}
}
/// CP
- (void)removeCpDataForUids:(NSArray<NSNumber *> *)uids {
if (!self.stageView || ![self.stageView respondsToSelector:@selector(midpointRectManager)]) {
NSLog(@"🔧 移除CP数据stageView 不支持 midpointRectManager跳过处理");
return;
}
if (uids.count == 0) {
NSLog(@"🔧 移除CP数据没有需要移除的用户跳过处理");
return;
}
// 使 MicMidpointRectManager CP
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (manager) {
[manager removeCpDataForUids:uids];
NSLog(@"🔧 移除CP数据完成UIDs %@", uids);
}
}
/// CP API
- (void)callMicCpListByUidListWithQueue:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSLog(@"🔧 调用CP API开始获取mic用户列表");
// queuemicuid
NSMutableArray<NSString *> *micUserUids = [NSMutableArray array];
if (queue) {
for (NSString *positionKey in queue.allKeys) {
MicroQueueModel *micModel = queue[positionKey];
if (micModel && micModel.userInfo && micModel.userInfo.uid > 0) {
[micUserUids addObject:[NSString stringWithFormat:@"%ld", (long)micModel.userInfo.uid]];
}
}
}
if (micUserUids.count == 0) {
NSLog(@"🔧 调用CP API没有用户在mic上跳过API调用");
return;
}
// micCpListByUidList
NSLog(@"🔧 调用CP APImicCpListByUidList: %@", micUserUids);
[self.presenter micCpListByUidList:micUserUids];
NSLog(@"🔧 调用CP API完成");
}
///
- (void)initializeCurrentUserMicStatus {
NSLog(@"🔧 初始化当前用户麦位状态");
//
self.currentUserMicStatusChanged = NO;
self.currentUserWasOnMic = NO;
self.currentUserMicPosition = -1;
self.hasCompletedRoomInitialization = NO; //
//
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (currentQueue && currentQueue.count > 0) {
NSDictionary *currentStatus = [self getCurrentUserMicStatus:currentQueue];
BOOL isOnMic = [currentStatus[@"isOnMic"] boolValue];
NSInteger micPosition = [currentStatus[@"micPosition"] integerValue];
self.currentUserWasOnMic = isOnMic;
self.currentUserMicPosition = micPosition;
NSLog(@"🔧 初始化完成 - 当前用户是否在麦上: %@, 麦位: %ld",
isOnMic ? @"是" : @"否", (long)micPosition);
} else {
NSLog(@"🔧 初始化完成 - 当前没有麦位数据");
}
// API
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.hasCompletedRoomInitialization = YES;
NSLog(@"🔧 进房初始化完成,后续麦位变动将触发 micCpListByUidList 调用");
});
}
///
- (void)initializeCurrentUserMicStatusForMiniEnter {
NSLog(@"🔧 最小化进房:初始化当前用户麦位状态");
//
self.currentUserMicStatusChanged = NO;
self.currentUserWasOnMic = NO;
self.currentUserMicPosition = -1;
self.hasCompletedRoomInitialization = NO; //
//
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
if (currentQueue && currentQueue.count > 0) {
NSDictionary *currentStatus = [self getCurrentUserMicStatus:currentQueue];
BOOL isOnMic = [currentStatus[@"isOnMic"] boolValue];
NSInteger micPosition = [currentStatus[@"micPosition"] integerValue];
self.currentUserWasOnMic = isOnMic;
self.currentUserMicPosition = micPosition;
NSLog(@"🔧 最小化进房初始化完成 - 当前用户是否在麦上: %@, 麦位: %ld",
isOnMic ? @"是" : @"否", (long)micPosition);
} else {
NSLog(@"🔧 最小化进房初始化完成 - 当前没有麦位数据");
}
//
self.hasCompletedRoomInitialization = YES;
NSLog(@"🔧 最小化进房初始化完成,后续麦位变动将触发 micCpListByUidList 调用");
}
///
- (NSDictionary *)getCurrentUserMicStatus:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSInteger currentUid = [AccountInfoStorage instance].getUid.integerValue;
BOOL isOnMic = NO;
NSInteger micPosition = -1;
for (NSString *position in queue.allKeys) {
MicroQueueModel *micModel = queue[position];
if (micModel.userInfo.uid > 0 && micModel.userInfo.uid == currentUid) {
isOnMic = YES;
micPosition = position.integerValue;
break;
}
}
return @{
@"isOnMic": @(isOnMic),
@"micPosition": @(micPosition)
};
}
///
- (BOOL)checkCurrentUserMicStatusChanged:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSDictionary *currentStatus = [self getCurrentUserMicStatus:queue];
BOOL currentUserOnMic = [currentStatus[@"isOnMic"] boolValue];
NSInteger currentMicPosition = [currentStatus[@"micPosition"] integerValue];
// 1
if (currentUserOnMic && !self.currentUserWasOnMic) {
NSLog(@"🔧 检测到当前用户刚刚上麦,麦位: %ld", (long)currentMicPosition);
return YES;
}
// 2
if (!currentUserOnMic && self.currentUserWasOnMic) {
NSLog(@"🔧 检测到当前用户刚刚下麦,之前麦位: %ld", (long)self.currentUserMicPosition);
return YES;
}
// 3
if (currentUserOnMic && self.currentUserWasOnMic &&
currentMicPosition != self.currentUserMicPosition) {
NSLog(@"🔧 检测到当前用户换麦位,从 %ld 换到 %ld",
(long)self.currentUserMicPosition, (long)currentMicPosition);
return YES;
}
return NO;
}
///
- (void)updateCurrentUserMicStatus:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSDictionary *currentStatus = [self getCurrentUserMicStatus:queue];
BOOL currentUserOnMic = [currentStatus[@"isOnMic"] boolValue];
NSInteger micPosition = [currentStatus[@"micPosition"] integerValue];
//
if ([self checkCurrentUserMicStatusChanged:queue]) {
self.currentUserMicStatusChanged = YES;
}
//
self.currentUserWasOnMic = currentUserOnMic;
self.currentUserMicPosition = micPosition;
}
/// NIM message
- (void)sendMicRelationshipNIMessage:(NSArray<MicCpInfoModel *> *)cpList {
NSLog(@"🔧 发送麦位关系 NIM messageCP数据条数: %ld当前用户麦位: %ld",
(long)cpList.count, (long)self.currentUserMicPosition);
if (!self.roomInfo) {
NSLog(@"⚠️ 发送麦位关系 NIM messageroomInfo为空跳过发送");
return;
}
// CP JSON string
NSMutableArray *cpDataArray = [NSMutableArray array];
for (MicCpInfoModel *cpInfo in cpList) {
NSDictionary *cpDict = @{
@"uid": @(cpInfo.uid),
@"loverUid": @(cpInfo.loverUid),
@"cpLevel": @(cpInfo.cpLevel)
};
[cpDataArray addObject:cpDict];
}
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:cpDataArray.copy
options:0
error:&error];
if (error) {
NSLog(@"❌ 发送麦位关系 NIM messageJSON序列化失败 - %@", error.localizedDescription);
return;
}
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"🔧 发送麦位关系 NIM messageJSON数据 - %@", jsonString);
NSDictionary *finalData = @{@"first": @(MicRelationship_Type),
@"second":@(MicRelationship_CP),
@"data":jsonString};
// AttachmentModel
AttachmentModel *attachment = [[AttachmentModel alloc] init];
attachment.first = MicRelationship_Type; // 1001
attachment.second = MicRelationship_CP; // 10011
attachment.data = finalData;
// NIM message
NIMMessage *message = [[NIMMessage alloc] init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
message.messageObject = object;
// remoteExt
UserInfoModel *userInfo = [self getUserInfo];
XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init];
extModel.androidBubbleUrl = userInfo.androidBubbleUrl;
extModel.iosBubbleUrl = userInfo.iosBubbleUrl;
extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel;
extModel.platformRole = userInfo.platformRole;
NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
message.remoteExt = remoteExt;
//
NSString *sessionID = [NSString stringWithFormat:@"%ld", self.roomInfo.roomId];
NIMSession *session = [NIMSession session:sessionID type:NIMSessionTypeChatroom];
//
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session completion:^(NSError * _Nullable error) {
if (error) {
NSLog(@"❌ 发送麦位关系 NIM message 失败 - %@", error.localizedDescription);
} else {
NSLog(@"✅ 发送麦位关系 NIM message 成功");
}
}];
}
/// MicMidpointRectManager
- (void)updateMicMidpointRectManagerCache:(NSArray<MicCpInfoModel *> *)cpList {
if (!self.stageView) {
NSLog(@"<22><> 更新缓存stageView 为空,跳过缓存更新");
return;
}
MicMidpointRectManager *midpointRectManager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (midpointRectManager) {
//
midpointRectManager.roomType = self.roomInfo.type;
// UID
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
NSArray<NSString *> *micUserUids = [self getAllMicUserUidsWithQueue:currentQueue];
// NSNumber
NSMutableArray<NSNumber *> *uidNumbers = [NSMutableArray array];
for (NSString *uidString in micUserUids) {
[uidNumbers addObject:@(uidString.integerValue)];
}
//
[midpointRectManager mergeCpListCache:cpList replaceForUids:uidNumbers];
NSLog(@"<22><> 更新缓存完成CP数据条数 %lu相关用户 %@",
(unsigned long)cpList.count, uidNumbers);
}
}
/// MicMidpointRectManager
- (void)updateMicMidpointRectManagerSnapshot {
if (!self.stageView) {
NSLog(@"<22><> 更新快照stageView 为空,跳过快照更新");
return;
}
//
NSInteger micCount = 0;
if (self.roomInfo) {
switch (self.roomInfo.type) {
case RoomType_Room: micCount = 9; break;
case RoomType_10Mic: micCount = 10; break;
case RoomType_15Mic: micCount = 15; break;
case RoomType_19Mic: micCount = 19; break;
case RoomType_20Mic: micCount = 20; break;
default: micCount = 9; break;
}
}
MicMidpointRectManager *midpointRectManager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
if (midpointRectManager) {
//
midpointRectManager.roomType = self.roomInfo.type;
[midpointRectManager rebuildMicSnapshotWithStageView:self.stageView micCount:micCount];
NSLog(@"🔧 更新麦位快照完成:麦位总数 %ld", (long)micCount);
}
}
///
- (NSInteger)getMicCountForRoomType:(NSInteger)roomType {
switch (roomType) {
case RoomType_Room: return 9;
case RoomType_10Mic: return 10;
case RoomType_15Mic: return 15;
case RoomType_19Mic: return 19;
case RoomType_20Mic: return 20;
default: return 9;
}
}
/// 19 micposition 6
- (void)checkCentralPositionUserQualification:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
// 19 mic
if (self.roomInfo.type != RoomType_19Mic) {
return;
}
NSLog(@"🔧 检查19 mic房间中央位置用户资格");
// position 6
MicroQueueModel *centralMicModel = nil;
for (NSString *positionKey in queue.allKeys) {
MicroQueueModel *micModel = queue[positionKey];
if (micModel.microState.position == 6) {
centralMicModel = micModel;
break;
}
}
//
if (centralMicModel && centralMicModel.userInfo) {
NSString *userId = [NSString stringWithFormat:@"%ld", (long)centralMicModel.userInfo.uid];
NSLog(@"🔧 中央位置用户:%@,检查资格", userId);
// BossAPI
[Api requestBossMicUp:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
NSLog(@"✅ 中央位置用户资格检查通过:%@", userId);
} else {
NSLog(@"❌ 中央位置用户资格检查失败:%@,错误:%@", userId, msg);
// mic
[self forceDownMicForUser:userId atPosition:6];
}
} roomUid:@(self.roomInfo.uid).stringValue uid:userId];
} else {
NSLog(@"🔧 中央位置无用户,无需检查");
}
}
/// mic
- (void)forceDownMicForUser:(NSString *)userId atPosition:(NSInteger)position {
NSLog(@"🔧 强制用户下mic%@,位置:%ld", userId, (long)position);
// 使 NIM API mic
NIMChatroomQueueRemoveRequest *request = [[NIMChatroomQueueRemoveRequest alloc] init];
request.key = [NSString stringWithFormat:@"%ld", (long)position];
request.roomId = @(self.roomInfo.roomId).stringValue;
[[NIMSDK sharedSDK].chatroomManager removeChatroomQueueObject:request completion:^(NSError * _Nullable error, NSDictionary<NSString *,NSString *> * _Nullable element) {
if (error) {
NSLog(@"❌ 强制下mic失败%@,错误:%@", userId, error.localizedDescription);
[XNDJTDDLoadingTool showErrorWithMessage:@"强制下mic失败"];
} else {
NSLog(@"✅ 强制下mic成功%@", userId);
[XNDJTDDLoadingTool showSuccessWithMessage:@"中央位置需要满足贡献值要求已自动下mic"];
}
}];
}
2023-07-14 18:50:55 +08:00
@end