// // KSEnterLiveroomManager.m // KulexiuForTeacher // // Created by Kyle on 2022/3/30. // #import "KSEnterLiveroomManager.h" #import "TXLiveRoomViewController.h" #import "LiveModuleService.h" // 用于记录防止重复点击的进入多个直播 static BOOL isRequestRoomMsg = NO; @implementation KSEnterLiveroomManager + (void)joinLiveWithRoomId:(NSString *)roomId inController:(CustomNavViewController *)navCtrl callback:(EnterCallback)callback { if (isRequestRoomMsg == YES) { return; } [LiveModuleService imLiveBroadcastRoomQueryRoomRequest:KS_GET roomId:roomId success:^(NSDictionary * _Nonnull dic) { if (callback) { callback(); } isRequestRoomMsg = NO; if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) { [self joinRoomWithMessage:[dic ks_dictionaryValueForKey:@"data"] controller:navCtrl]; } else { [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { isRequestRoomMsg = NO; if (callback) { callback(); } }]; } + (void)joinRoomWithMessage:(NSDictionary *)source controller:(CustomNavViewController *)navCtrl { TXLiveRoomViewController *liveVC = [[TXLiveRoomViewController alloc] init]; liveVC.roomId = [source ks_stringValueForKey:@"roomUid"]; liveVC.createrId = [source ks_stringValueForKey:@"speakerImUserId"]; liveVC.createrUserId = [source ks_stringValueForKey:@"speakerId"]; liveVC.createrName = [source ks_stringValueForKey:@"speakerName"]; liveVC.createrAvatal = [source ks_stringValueForKey:@"speakerPic"]; NSInteger lookCount = [source ks_integerValueForKey:@"lookNum"]; liveVC.blacklistFlag = [source ks_integerValueForKey:@"blacklistFlag"] == 1 ? YES : NO; liveVC.totalCount = lookCount; // 观看人数 // 是否需要横竖屏按钮 liveVC.needSwitchButton = [[source ks_stringValueForKey:@"os"] isEqualToString:@"mobile"] ? NO : YES; NSString *roomConfig = [source ks_stringValueForKey:@"roomConfig"]; NSData *jsonData = [roomConfig dataUsingEncoding:NSUTF8StringEncoding]; NSError *err; NSDictionary *configDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; // BOOL enableRecord = NO; // if (configDic) { // liveVC.enableChat = ![configDic ks_boolValueForKey:@"whether_chat"]; // liveVC.enableSeat = ![configDic ks_boolValueForKey:@"whether_mic"]; // liveVC.enableLike = ![configDic ks_boolValueForKey:@"whether_like"]; // liveVC.hideCartButton = [configDic ks_integerValueForKey:@"whether_view_shop_cart"] == 1 ? YES : NO; // // 是否录制 // enableRecord = [configDic ks_boolValueForKey:@"whether_video"]; // } liveVC.UserSig = [source ks_stringValueForKey:@"userSig"]; NSDictionary *liveRoomConfig = [source ks_dictionaryValueForKey:@"liveRoomConfig"]; if (liveRoomConfig) { liveVC.pushDomain = [liveRoomConfig ks_stringValueForKey:@"pushUrl"]; liveVC.pushUrlKey = [liveRoomConfig ks_stringValueForKey:@"pushSecret"]; liveVC.playDomain = [liveRoomConfig ks_stringValueForKey:@"playUrl"]; liveVC.liveUrlKey = [liveRoomConfig ks_stringValueForKey:@"playSecret"]; } CustomNavViewController *liveNav = [[CustomNavViewController alloc] initWithRootViewController:liveVC]; liveNav.modalPresentationStyle = UIModalPresentationFullScreen; if ([navCtrl.visibleViewController isKindOfClass:[TXLiveRoomViewController class]]) { TXLiveRoomViewController *ctrl = (TXLiveRoomViewController *)navCtrl.visibleViewController; [ctrl quitRoom]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [navCtrl.visibleViewController presentViewController:liveNav animated:YES completion:nil]; }); } else { [navCtrl.visibleViewController presentViewController:liveNav animated:YES completion:nil]; } } + (void)MBShowInWindow:(NSString *)str { [MBProgressHUD hideHUD]; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES]; hud.removeFromSuperViewOnHide =YES; hud.mode = MBProgressHUDModeText; hud.label.text = str; hud.label.numberOfLines = 0; hud.minSize = CGSizeMake(132.f, 60.0f); hud.label.textColor = [UIColor whiteColor]; hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor; hud.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8]; double hiddenTime = str.length > 15 ? 3.0f : 1.5f; [hud hideAnimated:YES afterDelay:hiddenTime]; } + (void)refreshClickStatus { isRequestRoomMsg = NO; } @end