KSEnterLiveroomManager.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // KSEnterLiveroomManager.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/30.
  6. //
  7. #import "KSEnterLiveroomManager.h"
  8. #import "TXLiveRoomViewController.h"
  9. #import "LiveModuleService.h"
  10. // 用于记录防止重复点击的进入多个直播
  11. static BOOL isRequestRoomMsg = NO;
  12. @implementation KSEnterLiveroomManager
  13. + (void)joinLiveWithRoomId:(NSString *)roomId inController:(CustomNavViewController *)navCtrl callback:(EnterCallback)callback {
  14. if (isRequestRoomMsg == YES) {
  15. return;
  16. }
  17. [LiveModuleService imLiveBroadcastRoomQueryRoomRequest:KS_GET roomId:roomId success:^(NSDictionary * _Nonnull dic) {
  18. if (callback) {
  19. callback();
  20. }
  21. isRequestRoomMsg = NO;
  22. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  23. [self joinRoomWithMessage:[dic ks_dictionaryValueForKey:@"data"] controller:navCtrl];
  24. }
  25. else {
  26. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  27. }
  28. } faliure:^(NSError * _Nonnull error) {
  29. isRequestRoomMsg = NO;
  30. if (callback) {
  31. callback();
  32. }
  33. }];
  34. }
  35. + (void)joinRoomWithMessage:(NSDictionary *)source controller:(CustomNavViewController *)navCtrl {
  36. TXLiveRoomViewController *liveVC = [[TXLiveRoomViewController alloc] init];
  37. liveVC.roomId = [source ks_stringValueForKey:@"roomUid"];
  38. liveVC.createrId = [source ks_stringValueForKey:@"speakerImUserId"];
  39. liveVC.createrUserId = [source ks_stringValueForKey:@"speakerId"];
  40. liveVC.createrName = [source ks_stringValueForKey:@"speakerName"];
  41. liveVC.createrAvatal = [source ks_stringValueForKey:@"speakerPic"];
  42. NSInteger lookCount = [source ks_integerValueForKey:@"lookNum"];
  43. liveVC.blacklistFlag = [source ks_integerValueForKey:@"blacklistFlag"] == 1 ? YES : NO;
  44. liveVC.totalCount = lookCount; // 观看人数
  45. // 是否需要横竖屏按钮
  46. liveVC.needSwitchButton = [[source ks_stringValueForKey:@"os"] isEqualToString:@"mobile"] ? NO : YES;
  47. NSString *roomConfig = [source ks_stringValueForKey:@"roomConfig"];
  48. NSData *jsonData = [roomConfig dataUsingEncoding:NSUTF8StringEncoding];
  49. NSError *err;
  50. NSDictionary *configDic = [NSJSONSerialization JSONObjectWithData:jsonData
  51. options:NSJSONReadingMutableContainers
  52. error:&err];
  53. // BOOL enableRecord = NO;
  54. // if (configDic) {
  55. // liveVC.enableChat = ![configDic ks_boolValueForKey:@"whether_chat"];
  56. // liveVC.enableSeat = ![configDic ks_boolValueForKey:@"whether_mic"];
  57. // liveVC.enableLike = ![configDic ks_boolValueForKey:@"whether_like"];
  58. // liveVC.hideCartButton = [configDic ks_integerValueForKey:@"whether_view_shop_cart"] == 1 ? YES : NO;
  59. // // 是否录制
  60. // enableRecord = [configDic ks_boolValueForKey:@"whether_video"];
  61. // }
  62. liveVC.UserSig = [source ks_stringValueForKey:@"userSig"];
  63. NSDictionary *liveRoomConfig = [source ks_dictionaryValueForKey:@"liveRoomConfig"];
  64. if (liveRoomConfig) {
  65. liveVC.pushDomain = [liveRoomConfig ks_stringValueForKey:@"pushUrl"];
  66. liveVC.pushUrlKey = [liveRoomConfig ks_stringValueForKey:@"pushSecret"];
  67. liveVC.playDomain = [liveRoomConfig ks_stringValueForKey:@"playUrl"];
  68. liveVC.liveUrlKey = [liveRoomConfig ks_stringValueForKey:@"playSecret"];
  69. }
  70. CustomNavViewController *liveNav = [[CustomNavViewController alloc] initWithRootViewController:liveVC];
  71. liveNav.modalPresentationStyle = UIModalPresentationFullScreen;
  72. if ([navCtrl.visibleViewController isKindOfClass:[TXLiveRoomViewController class]]) {
  73. TXLiveRoomViewController *ctrl = (TXLiveRoomViewController *)navCtrl.visibleViewController;
  74. [ctrl quitRoom];
  75. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  76. [navCtrl.visibleViewController presentViewController:liveNav animated:YES completion:nil];
  77. });
  78. }
  79. else {
  80. [navCtrl.visibleViewController presentViewController:liveNav animated:YES completion:nil];
  81. }
  82. }
  83. + (void)MBShowInWindow:(NSString *)str {
  84. [MBProgressHUD hideHUD];
  85. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  86. hud.removeFromSuperViewOnHide =YES;
  87. hud.mode = MBProgressHUDModeText;
  88. hud.label.text = str;
  89. hud.label.numberOfLines = 0;
  90. hud.minSize = CGSizeMake(132.f, 60.0f);
  91. hud.label.textColor = [UIColor whiteColor];
  92. hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
  93. hud.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
  94. double hiddenTime = str.length > 15 ? 3.0f : 1.5f;
  95. [hud hideAnimated:YES afterDelay:hiddenTime];
  96. }
  97. + (void)refreshClickStatus {
  98. isRequestRoomMsg = NO;
  99. }
  100. @end