BogoRoomUIViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. //
  2. // BogoRoomUIViewController.m
  3. // BuguLive
  4. //
  5. // Created by 志刚杨 on 2022/4/7.
  6. // Copyright © 2022 xfg. All rights reserved.
  7. //
  8. #import "BogoRoomUIViewController.h"
  9. #import "RoomLiveMicView.h"
  10. #import <YYKit/YYKit.h>
  11. #import "RoomModel.h"
  12. #import "VoiceHTTPManger.h"
  13. #import "RoomUserInfo.h"
  14. #import "BGRoomMicManageCell.h"
  15. #import "RoomUserListView.h"
  16. @interface BogoRoomUIViewController ()<RoomMicUserListViewDelegate,RoomLiveMicViewDelegate>
  17. @property(nonatomic, strong) VoiceHTTPManger *voiceApi;
  18. @end
  19. @implementation BogoRoomUIViewController
  20. #pragma mark - LifeCycle
  21. - (void)dealloc {
  22. [self removeNotificationObserver];
  23. }
  24. -(void)viewWillAppear:(BOOL)animated {
  25. [super viewWillAppear:animated];
  26. }
  27. - (void)viewWillDisappear:(BOOL)animated {
  28. [super viewWillDisappear:animated];
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. //设置导航栏
  33. [self setupNavBar];
  34. //设置view
  35. [self setupView];
  36. //请求数据
  37. [self requestData];
  38. //添加通知
  39. [self addNotificationObserver];
  40. }
  41. #pragma mark - View
  42. - (void)setupNavBar {
  43. }
  44. - (void)showMicView {
  45. __weak __typeof(self)weakSelf = self;
  46. // [self.voiceApi requestWheatListType:@"0" block:^(NSDictionary *selfPtr) {
  47. // NSMutableArray *dataArr = [NSMutableArray modelArrayWithClass:RoomUserInfo.class json:selfPtr[@"data"]];
  48. // weakSelf.userListView.dataArray = dataArr;
  49. weakSelf.userListView.voiceApi = self.voiceApi;
  50. [weakSelf.userListView show:weakSelf.supperView];
  51. // }];
  52. }
  53. - (void)setupView {
  54. self.view.userInteractionEnabled = YES;
  55. [self.view addSubview:self.roomTopView];
  56. [self.view addSubview:self.micView];
  57. UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
  58. [self.view addSubview:view];
  59. view.tag = 100000;
  60. [GlobalVariables sharedInstance].voiceGiftView = view;
  61. view.backgroundColor = kClearColor;
  62. view.userInteractionEnabled = NO;
  63. }
  64. - (BGVoiceRoomTopView *)roomTopView
  65. {
  66. if(!_roomTopView)
  67. {
  68. _roomTopView = [BGVoiceRoomTopView getView];
  69. _roomTopView.frame = CGRectMake(0, 0, self.view.width, 300);
  70. }
  71. return _roomTopView;
  72. }
  73. - (RoomLiveMicView *)micView{
  74. if (!_micView) {
  75. _micView = [[RoomLiveMicView alloc]initWithFrame:CGRectMake(0, kStatusBarHeight + NavigationBarHeight + 20, kScreenW, 330+30+20+20+115)];
  76. _micView.delegate = self;
  77. _micView.userInteractionEnabled = YES;
  78. }
  79. return _micView;
  80. }
  81. - (void)setLive_info:(CurrentLiveInfo *)live_info
  82. {
  83. _live_info = live_info;
  84. self.roomTopView.liveInfo = live_info;
  85. self.voiceApi = [[VoiceHTTPManger alloc] init];
  86. self.voiceApi.live_info = live_info;
  87. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  88. // 需要延迟执行的代码
  89. // [self.voiceApi requestBanVoice:@"" toUserID:[IMAPlatform sharedInstance].host.userId second:@"1" block:^(id selfPtr) {
  90. //
  91. // }];
  92. });
  93. }
  94. #pragma mark - RoomLiveMicViewDelegate
  95. - (void)micView:(RoomLiveMicView *)micView didClickLinkBtnIndex:(NSInteger)index{
  96. __weak __typeof(self)weakSelf = self;
  97. Wheat_Type_List *model = self.roomModel.wheat_type_list[index];
  98. //如果是个人就下麦
  99. if (self.live_info.user_id.intValue == [IMAPlatform sharedInstance].host.userId.intValue) {
  100. FDActionSheet *actionSheet = [[FDActionSheet alloc] initWithTitle:@"" message:@""];
  101. //如果是个人就下model
  102. if (model.even_wheat.user_id == [IMAPlatform sharedInstance].host.userId.intValue) {
  103. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"下麦") type:FDActionTypeDefault CallBack:^{
  104. [weakSelf.voiceApi requestUpdWheatUser:model.wheat_id toUserID:[IMAPlatform sharedInstance].host.userId status:@"3" block:^(id selfPtr) {
  105. // [weakSelf openAudio:NO];
  106. }];
  107. }]];
  108. //判断是否开麦
  109. if(model.even_wheat.is_ban_voice == 1)
  110. {
  111. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"打开麦克风") type:FDActionTypeDefault CallBack:^{
  112. [self.voiceApi requestBanVoice:@"" toUserID:[IMAPlatform sharedInstance].host.userId second:@"0" block:^(id selfPtr) {
  113. }];
  114. }]];
  115. }
  116. else
  117. {
  118. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"关闭麦克风") type:FDActionTypeDefault CallBack:^{
  119. [self.voiceApi requestBanVoice:@"" toUserID:[IMAPlatform sharedInstance].host.userId second:@"1" block:^(id selfPtr) {
  120. }];
  121. }]];
  122. }
  123. } else {
  124. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"上麦") type:FDActionTypeDefault CallBack:^{
  125. [self requestApplyWheatWithId:model.wheat_id];
  126. }]];
  127. }
  128. //设置麦位
  129. if(model.type == 0)
  130. {
  131. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"设置申请上麦") type:FDActionTypeDefault CallBack:^{
  132. [weakSelf.voiceApi setWheatApplyTypeWheatId:model.wheat_id type:@"1" block:^(id selfPtr) {
  133. }];
  134. }]];
  135. }
  136. else if(model.type == 1)
  137. {
  138. [actionSheet addAction:[FDAction actionWithTitle:@"设置直接上麦" type:FDActionTypeDefault CallBack:^{
  139. [weakSelf.voiceApi setWheatApplyTypeWheatId:model.wheat_id type:@"0" block:^(id selfPtr) {
  140. }];
  141. }]];
  142. }
  143. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"取消") type:FDActionTypeCancel CallBack:^{
  144. }]];
  145. [actionSheet show:[UIApplication sharedApplication].keyWindow];
  146. } else {
  147. //如果是自己或者管理员的
  148. [self requestApplyWheatWithId:model.wheat_id];
  149. }
  150. }
  151. - (void)micViewdidClickRoomTrueLove
  152. {
  153. NSLog(@"点击了真爱榜单");
  154. NSString *tmpUrlStr = [NSString stringWithFormat:@"%@&room_id=%@&to_uid=%@",[GlobalVariables sharedInstance].appModel.h5_url.video_ranking_url,self.live_info.room_id,self.live_info.user_id];
  155. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:tmpUrlStr isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  156. if (@available(iOS 15.0, *)) {
  157. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  158. appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
  159. appearance.backgroundColor = kWhiteColor;
  160. self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
  161. }
  162. [self.navigationController pushViewController:tmpController animated:NO];
  163. // [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  164. // video_ranking_url
  165. }
  166. - (void)requestApplyWheatWithId:(NSString *)id {
  167. [self.voiceApi requestApplyWheat:id block:^(NSDictionary *selfPtr) {
  168. }];
  169. }
  170. //- (void)openAudio:(BOOL)isOpen {
  171. // if([self.delegate respondsToSelector:@selector(needOpenRTCAudio:)])
  172. // {
  173. // [self.delegate needOpenRTCAudio:isOpen];
  174. // }
  175. //}
  176. - (void)micView:(RoomLiveMicView *)micView didClickNumberBtn:(UIButton *)sender
  177. {
  178. RoomUserListView *listView = [[RoomUserListView alloc] initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH/2)];
  179. // listView.frame =
  180. listView.room_id = self.live_info.room_id;
  181. [listView show:self.view.superview];
  182. listView.delegate = self;
  183. }
  184. - (void)listView:(RoomUserListView *)listView didSelectUser:(RoomUserInfo *)user
  185. {
  186. UserModel *userModel = [[UserModel alloc]init];
  187. userModel.user_id = user.user_id;
  188. userModel.nick_name = user.nick_name;
  189. userModel.head_image = user.head_image;
  190. userModel.user_level = user.level;
  191. [self.delegate clickUser:userModel];
  192. // [self getUserInfo:userModel];
  193. }
  194. //点击别人会调用
  195. - (void)micView:(RoomLiveMicView *)micView didClickUser:(Wheat_Type_List *)info{
  196. __weak __typeof(self)weakSelf = self;
  197. FDActionSheet *actionSheet = [[FDActionSheet alloc] initWithTitle:@"" message:@""];
  198. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"查看资料") type:FDActionTypeDefault CallBack:^{
  199. UserModel *model = [[UserModel alloc] init];
  200. model.user_id = StringFromInt(info.even_wheat.user_id);
  201. model.nick_name = info.even_wheat.nick_name;
  202. model.head_image = info.even_wheat.head_image;
  203. [self.delegate clickUser:model];
  204. // SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  205. // tmpController.user_id = [NSString stringWithFormat:@"%d",info.even_wheat.user_id];
  206. // tmpController.type = 0;
  207. // [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  208. }]];
  209. //如果是个人就下麦
  210. if (info.even_wheat.user_id == [IMAPlatform sharedInstance].host.userId.intValue) {
  211. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"下麦") type:FDActionTypeDefault CallBack:^{
  212. [weakSelf.voiceApi requestUpdWheatUser:info.wheat_id toUserID:[IMAPlatform sharedInstance].host.userId status:@"3" block:^(id selfPtr) {
  213. // [weakSelf openAudio:NO];
  214. }];
  215. }]];
  216. //判断是否开麦
  217. if(info.even_wheat.is_ban_voice == 1)
  218. {
  219. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"打开麦克风") type:FDActionTypeDefault CallBack:^{
  220. [self.voiceApi requestBanVoice:@"" toUserID:[IMAPlatform sharedInstance].host.userId second:@"0" block:^(id selfPtr) {
  221. }];
  222. }]];
  223. }
  224. else
  225. {
  226. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"关闭麦克风") type:FDActionTypeDefault CallBack:^{
  227. [self.voiceApi requestBanVoice:@"" toUserID:[IMAPlatform sharedInstance].host.userId second:@"1" block:^(id selfPtr) {
  228. }];
  229. }]];
  230. }
  231. } else {
  232. }
  233. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"取消") type:FDActionTypeCancel CallBack:^{
  234. }]];
  235. // [actionSheet show:[UIApplication sharedApplication].delegate.window];
  236. [actionSheet show:[UIApplication sharedApplication].keyWindow];
  237. }
  238. - (RoomMicUserListView *)userListView{
  239. if (!_userListView) {
  240. _userListView = [[RoomMicUserListView alloc]initWithFrame:CGRectMake(kScreenW, kScreenH - 300 - (IPHONE_X ? 34 : 0), self.view.width, 300 + (IPHONE_X ? 34 : 0))];
  241. _userListView.delegate = self;
  242. _userListView.vc = self;
  243. }
  244. return _userListView;
  245. }
  246. //抱上下麦
  247. - (void)userListView:(RoomMicUserListView *)userListView manageCell:(BGRoomMicManageCell *)messageCell didClickManageBtn:(UIButton *)sender{
  248. __weak __typeof(self)weakSelf = self;
  249. if(messageCell.type == RoomMicManageCellTypeApplyList)
  250. {
  251. NSString *type = @"0";
  252. if([sender.titleLabel.text isEqualToString:@"同意上麦"])
  253. {
  254. type = @"1";
  255. }
  256. else if([sender.titleLabel.text isEqualToString:@"拒绝上麦"])
  257. {
  258. type = @"2";
  259. }
  260. //同意上麦
  261. [self.voiceApi requestUpdWheatUser:@"" toUserID:messageCell.model.user_id status:type block:^(id selfPtr) {
  262. [weakSelf.userListView hide];
  263. }];
  264. }
  265. else if(messageCell.type == RoomMicManageCellTypeManageView)
  266. {
  267. if([sender.titleLabel.text isEqualToString:@"抱下麦"])
  268. {
  269. //抱下麦
  270. [self.voiceApi requestUpdWheatUser:@"" toUserID:messageCell.model.user_id status:@"3" block:^(id selfPtr) {
  271. [weakSelf.userListView hide];
  272. }];
  273. }
  274. else
  275. {
  276. //关麦
  277. NSString *status = @"1";
  278. if(sender.selected)
  279. {
  280. status = @"0";
  281. }
  282. [self.voiceApi requestBanVoice:@"" toUserID:messageCell.model.user_id second:status block:^(id selfPtr) {
  283. sender.selected = !sender.selected;
  284. }];
  285. }
  286. }
  287. }
  288. - (void)micView:(RoomLiveMicView *)micView didClickShareBtn:(QMUIButton *)sender{
  289. //
  290. // if (self.delegate && [self.delegate respondsToSelector:@selector(uicontroller:micView:didClickShareBtn:)]) {
  291. // [self.delegate uicontroller:self micView:micView didClickShareBtn:sender];
  292. // }
  293. //
  294. }
  295. - (void)micView:(RoomLiveMicView *)micView didClickAnnouncementBtn:(UIButton *)sender
  296. {
  297. NSLog(@"点击了公告");
  298. [self.delegate micView:micView didClickAnnouncementBtn:sender];
  299. }
  300. #pragma mark - Network
  301. - (void)requestData {
  302. // NSDictionary *dic = [self getJsonDataJsonname:@"room_json"];
  303. // RoomModel *model = [RoomModel mj_objectWithKeyValues:dic];
  304. //// RoomModel *model = [RoomModel]
  305. // NSLog(@"%@",dic);
  306. }
  307. - (void)setRoomModel:(RoomModel *)roomModel
  308. {
  309. _roomModel = roomModel;
  310. [self.micView setModel:roomModel];
  311. }
  312. -(id)getJsonDataJsonname:(NSString *)jsonname
  313. {
  314. NSString *path = [[NSBundle mainBundle] pathForResource:jsonname ofType:@"json"];
  315. NSData *jsonData = [[NSData alloc] initWithContentsOfFile:path];
  316. NSError *error;
  317. id jsonObj = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
  318. if (!jsonData || error) {
  319. //DLog(@"JSON解码失败");
  320. return nil;
  321. } else {
  322. return jsonObj;
  323. }
  324. }
  325. #pragma mark- Delegate
  326. #pragma mark UITableDatasource & UITableviewDelegate
  327. #pragma mark - Private
  328. #pragma mark - Event
  329. #pragma mark - Public
  330. #pragma mark - NSNotificationCenter
  331. - (void)addNotificationObserver {
  332. }
  333. - (void)removeNotificationObserver {
  334. }
  335. #pragma mark - Setter
  336. #pragma mark - Getter
  337. #pragma mark - MemoryWarning
  338. - (void)didReceiveMemoryWarning {
  339. }
  340. @end