YBLiveCtrlView.m 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. //
  2. // YBLiveCtrlView.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/11/29.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBLiveCtrlView.h"
  9. #import "YBLiveChatView.h"
  10. #import "YBUserListView.h"
  11. #import "UIImage+RKCircleImg.h"
  12. #import "YBLiveFucView.h"
  13. #import "YBUserEnterAnimation.h"
  14. #import "expensiveGiftV.h"
  15. #import "continueGift.h"
  16. #import "YBShareView.h"
  17. #import "YBOnSaleView.h"
  18. #import "YBGoodsListVC.h"
  19. #import "RKShowPaintedView.h"
  20. #import "SDCycleScrollView.h"
  21. #import "YBDayTaskView.h"
  22. #import "guardShowView.h"
  23. #import "YBTxLinkMicView.h"
  24. #import "YBAnchorOnline.h"
  25. #import "YBAnchorPKAlert.h"
  26. #import "YBAnchorPKView.h"
  27. #import "YBAlertActionSheet.h"
  28. #import "roomShowGoodsView.h"
  29. #import "RelationGoodsVC.h"
  30. #import "YBAnchorLinkInfo.h"
  31. @interface YBLiveCtrlView()<UIGestureRecognizerDelegate,haohuadelegate,SDCycleScrollViewDelegate,guardShowDelegate> {
  32. PublicView *_pubTiems; //开播倒计时
  33. int _liveTime; //直播时长
  34. expensiveGiftV *haohualiwuV; //豪华礼物
  35. continueGift *continueGifts; //连送礼物
  36. UIView *liansongliwubottomview;
  37. UIImageView *starImage;
  38. CGFloat starX;
  39. CGFloat starY;
  40. guardShowView *gShowView;
  41. BOOL _hostLinking; //主播连麦中【包含用户-主播、主播-主播连麦】
  42. roomShowGoodsView *roomGoodsV;
  43. }
  44. @property(nonatomic,strong)UIView *hostInfoView; //左上角主播信息
  45. @property(nonatomic,strong)UIButton *hostAvatarBtn; //主播头像
  46. @property(nonatomic,strong)UILabel *hostNameL; //主播昵称
  47. @property(nonatomic,strong)UILabel *hostIDL; //主播id
  48. @property(nonatomic,strong)UIButton *hostVotesBtn; //主播映票
  49. @property(nonatomic,strong)UIButton *hostGuardBtn; //守护
  50. @property(nonatomic,strong)UIButton *hostLiveTimeBtn; //主播直播时长
  51. @property(nonatomic,strong)NSArray *roomGameArray;
  52. @property(nonatomic,strong)SDCycleScrollView *roomGameCycle; //每日任务
  53. @property(nonatomic,strong)YBPageControl *roomGamePage;
  54. @property(nonatomic,strong)YBDayTaskView *dayTaskView; //每日任务
  55. @property(nonatomic,strong)YBUserListView *userListView; //用户列表
  56. @property(nonatomic,strong)YBLiveChatView *liveChatView; //公屏聊天
  57. @property(nonatomic,strong)YBUserEnterAnimation *userAnimation; //进场动画
  58. @property(nonatomic,strong)YBOnSaleView *onsaleView; //在售商品小窗
  59. @property(nonatomic,strong)RKShowPaintedView *paintedShowRegion;//手绘礼物显示区域
  60. @property(nonatomic,strong)UIButton *closeLiveBtn; //↓...底部功能键
  61. @property(nonatomic,strong)UIButton *msgBtn;
  62. @property(nonatomic,strong)UILabel *redPoint;
  63. @property(nonatomic,strong)UIButton *moreBtn;
  64. //@property(nonatomic,strong)UIButton *cartBtn;
  65. @property(nonatomic,strong)YBTxLinkMicView *linkMicView; //连麦窗口
  66. @property(nonatomic,strong)YBAnchorOnline *anchorOnlineView; //主播在线列表
  67. @property(nonatomic,strong)YBAnchorPKAlert *pkAlertView;
  68. @property(nonatomic,strong)YBAnchorPKView *pkView;
  69. @property(nonatomic,strong)YBAnchorLinkInfo *pkTohostInfoV;
  70. @property(nonatomic,strong)UIButton *pkFollowBtn;
  71. @property (nonatomic, strong) YBAlertActionSheet *actionSheet;
  72. @end
  73. @implementation YBLiveCtrlView
  74. - (instancetype)initWithFrame:(CGRect)frame {
  75. self = [super initWithFrame:frame];
  76. if (self) {
  77. _liveTime = 0;
  78. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGes)];
  79. tap.delegate = self;
  80. [self addGestureRecognizer:tap];
  81. //手绘礼物
  82. [self addSubview:self.paintedShowRegion];
  83. //连送礼物显示区域
  84. liansongliwubottomview = [[UIView alloc]init];
  85. liansongliwubottomview.userInteractionEnabled = NO;
  86. liansongliwubottomview.backgroundColor = UIColor.clearColor;
  87. [self addSubview:liansongliwubottomview];
  88. liansongliwubottomview.frame = CGRectMake(0, statusbarHeight + 200,_window_width,140);
  89. [self addSubview:self.hostInfoView];
  90. [self addSubview:self.hostVotesBtn];
  91. [self addSubview:self.hostGuardBtn];
  92. [self addSubview:self.hostLiveTimeBtn];
  93. [self addSubview:self.userListView];
  94. [self addSubview:self.liveChatView];
  95. [self addSubview:self.userAnimation];
  96. [self addSubview:self.botBtnFunView];
  97. [self addSubview:self.chatTool];
  98. self.roomGameArray = @[@"日任-房间"];
  99. if ([lagType isEqual:EN]) {
  100. self.roomGameArray = @[@"日任-房间_en"];
  101. }
  102. [self addSubview:self.roomGameCycle];
  103. [self addSubview:self.roomGamePage];
  104. if ([PublicObj isUp]) {
  105. self.roomGameCycle.hidden = self.roomGamePage.hidden = YES;
  106. }
  107. [self addSubview:self.linkCtrBtn];
  108. [self layoutIfNeeded];
  109. }
  110. return self;
  111. }
  112. - (void)layoutSubviews {
  113. [super layoutSubviews];
  114. [_hostInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.equalTo(self.mas_left).offset(11);
  116. make.top.equalTo(self.mas_top).offset(27+statusbarHeight);
  117. make.right.equalTo(_hostNameL.mas_right).offset(15);
  118. make.height.mas_equalTo(34);
  119. }];
  120. [_userListView mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.height.mas_equalTo(40);
  122. make.left.equalTo(_hostInfoView.mas_right).offset(5);
  123. make.centerY.equalTo(_hostInfoView.mas_centerY).offset(-5);
  124. make.right.equalTo(self.mas_right).offset(0);
  125. }];
  126. [_hostVotesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.left.equalTo(_hostInfoView);
  128. make.top.equalTo(_hostInfoView.mas_bottom).offset(8);
  129. make.height.mas_equalTo(22);
  130. }];
  131. [_hostGuardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.left.equalTo(_hostVotesBtn.mas_right).offset(5);
  133. make.height.centerY.equalTo(_hostVotesBtn);
  134. }];
  135. [_hostLiveTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.left.equalTo(_hostVotesBtn);
  137. make.top.equalTo(_hostVotesBtn.mas_bottom).offset(4);
  138. make.height.mas_equalTo(22);
  139. }];
  140. [_roomGameCycle mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.width.mas_equalTo(70);
  142. make.height.mas_equalTo(50);
  143. make.left.equalTo(_hostVotesBtn);
  144. make.top.equalTo(_hostVotesBtn.mas_bottom).offset(30);
  145. }];
  146. [_roomGamePage mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.height.mas_equalTo(10);
  148. if (@available(iOS 14.0,*)) {
  149. make.width.mas_equalTo(200);
  150. }else {
  151. make.width.mas_equalTo(80);
  152. }
  153. make.centerX.equalTo(_roomGameCycle);
  154. make.top.equalTo(_roomGameCycle.mas_bottom).offset(0);
  155. }];
  156. [_userAnimation mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.left.equalTo(self.mas_left).offset(10);
  158. make.bottom.equalTo(_liveChatView.mas_top).offset(-20);
  159. make.width.equalTo(self);
  160. make.height.mas_equalTo(20);
  161. }];
  162. CGFloat blodW = 50;
  163. if ([PublicObj isBlodText]) {
  164. blodW = 60;
  165. }
  166. [_linkCtrBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  167. make.width.height.mas_equalTo(blodW);
  168. make.bottom.equalTo(_botBtnFunView.mas_top).offset(-10);
  169. make.right.equalTo(self.mas_right).offset(-15);
  170. }];
  171. [_linkCtrBtn layoutIfNeeded];
  172. _linkCtrBtn = [PublicObj setUpImgDownText:_linkCtrBtn];
  173. [_hostGuardBtn layoutIfNeeded];
  174. [_hostGuardBtn setImageEdgeInsets:UIEdgeInsetsMake(0, _hostGuardBtn.titleLabel.size.width, 0, -_hostGuardBtn.titleLabel.size.width)];
  175. [_hostGuardBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -_hostGuardBtn.imageView.size.width-1, 0, _hostGuardBtn.imageView.size.width+1)];
  176. }
  177. #pragma mark - 点击事件
  178. -(void)clickHostAvatarBtn {
  179. if (self.liveCtrEvent) {
  180. self.liveCtrEvent(@"控制-信息卡", @{@"id":[Config getOwnID]});
  181. }
  182. }
  183. -(void)clickKeyBtn {
  184. [_chatTool.chatTF becomeFirstResponder];
  185. _botBtnFunView.hidden = YES;
  186. _chatTool.hidden = NO;
  187. }
  188. -(void)clikcCloseLiveBtn {
  189. if (self.liveCtrEvent) {
  190. self.liveCtrEvent(@"控制-关闭", @{});
  191. }
  192. }
  193. -(void)clikcMsgBtn {
  194. if (self.liveCtrEvent) {
  195. self.liveCtrEvent(@"控制-私信", @{});
  196. }
  197. }
  198. -(void)clikcMoreBtn {
  199. _moreBtn.selected = !_moreBtn.selected;
  200. YBWeakSelf;
  201. [YBLiveFucView showBotFunViewWithTorch:_isTorch Complete:^(NSString *eventType) {
  202. [weakSelf funViewCallBack:eventType];
  203. }];
  204. }
  205. -(void)clikcCartBtn {
  206. YBWeakSelf;
  207. if (roomGoodsV) {
  208. [roomGoodsV removeFromSuperview];
  209. roomGoodsV = nil;
  210. }
  211. roomGoodsV = [[roomShowGoodsView alloc]initWithFrom:YES andZhuboMsg:@{}];
  212. roomGoodsV.showEvent = ^(NSDictionary * _Nonnull infoDic, RelationGoodsModel * _Nonnull models) {
  213. NSLog(@"-----broadcast:%@", infoDic);
  214. NSDictionary *goodDic = @{@"name":models.name,
  215. @"old_price":[PublicObj checkNull: models.original_price]?@"":models.original_price,
  216. @"price":models.price,
  217. @"thumb":models.thumb,
  218. @"type":models.type,
  219. @"id":models.goodsid};
  220. if ([minstr([infoDic valueForKey:@"status"]) isEqual:@"1"]) {
  221. NSMutableDictionary *m_dic = [NSMutableDictionary dictionaryWithDictionary:goodDic];
  222. [m_dic addEntriesFromDictionary:@{@"action":@"1"}];
  223. weakSelf.liveCtrEvent(@"控制-在售",[NSDictionary dictionaryWithDictionary:m_dic]);
  224. }else{
  225. NSMutableDictionary *m_dic = [NSMutableDictionary dictionaryWithDictionary:goodDic];
  226. [m_dic addEntriesFromDictionary:@{@"action":@"0"}];
  227. weakSelf.liveCtrEvent(@"控制-在售",[NSDictionary dictionaryWithDictionary:m_dic]);
  228. }
  229. };
  230. [self addSubview:roomGoodsV];
  231. // _onsaleView = [YBOnSaleView showSaleWithAnchor:YES andAnchorID:[Config getOwnID]];
  232. // YBWeakSelf;
  233. // _onsaleView.onSaleEvent = ^(OnSaleType saleCtrEvent,NSDictionary *goodsDic) {
  234. // [weakSelf onSaleEvent:saleCtrEvent andGoodsDic:goodsDic];
  235. // };
  236. }
  237. -(void)onSaleEvent:(OnSaleType)ctrType andGoodsDic:(NSDictionary *)goodsDic{
  238. YBWeakSelf;
  239. if (ctrType == OnSaleType_addGoods) {
  240. //添加在售商品
  241. // _onsaleView.hidden = YES;
  242. // YBGoodsListVC *gVC = [[YBGoodsListVC alloc]init];
  243. // gVC.enterType = GoodsEnterType_Live;
  244. // gVC.touserID = [Config getOwnID];
  245. // gVC.refreshEvent = ^{
  246. // _onsaleView.hidden = NO;
  247. // [_onsaleView pullData];
  248. // };
  249. // [[YBBaseAppDelegate sharedAppDelegate]pushViewController:gVC animated:YES];
  250. YBWeakSelf;
  251. NSArray *arr = @[YZMsg(@"我的商品"),YZMsg(@"平台商品")];
  252. _actionSheet = [[YBAlertActionSheet alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) cancelTitle:YZMsg(@"取消") cancelColor:[UIColor blackColor] andRowHeight:50 andOtherTitle:arr];
  253. _actionSheet.btnEvent = ^(NSString *btnTitle) {
  254. NSString *titleStr = btnTitle;
  255. if ([titleStr isEqual:YZMsg(@"取消")]) {
  256. [weakSelf.actionSheet removeFromSuperview];
  257. weakSelf.actionSheet = nil;
  258. }else if ([titleStr isEqual:YZMsg(@"我的商品")]) {
  259. [weakSelf.actionSheet removeFromSuperview];
  260. weakSelf.actionSheet = nil;
  261. RelationGoodsVC *vc = [[RelationGoodsVC alloc]init];
  262. // vc.haveGoods = goodsList;
  263. [[YBBaseAppDelegate sharedAppDelegate] presentViewController:vc animated:YES completion:nil];
  264. }else if ([titleStr isEqual:YZMsg(@"平台商品")]) {
  265. [weakSelf.actionSheet removeFromSuperview];
  266. weakSelf.actionSheet = nil;
  267. RelationGoodsVC *vc = [[RelationGoodsVC alloc]init];
  268. vc.isOtherSale = YES;
  269. // vc.haveGoods = goodsList;
  270. [[YBBaseAppDelegate sharedAppDelegate] presentViewController:vc animated:YES completion:nil];
  271. }
  272. };
  273. [self addSubview:_actionSheet];
  274. }
  275. else if (ctrType == OnSaleType_Delete){
  276. //删除在售商品
  277. [MBProgressHUD showMessage:@""];
  278. [YBNetworking postWithUrl:@"Shop.setSale" Dic:@{@"goodsid":minstr([goodsDic valueForKey:@"id"]),@"issale":@"0"} Suc:^(int code, id info, NSString *msg) {
  279. [MBProgressHUD hideHUD];
  280. [MBProgressHUD showPop:msg];
  281. if (code == 0 && _onsaleView) {
  282. int live_isshow = [minstr([goodsDic valueForKey:@"live_isshow"]) intValue];
  283. if (live_isshow == 1) {
  284. //删除的商品正在展示,自己发送一个取消展示的socket
  285. NSMutableDictionary *m_dic = [NSMutableDictionary dictionaryWithDictionary:goodsDic];
  286. [m_dic addEntriesFromDictionary:@{@"action":@"0"}];
  287. weakSelf.liveCtrEvent(@"控制-在售",[NSDictionary dictionaryWithDictionary:m_dic]);
  288. }
  289. [_onsaleView pullData];
  290. }
  291. } Fail:^(id fail) {
  292. [MBProgressHUD hideHUD];
  293. }];
  294. }
  295. else if (ctrType == OnSaleType_Show || ctrType == OnSaleType_Hidden){
  296. //在用户端公屏聊天下方:展示-非展示
  297. NSString *showStr = (ctrType == OnSaleType_Show)?@"1":@"0";
  298. [MBProgressHUD showMessage:@""];
  299. [YBNetworking postWithUrl:@"Shop.setShowGoods" Dic:@{@"goodsid":minstr([goodsDic valueForKey:@"id"]),@"isshow":showStr} Suc:^(int code, id info, NSString *msg) {
  300. [MBProgressHUD hideHUD];
  301. [MBProgressHUD showPop:msg];
  302. if (code == 0) {
  303. [_onsaleView pullData];
  304. NSMutableDictionary *m_dic = [NSMutableDictionary dictionaryWithDictionary:goodsDic];
  305. [m_dic addEntriesFromDictionary:@{@"action":showStr}];
  306. weakSelf.liveCtrEvent(@"控制-在售",[NSDictionary dictionaryWithDictionary:m_dic]);
  307. }
  308. } Fail:^(id fail) {
  309. [MBProgressHUD hideHUD];
  310. }];
  311. }
  312. }
  313. #pragma mark - 连麦开始
  314. //用户-主播连麦
  315. -(void)clickLinkCtrBtn:(UIButton *)sender {
  316. [MBProgressHUD showMessage:@""];
  317. [YBNetworking postWithUrl:@"Linkmic.setMic" Dic:@{@"ismic":@(!sender.selected)} Suc:^(int code, id info, NSString *msg) {
  318. [MBProgressHUD hideHUD];
  319. [MBProgressHUD showPop:msg];
  320. if (code == 0) {
  321. sender.selected = !sender.selected;
  322. }
  323. } Fail:^(id fail) {
  324. [MBProgressHUD hideHUD];
  325. }];
  326. }
  327. /** socket展示连麦用户小窗 */
  328. -(void)socketShowLinkUserPop:(NSDictionary *)linkDic;{
  329. NSDictionary *subDic = @{@"userid":minstr([linkDic valueForKey:@"uid"]),
  330. @"uname":minstr([linkDic valueForKey:@"uname"]),
  331. @"playurl":minstr([linkDic valueForKey:@"playurl"]),
  332. @"pushurl":@"0",
  333. };
  334. [self createLinkMicView:subDic andHostToHost:NO];
  335. }
  336. /** socket连麦用户挂断 */
  337. -(void)socketLinkUserDisconnect:(NSDictionary *)linkDic; {
  338. //混流
  339. NSDictionary *mixDic = @{@"selfUrl":_liveHostUrl,@"otherUrl":@""};
  340. [_linkMicView linkMicMixStream:mixDic andHostToHost:_linkMicView.isHostToHost];
  341. [self destroyLinkMicView];
  342. }
  343. //主播-主播连麦
  344. -(void)showAnchorOnlineList {
  345. [self destroyAnchorOnlineList];
  346. _anchorOnlineView = [YBAnchorOnline showAnchorListOnView:self];
  347. YBWeakSelf;
  348. _anchorOnlineView.anchorListEvent = ^(AnchorListType callBackType,NSDictionary *otherInfo, NSDictionary *myInfo) {
  349. [weakSelf anchorOnlineViewBack:callBackType andOtherInfo:otherInfo andMyInfo:myInfo];
  350. };
  351. _anchorOnlineView.myStream = _liveStream;
  352. [_anchorOnlineView showOnlineView];
  353. }
  354. -(void)anchorOnlineViewBack:(AnchorListType)callBackType andOtherInfo:(NSDictionary *)otherInfo andMyInfo:(NSDictionary *)myInfo {
  355. [self destroyAnchorOnlineList];
  356. switch (callBackType) {
  357. case AnchorListType_StartLink:{
  358. //发起主播-主播连麦
  359. [MBProgressHUD showPop:YZMsg(@"连麦请求已发送")];
  360. if (self.liveCtrEvent) {
  361. self.liveCtrEvent(@"控制-主播和主播连麦请求", @{@"otherInfo":otherInfo,@"myInfo":myInfo});
  362. }
  363. }break;
  364. default:{
  365. }break;
  366. }
  367. }
  368. -(void)destroyAnchorOnlineList {
  369. if (_anchorOnlineView) {
  370. [_anchorOnlineView removeFromSuperview];
  371. _anchorOnlineView = nil;
  372. }
  373. }
  374. /** socekt主播-主播连麦成功 */
  375. -(void)socketLinkHostToHostSuc:(NSDictionary*)linkDic;{
  376. NSDictionary *subDic = @{@"userid":minstr([linkDic valueForKey:@"pkuid"]),
  377. @"uname":minstr([linkDic valueForKey:@"uname"]), //uname暂时未使用
  378. @"playurl":minstr([linkDic valueForKey:@"pkpull"]),
  379. @"pushurl":@"0",
  380. };
  381. [self createLinkMicView:subDic andHostToHost:YES];
  382. [self destroyAnchorOnlineList];
  383. _startPkBtn.hidden = NO;
  384. }
  385. /** socket主播-主播连麦挂断 */
  386. -(void)socketlinkHostToHostDisconnect:(NSDictionary *)linkDic{
  387. //混流
  388. NSDictionary *mixDic = @{@"selfUrl":_liveHostUrl,@"otherUrl":@""};
  389. [_linkMicView linkMicMixStream:mixDic andHostToHost:_linkMicView.isHostToHost];
  390. [self destroyLinkMicView];
  391. _startPkBtn.hidden = YES;
  392. [self destroyPkView];
  393. }
  394. //主播-用户、主播-主播连麦公共
  395. -(void)createLinkMicView:(NSDictionary *)linkDic andHostToHost:(BOOL)isHostToHost{
  396. [self destroyLinkMicView];
  397. _hostLinking = YES;
  398. _linkMicView = [YBTxLinkMicView createLinkMicViewOnSuper:self andHostToHost:isHostToHost];
  399. _linkMicView.linkDic = linkDic;
  400. [_linkMicView linkMicShowViewHaveCloseBtn:YES];
  401. YBWeakSelf;
  402. _linkMicView.linkMicEvent = ^(TxLinkEventType eventType, NSDictionary *eventDic) {
  403. [weakSelf linkMicViewEvent:eventType andDic:eventDic];
  404. };
  405. //混流
  406. NSDictionary *mixDic = @{@"selfUrl":_liveHostUrl,@"otherUrl":minstr([linkDic valueForKey:@"playurl"])};
  407. [_linkMicView linkMicMixStream:mixDic andHostToHost:isHostToHost];
  408. if (!isHostToHost) {
  409. //主播-用户连麦上报信息
  410. [_linkMicView linkMicUploadInfo:@{@"pull_url":minstr([linkDic valueForKey:@"playurl"]),@"touid":minstr([linkDic valueForKey:@"userid"])}];
  411. }
  412. }
  413. -(void)linkMicViewEvent:(TxLinkEventType)eventType andDic:(NSDictionary *)eventDic {
  414. switch (eventType) {
  415. case TxLinkEventType_LinkDisconnect:{
  416. //混流
  417. NSDictionary *mixDic = @{@"selfUrl":_liveHostUrl,@"otherUrl":@""};
  418. [_linkMicView linkMicMixStream:mixDic andHostToHost:_linkMicView.isHostToHost];
  419. _hostLinking = NO;
  420. //主播下麦用户 或者 主播下麦对方主播
  421. if (self.liveCtrEvent) {
  422. NSDictionary *passDic = @{@"uid":minstr([eventDic valueForKey:@"userid"]),
  423. @"uname":minstr([eventDic valueForKey:@"uname"]),
  424. @"hostToHost":@(_linkMicView.isHostToHost),};
  425. self.liveCtrEvent(@"控制-主播下麦他人",passDic);
  426. }
  427. }break;
  428. default:
  429. break;
  430. }
  431. }
  432. -(void)destroyLinkMicView {
  433. _hostLinking = NO;
  434. if (_linkMicView) {
  435. [_linkMicView linkMicViewDismiss];
  436. _linkMicView = nil;
  437. }
  438. }
  439. #pragma mark - 连麦结束
  440. /** 主播-主播:对方主播id */
  441. -(void)showToHostInfoWithId:(NSString *)toHostId;{
  442. [self destroyPkTohostInfo];
  443. _pkTohostInfoV = [YBAnchorLinkInfo showHostInfoWithSuperView:self];
  444. [_pkTohostInfoV reqToHostInfo:toHostId];
  445. YBWeakSelf;
  446. _pkTohostInfoV.attentEvent = ^(int isAttent) {
  447. weakSelf.pkFollowBtn.hidden = isAttent;
  448. };
  449. //遮罩【控制层级响应点击,实际UI显示在_pkTohostInfoV里的子视图】
  450. _pkFollowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  451. _pkFollowBtn.backgroundColor = UIColor.clearColor;
  452. [_pkFollowBtn addTarget:self action:@selector(clickPkFollow) forControlEvents:UIControlEventTouchUpInside];
  453. [self addSubview:_pkFollowBtn];
  454. [_pkFollowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  455. make.right.equalTo(self.mas_right);
  456. make.bottom.equalTo(_pkTohostInfoV.mas_bottom);
  457. make.width.height.mas_equalTo(40);
  458. }];
  459. }
  460. -(void)clickPkFollow {
  461. _pkFollowBtn.hidden = YES;
  462. [_pkTohostInfoV updateFollow];
  463. }
  464. -(void)destroyPkTohostInfo {
  465. if (_pkTohostInfoV) {
  466. [_pkTohostInfoV removeFromSuperview];
  467. _pkTohostInfoV = nil;
  468. [_pkFollowBtn removeFromSuperview];
  469. _pkFollowBtn = nil;
  470. }
  471. }
  472. #pragma mark - PK
  473. -(void)resetPKBtnFrame {
  474. [_startPkBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  475. make.width.mas_equalTo(60);
  476. make.height.mas_equalTo(30);
  477. make.centerY.equalTo(_botBtnFunView);
  478. if (!_cartBtn.hidden) {
  479. make.right.equalTo(_cartBtn.mas_left).offset(-10);
  480. }else{
  481. make.right.equalTo(_moreBtn.mas_left).offset(-10);
  482. }
  483. }];
  484. }
  485. -(void)clikcStartPkBtn {
  486. [self cancelPKAlert];
  487. _startPkBtn.hidden = YES;
  488. _pkAlertView = [[YBAnchorPKAlert alloc]initWithFrame:CGRectMake(0, 130+statusbarHeight+_window_width*2/6, _window_width, 70) andIsStart:YES];
  489. [[UIApplication sharedApplication].delegate.window addSubview:_pkAlertView];
  490. YBWeakSelf
  491. _pkAlertView.anchorPkEvent = ^(AnchorPkAlertType pkAlertType) {
  492. [weakSelf pkAlertCallBack:pkAlertType];
  493. };
  494. if (self.liveCtrEvent) {
  495. self.liveCtrEvent(@"控制-发起PK", @{});
  496. }
  497. [MBProgressHUD showError:YZMsg(@"PK请求已发送")];
  498. }
  499. -(void)pkAlertCallBack:(AnchorPkAlertType)pkAlertType {
  500. [self cancelPKAlert];
  501. }
  502. -(void)cancelPKAlert {
  503. if (_pkAlertView) {
  504. [_pkAlertView removeTimer];
  505. [_pkAlertView removeFromSuperview];
  506. _pkAlertView = nil;
  507. }
  508. }
  509. /** PK 开始 */
  510. -(void)socketLinkPKStart:(NSDictionary *)pkDic;{
  511. [self destroyPkView];
  512. _pkView = [[YBAnchorPKView alloc]initWithFrame:CGRectMake(0, 130+statusbarHeight, _window_width, _window_width*2/3+20) andTime:@"300"];
  513. YBWeakSelf;
  514. _pkView.pkViewEvent = ^{
  515. weakSelf.startPkBtn.hidden = NO;
  516. [weakSelf destroyPkView];
  517. };
  518. [self addSubview:_pkView];
  519. [self bringToFront];
  520. }
  521. ///层级关系处理
  522. -(void)bringToFront {
  523. [self bringSubviewToFront:_chatTool];
  524. [self bringSubviewToFront:_liveChatView];
  525. [self bringSubviewToFront:haohualiwuV];
  526. [self bringSubviewToFront:_paintedShowRegion];
  527. [self bringSubviewToFront:liansongliwubottomview];
  528. [self bringSubviewToFront:_userAnimation];
  529. }
  530. /** PK 结果 */
  531. -(void)socketLinkPKReult:(NSDictionary *)pkDic{
  532. int win;
  533. if ([minstr([pkDic valueForKey:@"win_uid"]) isEqual:@"0"]) {
  534. win = 0;
  535. }else if ([minstr([pkDic valueForKey:@"win_uid"]) isEqual:[Config getOwnID]]) {
  536. win = 1;
  537. }else{
  538. win = 2;
  539. }
  540. [_pkView showPkResult:pkDic andWin:win];
  541. }
  542. /** PK 进度 */
  543. -(void)socketLinkPKProgress:(NSDictionary *)pkDic;{
  544. NSString *blueNum;
  545. NSString *redNum;
  546. CGFloat progress = 0.0;
  547. if ([minstr([pkDic valueForKey:@"pkuid1"]) isEqual:[Config getOwnID]]) {
  548. blueNum = minstr([pkDic valueForKey:@"pktotal1"]);
  549. redNum = minstr([pkDic valueForKey:@"pktotal2"]);
  550. }else{
  551. redNum = minstr([pkDic valueForKey:@"pktotal1"]);
  552. blueNum = minstr([pkDic valueForKey:@"pktotal2"]);
  553. }
  554. if ([blueNum isEqual:@"0"]) {
  555. progress = 0.2;
  556. }else if ([redNum isEqual:@"0"]) {
  557. progress = 0.8;
  558. }else{
  559. CGFloat ppp = [blueNum floatValue]/([blueNum floatValue] + [redNum floatValue]);
  560. if (ppp < 0.2) {
  561. progress = 0.2;
  562. }else if (ppp > 0.8){
  563. progress = 0.8;
  564. }else{
  565. progress = ppp;
  566. }
  567. }
  568. [_pkView updateProgress:progress withBlueNum:blueNum withRedNum:redNum];
  569. }
  570. -(void)destroyPkView {
  571. if (_pkView) {
  572. [_pkView removeTimer];
  573. [_pkView removeFromSuperview];
  574. _pkView = nil;
  575. }
  576. }
  577. #pragma mark - /** 键盘弹起事件: 目前只处理 PK和连麦 的界面相对位置不变*/
  578. -(void)keyBoardNoticeIsShow:(BOOL)isShow andHeight:(CGFloat)height;{
  579. _pkView.top = 130+statusbarHeight + height;
  580. [_linkMicView keyBoardNoticeIsShow:isShow andHeight:height];
  581. }
  582. #pragma mark - 功能按钮回调
  583. -(void)funViewCallBack:(NSString *)eventType {
  584. if ([eventType isEqual:@"直播功能-取消"]) {
  585. _moreBtn.selected = NO;
  586. }
  587. if ([eventType isEqual:@"直播功能-美颜"] && self.liveCtrEvent) {
  588. self.liveCtrEvent(@"控制-美颜", @{});
  589. }
  590. if ([eventType isEqual:@"直播功能-翻转"] && self.liveCtrEvent) {
  591. self.liveCtrEvent(@"控制-翻转", @{});
  592. }
  593. if ([eventType isEqual:@"直播功能-闪光灯"] && self.liveCtrEvent) {
  594. self.liveCtrEvent(@"控制-闪光灯", @{});
  595. }
  596. if ([eventType isEqual:@"直播功能-分享"]) {
  597. // self.liveCtrEvent(@"控制-分享", @{});
  598. NSDictionary *shareDic = @{@"hostName":[Config getOwnNicename],@"thumb_s":[Config getUserAvatarThumb],@"hostId":[Config getOwnID],@"liveTitle":_liveTitle};
  599. [YBShareView showShareWithType:RKShareType_Liveing parameter:shareDic commplete:^(int codeEvent, NSString *nums) {
  600. }];
  601. }
  602. if ([eventType isEqual:@"直播功能-连麦"]) {
  603. if (_hostLinking) {
  604. [MBProgressHUD showError:YZMsg(@"当前正在进行连麦")];
  605. return;
  606. }
  607. [self showAnchorOnlineList];
  608. }
  609. }
  610. #pragma mark - 聊天工具栏回调
  611. -(void)chatToolCallBack:(NSString *)eventType andContent:(NSString *)eventContent{
  612. //去发送socke;
  613. if ([eventType isEqual:@"直播聊天-发送"] && self.liveCtrEvent) {
  614. self.liveCtrEvent(@"控制-直播聊天", @{@"ct":eventContent});
  615. }
  616. }
  617. #pragma mark - 公屏聊天处点击回调
  618. -(void)roomChatCallBack:(NSString *)eventType andEventInfo:(NSDictionary *)eventDic {
  619. if ([eventType isEqual:@"房间聊天-用户信息"] && self.liveCtrEvent) {
  620. [_chatTool.chatTF resignFirstResponder];
  621. //@{@"id":model.userID,@"name":model.userName}
  622. self.liveCtrEvent(@"控制-信息卡", eventDic);
  623. }
  624. }
  625. #pragma mark - 用户列表回调
  626. -(void)userListCallBack:(NSString *)eventType andEventInfo:(NSDictionary *)eventDic{
  627. if ([eventType isEqual:@"用户列表-用户信息"] && self.liveCtrEvent) {
  628. [_chatTool.chatTF resignFirstResponder];
  629. //@{@"id":model.userID,@"name":model.userName}
  630. self.liveCtrEvent(@"控制-信息卡", eventDic);
  631. }
  632. }
  633. #pragma mark - 开播动画
  634. -(void)startLiveAnimation {
  635. YBWeakSelf;
  636. _pubTiems = [PublicView showTimerView:^(int eventCode) {
  637. dispatch_async(dispatch_get_main_queue(), ^{
  638. [weakSelf timeEnd];
  639. });
  640. }];
  641. }
  642. -(void)timeEnd {
  643. if (self.liveCtrEvent) {
  644. self.liveCtrEvent(@"控制-动画结束", @{});
  645. }
  646. if (_pubTiems) {
  647. [_pubTiems removeFromSuperview];
  648. _pubTiems = nil;
  649. }
  650. }
  651. #pragma mark - 房间更新映票
  652. -(void)createroomUpdateInfo:(NSDictionary *)roomDic; {
  653. _hostVotesBtn.hidden = NO;
  654. NSString *votesStr = [NSString stringWithFormat:@"%@ %@",[common name_votes],[roomDic valueForKey:@"votestotal"]];
  655. [_hostVotesBtn setTitle:votesStr forState:0];
  656. [self updateGuardNums:minstr([roomDic valueForKey:@"guard_nums"])];
  657. }
  658. #pragma mark - 更新直播时长
  659. -(void)updateLiveTime {
  660. _liveTime ++;
  661. NSString *timeFormat = @"00:00";
  662. if (_liveTime < 3600) {
  663. timeFormat = [NSString stringWithFormat:@"%02d:%02d",_liveTime/60,_liveTime%60];
  664. }else{
  665. timeFormat = [NSString stringWithFormat:@"%02d:%02d:%02d",_liveTime/3600,(_liveTime%3600)/60,(_liveTime%3600)%60];
  666. }
  667. [_hostLiveTimeBtn setTitle:timeFormat forState:0];
  668. }
  669. #pragma mark - 用户点亮
  670. -(void)socketLightAnimation {
  671. [_botBtnFunView layoutIfNeeded];
  672. starX = CGRectGetMaxX(_botBtnFunView.frame)-20 ;
  673. starY = _botBtnFunView.frame.origin.y;
  674. starImage = [[UIImageView alloc]initWithFrame:CGRectMake(starX, starY, 30, 30)];
  675. starImage.contentMode = UIViewContentModeScaleAspectFit;
  676. NSMutableArray *array = [NSMutableArray arrayWithObjects:@"plane_heart_cyan.png",@"plane_heart_pink.png",@"plane_heart_red.png",@"plane_heart_yellow.png",@"plane_heart_heart.png", nil];
  677. NSInteger random = arc4random()%array.count;
  678. starImage.image = [UIImage imageNamed:[array objectAtIndex:random]];
  679. [UIView animateWithDuration:0.2 animations:^{
  680. dispatch_async(dispatch_get_main_queue(), ^{
  681. starImage.alpha = 1.0;
  682. starImage.frame = CGRectMake(starX+random - 10, starY-random - 30, 30, 30);
  683. CGAffineTransform transfrom = CGAffineTransformMakeScale(1.3, 1.3);
  684. starImage.transform = CGAffineTransformScale(transfrom, 1, 1);
  685. });
  686. }];
  687. [self addSubview:starImage];
  688. [self sendSubviewToBack:starImage];
  689. CGFloat finishX = _window_width - round(arc4random() % 200);
  690. // 动画结束点的Y值
  691. CGFloat finishY = 200;
  692. // imageView在运动过程中的缩放比例
  693. CGFloat scale = round(arc4random() % 2) + 0.7;
  694. // 生成一个作为速度参数的随机数
  695. CGFloat speed = 1 / round(arc4random() % 900) + 0.6;
  696. // 动画执行时间
  697. NSTimeInterval duration = 4 * speed;
  698. // 如果得到的时间是无穷大,就重新附一个值(这里要特别注意,请看下面的特别提醒)
  699. if (duration == INFINITY) duration = 2.412346;
  700. // 开始动画
  701. [UIView beginAnimations:nil context:(__bridge void *_Nullable)(starImage)];
  702. // 设置动画时间
  703. [UIView setAnimationDuration:duration];
  704. // 设置imageView的结束frame
  705. starImage.frame = CGRectMake( finishX, finishY, 30 * scale, 30 * scale);
  706. // 设置渐渐消失的效果,这里的时间最好和动画时间一致
  707. [UIView animateWithDuration:duration animations:^{
  708. starImage.alpha = 0;
  709. }];
  710. // 结束动画,调用onAnimationComplete:finished:context:函数
  711. [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
  712. // 设置动画代理
  713. [UIView setAnimationDelegate:self];
  714. [UIView commitAnimations];
  715. }
  716. /// 动画完后销毁iamgeView
  717. - (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
  718. UIImageView *imageViewsss = (__bridge UIImageView *)(context);
  719. [imageViewsss removeFromSuperview];
  720. imageViewsss = nil;
  721. }
  722. #pragma mark - 发言
  723. -(void)socketChatDic:(NSDictionary *)chatDic {
  724. [_liveChatView reloadMsg:chatDic];
  725. }
  726. #pragma mark - 用户离开
  727. -(void)socketUserLeave:(NSDictionary *)leaveDic {
  728. NSLog(@"leave");
  729. [_userListView userEventOfType:UserEvent_Leave andInfo:leaveDic];
  730. }
  731. #pragma mark - 用户进入
  732. -(void)socketUserEnter:(NSDictionary *)enterDic {
  733. NSLog(@"enter");
  734. [_userListView userEventOfType:UserEvent_Enter andInfo:enterDic];
  735. NSString *vipType = [NSString stringWithFormat:@"%@",[[enterDic valueForKey:@"ct"] valueForKey:@"vip_type"]];
  736. NSString *guardType = [NSString stringWithFormat:@"%@",[[enterDic valueForKey:@"ct"] valueForKey:@"guard_type"]];
  737. //vip暂时没有动画,只有守护有
  738. if ([vipType isEqual:@"1"] || [guardType isEqual:@"1"] || [guardType isEqual:@"2"]) {
  739. //进场动画
  740. [_userAnimation addUserMove:enterDic];
  741. }
  742. NSDictionary *ctDic = [enterDic valueForKey:@"ct"];
  743. NSDictionary *chatDic = @{@"userName":minstr([ctDic valueForKey:@"user_nickname"]),
  744. @"contentChat":YZMsg(@" 进入了直播间"),
  745. @"id":minstr([ctDic valueForKey:@"id"]),
  746. @"titleColor":@"userLogin",
  747. @"usertype":minstr([ctDic valueForKey:@"usertype"]),
  748. @"guard_type":minstr([ctDic valueForKey:@"guard_type"]),
  749. };
  750. [self socketChatDic:chatDic];
  751. }
  752. #pragma mark - 送礼物
  753. -(void)socketSendGift:(NSDictionary *)giftDic {
  754. NSDictionary *ctDic = [giftDic valueForKey:@"ct"];
  755. NSMutableDictionary *showDic = @{@"avatar":minstr([giftDic valueForKey:@"uhead"]),
  756. @"nickname":minstr([giftDic valueForKey:@"uname"]),
  757. @"paintedHeight":[giftDic valueForKey:@"paintedHeight"]?[giftDic valueForKey:@"paintedHeight"]:@"",
  758. @"paintedPath":[giftDic valueForKey:@"paintedPath"]?[giftDic valueForKey:@"paintedPath"]:@[],//数组
  759. @"paintedWidth":[giftDic valueForKey:@"paintedWidth"]?[giftDic valueForKey:@"paintedWidth"]:@"",
  760. }.mutableCopy;
  761. [showDic addEntriesFromDictionary:ctDic];
  762. [self showGift:showDic];
  763. NSString *votes = minstr([ctDic valueForKey:@"votestotal"]);
  764. [self updateVotes:votes];
  765. }
  766. #pragma mark - 更新映票
  767. -(void)updateVotes:(NSString *)votes {
  768. NSString *votesStr = [NSString stringWithFormat:@"%@ %@",[common name_votes],votes];
  769. [_hostVotesBtn setTitle:votesStr forState:0];
  770. }
  771. #pragma mark - 更新守护数量
  772. -(void)updateGuardNums:(NSString *)nums {
  773. if ([nums intValue] <= 0) {
  774. return;
  775. }
  776. NSString *guardStr = [NSString stringWithFormat:YZMsg(@"守护 %@人"),nums];
  777. [_hostGuardBtn setTitle:guardStr forState:0];
  778. [self layoutSubviews];
  779. }
  780. #pragma mark - /** 计时器刷新列表 */
  781. -(void)timerReloadList {
  782. [_userListView timerReloadList];
  783. }
  784. #pragma mark - /** 私信未读数 */
  785. -(void)updateUnread:(int)unread {
  786. _redPoint.hidden = YES;
  787. if (unread > 0) {
  788. _redPoint.hidden = NO;
  789. }
  790. }
  791. #pragma mark - 打赏开始
  792. -(void)showGift:(NSDictionary *)giftDic {
  793. NSString *type = minstr([giftDic valueForKey:@"type"]);
  794. if (!continueGifts) {
  795. continueGifts = [[continueGift alloc]initWithFrame:CGRectMake(0, 0, liansongliwubottomview.width, liansongliwubottomview.height)];
  796. [liansongliwubottomview addSubview:continueGifts];
  797. //初始化礼物空位
  798. [continueGifts initGift];
  799. YBWeakSelf;
  800. continueGifts.rkPaintedEvent = ^(NSDictionary *giftDic) {
  801. [weakSelf showPaintedGift:giftDic];
  802. };
  803. }
  804. if ([type isEqual:@"1"]) {
  805. [self expensiveGift:giftDic];
  806. }else{
  807. //手绘以及普通礼物都进 continueGifts 由它执行队列
  808. [continueGifts GiftPopView:giftDic andLianSong:@"Y"];
  809. }
  810. }
  811. -(void)showPaintedGift:(NSDictionary *)giftDic {
  812. //手绘显示动画
  813. _paintedShowRegion.giftPathStr = minstr([giftDic valueForKey:@"gifticon"]);
  814. _paintedShowRegion.paintedWidth = [minstr([giftDic valueForKey:@"paintedWidth"]) floatValue];
  815. _paintedShowRegion.paintedHeight = [minstr([giftDic valueForKey:@"paintedHeight"]) floatValue];
  816. _paintedShowRegion.paintedPointArray = [NSArray arrayWithArray:[giftDic valueForKey:@"paintedPath"]];
  817. }
  818. /************ 礼物弹出及队列显示开始 *************/
  819. -(void)expensiveGiftdelegate:(NSDictionary *)giftData{
  820. if (!haohualiwuV) {
  821. haohualiwuV = [[expensiveGiftV alloc]init];
  822. haohualiwuV.delegate = self;
  823. [self addSubview:haohualiwuV];
  824. }
  825. if (giftData == nil) {
  826. }else {
  827. [haohualiwuV addArrayCount:giftData];
  828. }
  829. if(haohualiwuV.haohuaCount == 0){
  830. [haohualiwuV enGiftEspensive];
  831. }
  832. }
  833. -(void)expensiveGift:(NSDictionary *)giftData{
  834. if (!haohualiwuV) {
  835. haohualiwuV = [[expensiveGiftV alloc]init];
  836. haohualiwuV.delegate = self;
  837. [self addSubview:haohualiwuV];
  838. }
  839. if (giftData == nil) {
  840. }else {
  841. [haohualiwuV addArrayCount:giftData];
  842. }
  843. if(haohualiwuV.haohuaCount == 0){
  844. [haohualiwuV enGiftEspensive];
  845. }
  846. }
  847. #pragma mark - 销毁子视图
  848. -(void)destroyCtrSubView {
  849. if (continueGifts) {
  850. [continueGifts stopTimerAndArray];
  851. [continueGifts initGift];
  852. [continueGifts removeFromSuperview];
  853. continueGifts = nil;
  854. }
  855. if (haohualiwuV) {
  856. [haohualiwuV stopHaoHUaLiwu];
  857. [haohualiwuV removeFromSuperview];
  858. haohualiwuV.expensiveGiftCount = nil;
  859. haohualiwuV = nil;
  860. }
  861. liansongliwubottomview.top = statusbarHeight+200;
  862. if (_onsaleView) {
  863. [_onsaleView removeFromSuperview];
  864. }
  865. if (_paintedShowRegion) {
  866. [_paintedShowRegion destroyPaitend];
  867. }
  868. [self desTroyDaytaskView];
  869. [self removeShouhuView];
  870. [self destroyLinkMicView];
  871. [self destroyAnchorOnlineList];
  872. [self cancelPKAlert];
  873. [self destroyPkView];
  874. }
  875. #pragma mark - 每日任务
  876. /** 点击图片回调 */
  877. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  878. NSLog(@"点击轮播----------index:%ld",index);
  879. if (index == 0) {
  880. //每日任务
  881. [self desTroyDaytaskView];
  882. _dayTaskView = [YBDayTaskView showRoomDayTask];
  883. _dayTaskView.liveuid = minstr(_liveUid);
  884. [_dayTaskView requestListData];
  885. }
  886. }
  887. /** 图片滚动回调 */
  888. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
  889. self.roomGamePage.currentPage = index;
  890. }
  891. #pragma mark - 守护
  892. -(void)clickGuardBtn {
  893. gShowView = [[guardShowView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) andUserGuardMsg:nil andLiveUid:[Config getOwnID]];
  894. gShowView.delegate = self;
  895. [self addSubview:gShowView];
  896. [gShowView show];
  897. }
  898. - (void)removeShouhuView{
  899. if (gShowView) {
  900. [gShowView removeFromSuperview];
  901. gShowView = nil;
  902. }
  903. }
  904. - (void)socketUpdateGuardMsg:(NSDictionary *)dic{
  905. [self updateVotes:minstr([dic valueForKey:@"votestotal"])];
  906. [self timerReloadList];
  907. [self updateGuardNums:minstr([dic valueForKey:@"guard_nums"])];
  908. }
  909. #pragma mark - set/get
  910. - (UIView *)hostInfoView {
  911. if (!_hostInfoView) {
  912. _hostInfoView = [[UIView alloc]init];
  913. _hostInfoView.layer.cornerRadius = 17;
  914. _hostInfoView.layer.masksToBounds = YES;
  915. _hostInfoView.backgroundColor = RGB_COLOR(@"#000000", 0.5);
  916. _hostAvatarBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  917. [_hostAvatarBtn sd_setImageWithURL:[NSURL URLWithString:[Config getUserAvatar]] forState:0];
  918. _hostAvatarBtn.layer.masksToBounds = YES;
  919. _hostAvatarBtn.layer.cornerRadius = 15;
  920. [_hostAvatarBtn.imageView setContentMode:UIViewContentModeScaleAspectFill];
  921. _hostAvatarBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
  922. _hostAvatarBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
  923. [_hostAvatarBtn addTarget:self action:@selector(clickHostAvatarBtn) forControlEvents:UIControlEventTouchUpInside];
  924. [_hostInfoView addSubview:_hostAvatarBtn];
  925. [_hostAvatarBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  926. make.centerY.equalTo(_hostInfoView);
  927. make.left.equalTo(_hostInfoView).offset(2);
  928. make.width.height.mas_equalTo(30);
  929. }];
  930. _hostNameL = [[UILabel alloc]init];
  931. _hostNameL.font = SYS_Font(13);
  932. _hostNameL.textColor = RGB_COLOR(@"#ffffff", 1);
  933. _hostNameL.text = minstr([Config getOwnNicename]);
  934. [_hostInfoView addSubview:_hostNameL];
  935. [_hostNameL mas_makeConstraints:^(MASConstraintMaker *make) {
  936. make.centerY.equalTo(_hostAvatarBtn.mas_centerY).multipliedBy(0.65);
  937. make.left.equalTo(_hostAvatarBtn.mas_right).offset(5);
  938. }];
  939. _hostIDL = [[UILabel alloc]init];
  940. _hostIDL.font = SYS_Font(10);
  941. _hostIDL.text = [NSString stringWithFormat:@"ID:%@",[Config getOwnID]];
  942. _hostIDL.textColor = RGB_COLOR(@"#f0f0f0", 1);
  943. [_hostInfoView addSubview:_hostIDL];
  944. [_hostIDL mas_makeConstraints:^(MASConstraintMaker *make) {
  945. make.left.right.equalTo(_hostNameL);
  946. make.centerY.equalTo(_hostAvatarBtn.mas_centerY).multipliedBy(1.53);
  947. }];
  948. }
  949. return _hostInfoView;
  950. }
  951. - (UIButton *)hostVotesBtn {
  952. if (!_hostVotesBtn) {
  953. _hostVotesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  954. //无点击事件
  955. [_hostVotesBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  956. _hostVotesBtn.titleLabel.font = SYS_Font(10);
  957. _hostVotesBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 11, 0, 11);
  958. _hostVotesBtn.backgroundColor = RGB_COLOR(@"#000000", 0.5);
  959. _hostVotesBtn.layer.masksToBounds = YES;
  960. _hostVotesBtn.layer.cornerRadius = 11;
  961. _hostVotesBtn.hidden = YES;
  962. }
  963. return _hostVotesBtn;
  964. }
  965. - (UIButton *)hostGuardBtn {
  966. if (!_hostGuardBtn) {
  967. _hostGuardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  968. _hostGuardBtn.titleLabel.font = SYS_Font(10);
  969. _hostGuardBtn.layer.masksToBounds = YES;
  970. _hostGuardBtn.layer.cornerRadius = 11;
  971. [_hostGuardBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  972. _hostGuardBtn.backgroundColor = RGB_COLOR(@"#000000", 0.5);
  973. [_hostGuardBtn setTitle:YZMsg(@"守护 虚位以待") forState:0];
  974. [_hostGuardBtn setImage:[UIImage imageNamed:@"pub_white_right"] forState:0];
  975. [_hostGuardBtn addTarget:self action:@selector(clickGuardBtn) forControlEvents:UIControlEventTouchUpInside];
  976. _hostGuardBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 5);
  977. }
  978. return _hostGuardBtn;;
  979. }
  980. - (UIButton *)hostLiveTimeBtn {
  981. if (!_hostLiveTimeBtn) {
  982. _hostLiveTimeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  983. //无点击事件
  984. [_hostLiveTimeBtn setTitleColor:RGB_COLOR(@"#f0f0f0", 1) forState:0];
  985. _hostLiveTimeBtn.titleLabel.font = SYS_Font(10);
  986. _hostLiveTimeBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 14, 0, 11);
  987. _hostLiveTimeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  988. _hostLiveTimeBtn.backgroundColor = RGB_COLOR(@"#000000", 0.5);
  989. _hostLiveTimeBtn.layer.masksToBounds = YES;
  990. _hostLiveTimeBtn.layer.cornerRadius = 11;
  991. UIImage *pointImg = [PublicObj getImgWithColor:Pink_Cor withSize:CGSizeMake(5, 5)];
  992. [_hostLiveTimeBtn setImage:[pointImg rk_circleImage] forState:0];
  993. [_hostLiveTimeBtn setTitle:@"00:00" forState:0];
  994. }
  995. return _hostLiveTimeBtn;
  996. }
  997. - (SDCycleScrollView *)roomGameCycle {
  998. if (!_roomGameCycle) {
  999. _roomGameCycle = [[SDCycleScrollView alloc]init];
  1000. _roomGameCycle.backgroundColor = [UIColor clearColor];
  1001. _roomGameCycle.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
  1002. _roomGameCycle.delegate = self;
  1003. _roomGameCycle.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
  1004. _roomGameCycle.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1005. _roomGameCycle.autoScrollTimeInterval = 3.0;
  1006. _roomGameCycle.currentPageDotColor = [UIColor whiteColor];
  1007. _roomGameCycle.pageDotColor = [[UIColor whiteColor] colorWithAlphaComponent:0.4];
  1008. _roomGameCycle.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
  1009. _roomGameCycle.imageURLStringsGroup = _roomGameArray;
  1010. }
  1011. return _roomGameCycle;
  1012. }
  1013. - (YBPageControl *)roomGamePage {
  1014. if (!_roomGamePage) {
  1015. _roomGamePage = [[YBPageControl alloc]init];
  1016. _roomGamePage.numberOfPages = _roomGameArray.count;
  1017. _roomGamePage.currentPage = 0;
  1018. _roomGamePage.pageIndicatorTintColor = [UIColor grayColor];
  1019. _roomGamePage.currentPageIndicatorTintColor = [UIColor whiteColor];
  1020. // _roomGamePage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7);
  1021. _roomGamePage.userInteractionEnabled = NO;
  1022. }
  1023. return _roomGamePage;
  1024. }
  1025. - (YBUserListView *)userListView {
  1026. if (!_userListView) {
  1027. YBWeakSelf;
  1028. _userListView = [[YBUserListView alloc]init];
  1029. _userListView.backgroundColor = UIColor.clearColor;
  1030. if (![PublicObj checkNull:_liveUid] && ![PublicObj checkNull:_liveStream]) {
  1031. _userListView.liveUid = minstr(_liveUid);
  1032. _userListView.liveStream = minstr(_liveStream);
  1033. }
  1034. _userListView.listEvent = ^(NSString *eventStr, NSDictionary *eventDic) {
  1035. [weakSelf userListCallBack:eventStr andEventInfo:eventDic];
  1036. };
  1037. }
  1038. return _userListView;
  1039. }
  1040. - (void)setLiveUid:(NSString *)liveUid {
  1041. _liveUid = liveUid;
  1042. if (_userListView) {
  1043. _userListView.liveUid = minstr(_liveUid);
  1044. }
  1045. }
  1046. -(void)setLiveStream:(NSString *)liveStream {
  1047. _liveStream = liveStream;
  1048. if (_userListView) {
  1049. _userListView.liveStream = minstr(_liveStream);
  1050. }
  1051. }
  1052. - (YBLiveChatView *)liveChatView {
  1053. if (!_liveChatView) {
  1054. YBWeakSelf;
  1055. _liveChatView = [[YBLiveChatView alloc]initWithFrame:CGRectMake(10,_window_height-ChatViewHeight-60-ShowDiff, ChatViewWidth, ChatViewHeight)];
  1056. _liveChatView.liveChatEvent = ^(NSString *eventStr, NSDictionary *eventDic) {
  1057. [weakSelf roomChatCallBack:eventStr andEventInfo:eventDic];
  1058. };
  1059. }
  1060. return _liveChatView;
  1061. }
  1062. - (YBUserEnterAnimation *)userAnimation {
  1063. if (!_userAnimation) {
  1064. _userAnimation = [[YBUserEnterAnimation alloc]init];
  1065. }
  1066. return _userAnimation;
  1067. }
  1068. - (UIButton *)linkCtrBtn {
  1069. if (!_linkCtrBtn) {
  1070. _linkCtrBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1071. [_linkCtrBtn addTarget:self action:@selector(clickLinkCtrBtn:) forControlEvents:UIControlEventTouchUpInside];
  1072. [_linkCtrBtn setTitleColor:RGB_COLOR(@"#dddddd", 1) forState:0];
  1073. [_linkCtrBtn setTitleColor:RGB_COLOR(@"#dddddd", 1) forState:UIControlStateSelected];
  1074. [_linkCtrBtn setTitle:YZMsg(@"连麦互动") forState:0];
  1075. [_linkCtrBtn setTitle:YZMsg(@"禁止连麦") forState:UIControlStateSelected];
  1076. _linkCtrBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  1077. _linkCtrBtn.titleLabel.font = SYS_Font(8);
  1078. [_linkCtrBtn setImage:[UIImage imageNamed:@"直播-连控彩"] forState:0];
  1079. [_linkCtrBtn setImage:[UIImage imageNamed:@"直播-连控灰"] forState:UIControlStateSelected];
  1080. _linkCtrBtn.layer.cornerRadius = 8;
  1081. _linkCtrBtn.layer.masksToBounds = YES;
  1082. _linkCtrBtn.backgroundColor = RGB_COLOR(@"#000000", 0.4);
  1083. }
  1084. return _linkCtrBtn;
  1085. }
  1086. - (UIView *)botBtnFunView {
  1087. if (!_botBtnFunView) {
  1088. _botBtnFunView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height-50-ShowDiff, _window_width, 40)];
  1089. CGFloat btnW = 30;
  1090. UIButton *keyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1091. [keyBtn addTarget:self action:@selector(clickKeyBtn) forControlEvents:UIControlEventTouchUpInside];
  1092. [keyBtn setImage:[UIImage imageNamed:@"live_聊天"] forState:0];
  1093. [_botBtnFunView addSubview:keyBtn];
  1094. [keyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  1095. make.width.height.mas_equalTo(btnW);
  1096. make.centerY.equalTo(_botBtnFunView);
  1097. make.left.equalTo(_botBtnFunView.mas_left).offset(10);
  1098. }];
  1099. _closeLiveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1100. [_closeLiveBtn addTarget:self action:@selector(clikcCloseLiveBtn) forControlEvents:UIControlEventTouchUpInside];
  1101. [_closeLiveBtn setImage:[UIImage imageNamed:@"live_关闭"] forState:0];
  1102. [_botBtnFunView addSubview:_closeLiveBtn];
  1103. [_closeLiveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  1104. make.width.height.mas_equalTo(btnW);
  1105. make.centerY.equalTo(_botBtnFunView);
  1106. make.right.equalTo(_botBtnFunView.mas_right).offset(-10);
  1107. }];
  1108. _msgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1109. [_msgBtn addTarget:self action:@selector(clikcMsgBtn) forControlEvents:UIControlEventTouchUpInside];
  1110. [_msgBtn setImage:[UIImage imageNamed:@"live_私信"] forState:0];
  1111. [_botBtnFunView addSubview:_msgBtn];
  1112. [_msgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  1113. make.width.height.mas_equalTo(btnW);
  1114. make.centerY.equalTo(_botBtnFunView);
  1115. make.right.equalTo(_closeLiveBtn.mas_left).offset(-10);
  1116. }];
  1117. _redPoint = [[UILabel alloc]init];
  1118. _redPoint.layer.masksToBounds = YES;
  1119. _redPoint.layer.cornerRadius = 4;
  1120. _redPoint.backgroundColor = UIColor.redColor;
  1121. [_botBtnFunView addSubview:_redPoint];
  1122. _redPoint.hidden = YES;
  1123. [_redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
  1124. make.width.height.mas_equalTo(8);
  1125. make.centerY.equalTo(_msgBtn.mas_top);
  1126. make.right.equalTo(_msgBtn.mas_right).offset(-4);
  1127. }];
  1128. _moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1129. [_moreBtn addTarget:self action:@selector(clikcMoreBtn) forControlEvents:UIControlEventTouchUpInside];
  1130. [_moreBtn setImage:[UIImage imageNamed:@"功能"] forState:0];
  1131. [_moreBtn setImage:[UIImage imageNamed:@"功能_S"] forState:UIControlStateSelected];
  1132. [_botBtnFunView addSubview:_moreBtn];
  1133. [_moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  1134. make.width.height.mas_equalTo(btnW);
  1135. make.centerY.equalTo(_botBtnFunView);
  1136. make.right.equalTo(_msgBtn.mas_left).offset(-10);
  1137. }];
  1138. _cartBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1139. [_cartBtn addTarget:self action:@selector(clikcCartBtn) forControlEvents:UIControlEventTouchUpInside];
  1140. [_cartBtn setImage:[UIImage imageNamed:@"live_店铺"] forState:0];
  1141. [_botBtnFunView addSubview:_cartBtn];
  1142. _cartBtn.hidden = YES;
  1143. [_cartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  1144. make.width.height.mas_equalTo(btnW);
  1145. make.centerY.equalTo(_botBtnFunView);
  1146. make.right.equalTo(_moreBtn.mas_left).offset(-10);
  1147. }];
  1148. _startPkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1149. [_startPkBtn addTarget:self action:@selector(clikcStartPkBtn) forControlEvents:UIControlEventTouchUpInside];
  1150. [_startPkBtn setImage:[UIImage imageNamed:getImagename(@"发起pk")] forState:0];
  1151. [_botBtnFunView addSubview:_startPkBtn];
  1152. _startPkBtn.hidden = YES;
  1153. }
  1154. return _botBtnFunView;
  1155. }
  1156. - (YBChatToolBar *)chatTool {
  1157. if (!_chatTool) {
  1158. YBWeakSelf;
  1159. _chatTool = [[YBChatToolBar alloc]initWithFrame:CGRectMake(0, _window_height-44, _window_width, 44)];
  1160. _chatTool.hidden = YES;
  1161. _chatTool.chatToolEvnt = ^(NSString *eventType, NSString *eventContent) {
  1162. [weakSelf chatToolCallBack:eventType andContent:eventContent];
  1163. };
  1164. }
  1165. return _chatTool;
  1166. }
  1167. -(void)tapGes {
  1168. if ([_chatTool.chatTF isFirstResponder]) {
  1169. [_chatTool.chatTF resignFirstResponder];
  1170. }
  1171. }
  1172. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;{
  1173. if ([touch.view isDescendantOfView:_botBtnFunView]
  1174. ||[touch.view isDescendantOfView:_liveChatView]
  1175. ||[touch.view isDescendantOfView:_userListView]
  1176. ||[touch.view isDescendantOfView:_hostInfoView]
  1177. ||[touch.view isDescendantOfView:_chatTool]
  1178. ||[touch.view isDescendantOfView:_roomGameCycle]) {
  1179. return NO;
  1180. }
  1181. return YES;
  1182. }
  1183. - (RKShowPaintedView *)paintedShowRegion {
  1184. if (!_paintedShowRegion) {
  1185. _paintedShowRegion = [[RKShowPaintedView alloc]init];
  1186. //_paintedShowRegion.backgroundColor = UIColor.redColor;
  1187. }
  1188. return _paintedShowRegion;
  1189. }
  1190. -(void)desTroyDaytaskView {
  1191. if (_dayTaskView) {
  1192. [_dayTaskView dismissView];
  1193. _dayTaskView = nil;
  1194. }
  1195. }
  1196. @end