YOUPAILZLiveBaseVC.m 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. //
  2. // YOUPAILZLiveBaseVC.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/7.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveBaseVC.h"
  9. #import "FUOpenGLView.h"
  10. #import "FUManager.h"
  11. //#import "YOUPAIAGVideoProcessing.h"
  12. #import "NIMMessageMaker.h"
  13. #import "YOUPAILCIMTool.h"
  14. #import "YOUPAILZLiveChatMessageCell.h"
  15. //#import "YOUPAILZLiveConsumeMemberListVC.h"
  16. #import "UIViewController+TFPresent.h"
  17. #import "YOUPAILCGiftAttachment.h"
  18. #import "YOUPAILZGuardAttachment.h"
  19. #import "YOUPAILZLiveInfoUpdateAttachment.h"
  20. #import "YOUPAILZLiveCloseAttachment.h"
  21. #import "YOUPAILZLivePKDataAttachment.h"
  22. #import "YOUPAILZLiveRankAttachment.h"
  23. #import "YOUPAILZLiveBarrageAttachment.h"
  24. #import "YOUPAILZLiveManageAttachment.h"
  25. #import "YOUPAILZLiveVipBarrageAttachment.h"
  26. #import "YOUPAILZLiveCarAttachment.h"
  27. #import "YOUPAILZLiveGiftView.h"
  28. #import "NIMKitUtil.h"
  29. #import "NIMKitInfoFetchOption.h"
  30. #import <SVGAPlayer.h>
  31. #import <SVGAParser.h>
  32. #import "YOUPAILZLiveFollowCell.h"
  33. #import "YOUPAILZLiveFollowAttachment.h"
  34. #import "YOUPAILZLiveUserInfoWindow.h"
  35. #import "YOUPAILZUserShowVC.h"
  36. #import "YOUPAILCReportVC.h"
  37. #import "YOUPAILPGuardHerVC.h"
  38. #import "YOUPAILCIMSessionVC.h"
  39. #import "UIView+YOUPAIRCDDanmaku.h"
  40. #import "YOUPAIRCDDanmaku.h"
  41. #import "YOUPAIRCDDanmakuManager.h"
  42. #import "YOUPAILZCommonGiftView.h"
  43. #import "LZAlertWindow.h"
  44. #import "UIViewController+TFPresent.h"
  45. #import "YOUPAILZLiveManageListWindow.h"
  46. #import "YOUPAILZLiveBarrageTool.h"
  47. #import "YOUPAILZLiveManagerListUtils.h"
  48. #import "SDCycleScrollView.h"
  49. #import "YOUPAILCFirstRechargeModel.h"
  50. #import "UIViewController+TFPresent.h"
  51. @interface YOUPAILZLiveBaseVC ()<AgoraRtcEngineDelegate,FUCameraDelegate,NIMChatroomManagerDelegate,NIMChatManagerDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,SVGAPlayerDelegate,LPGuardHerDelegate,LZLiveGiftViewDelegate,SDCycleScrollViewDelegate>
  52. @property (nonatomic,strong) AgoraRtcVideoCanvas *youpaiplocalCanvas; // 本地画布
  53. @property (nonatomic,strong) AgoraRtcVideoCanvas *youpaipremoteCanvas; // 远程画布
  54. @property (nonatomic,strong) YOUPAILZLiveVideoView *youpaiplocalVideo; // 本地视频容器
  55. @property (nonatomic,strong) YOUPAILZLiveVideoView *youpaipremoteVideo; // 远程视频容器
  56. @property (nonatomic, strong) UITableView *youpaipchatTableView; /// 消息列表
  57. @property (nonatomic, strong) UITextField *youpaipsendMessageTF; /// 发送消息输入框
  58. @property (nonatomic, strong) NSMutableArray <NIMMessage *>*youpaipmessages; // 消息数据
  59. @property (nonatomic, strong) NSMutableArray *youpaipgifts; // 礼物数据
  60. @property (nonatomic, strong) NSMutableArray <YOUPAILZLiveGiftView *>* youpaipgiftViews;// 礼物
  61. @property (nonatomic, strong) NSMutableArray *youpaipsvgas; /// svga礼物数据
  62. @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer;
  63. @property (nonatomic, strong) SVGAParser *youpaipparser;
  64. @property (nonatomic, assign) BOOL youpaipisPlaySvga;
  65. @property (nonatomic, assign) BOOL youpaipisNetworkInterrupt; // 是否网络中断
  66. @property (nonatomic, strong) UIImageView *youpaipdrawImgV; // 平局View
  67. @property (nonatomic, strong) UIButton *youpaipcloseEnemyAudioBtn; // 关闭对方音频按钮
  68. //@property (nonatomic, weak) UIImageView *youpaipheaderBgV;
  69. @property (nonatomic,strong) UIButton *youpaipfollowBgV;
  70. @property (nonatomic,strong) UILabel *youpaipnickNameL;
  71. @property (nonatomic,strong) UIButton *youpaipfollowBtn;
  72. @property (nonatomic,copy) NSString *youpaipto_uid; // 对方女神id
  73. @property (nonatomic,copy) NSString *youpaiptoRoomId; // 对方直播间id;
  74. @property (nonatomic,strong) UIButton *youpaipremoteVideoBtn;
  75. @property (nonatomic, assign) CGFloat youpaipchatBgX;
  76. @property (nonatomic, strong) NSDate *youpaipjoinLiveMessageDate; /// 直播间加入消息时间
  77. @property (nonatomic, strong) YOUPAILZLiveCarAttachment *youpaipcarAttachment; // 直播间座驾动画
  78. @property (nonatomic, strong) SVGAPlayer *youpaipcarSvgaPlayer;
  79. @property (nonatomic, strong) SVGAParser *youpaipcarParser;
  80. @property (nonatomic, assign) BOOL youpaipisPlayCarSvga;
  81. //广告相关
  82. @property(nonatomic,strong)SDCycleScrollView* youpaipSDCscrollView;
  83. @property (strong, nonatomic) YOUPAILCFirstRechargeModel *youpaipfirstRechargeModel;
  84. @end
  85. @implementation YOUPAILZLiveBaseVC
  86. //@synthesize consumer;
  87. +(instancetype)youpaifLiveWithModel:(YOUPAILZLiveModel *)youpaipliveModel{
  88. return [[self alloc] initWithModel:youpaipliveModel];
  89. }
  90. -(instancetype)initWithModel:(YOUPAILZLiveModel *)youpaipliveModel{
  91. if (self = [super init]) {
  92. _youpaipliveModel = youpaipliveModel;
  93. }
  94. return self;
  95. }
  96. - (void)viewWillAppear:(BOOL)animated{
  97. [super viewWillAppear:animated];
  98. self.navigationController.navigationBarHidden = YES;
  99. }
  100. - (void)viewDidAppear:(BOOL)animated{
  101. [super viewDidAppear:animated];
  102. self.youpaipisNotPanClose = NO;
  103. }
  104. - (void)viewWillDisappear:(BOOL)animated{
  105. [super viewWillDisappear:animated];
  106. self.navigationController.navigationBarHidden = NO;
  107. [self.view youpaifstopDanmaku];
  108. }
  109. - (void)dealloc{
  110. [[NSNotificationCenter defaultCenter] removeObserver:self];
  111. }
  112. - (void)viewDidLoad {
  113. [super viewDidLoad];
  114. self.sx_disableInteractivePop = YES;
  115. [self youpaifsetupBackgoundColor];
  116. [self youpaifinitVideoView];
  117. [self youpaifinitPKDataView];
  118. [self youpaifinitDrawImgV];
  119. [self youpaifinitChatBgView];
  120. [self youpaifinitRemoteVideoBtn];
  121. [self youpaifsetupCloseEnemyAudioBtn];
  122. [self youpaifinitFollowView];
  123. [self youpaifinitSvga];
  124. [self youpaifinitAdvertView];
  125. [self performSelector:@selector(youpaifsetupSDK) withObject:nil afterDelay:1.0];
  126. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  127. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  128. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifsetupMuteLocalVideoStream:) name:UIApplicationWillResignActiveNotification object:nil];
  129. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifsetupMuteLocalVideoStream:) name:UIApplicationDidBecomeActiveNotification object:nil];
  130. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaiflogoutCloseLive) name:@"AbnormalLogout" object:nil];
  131. /// 关注状态改变,接收通知
  132. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  133. /// 离开页面,不关闭直播
  134. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifinsufficientBalanceNotice) name:@"InsufficientBalanceNotice" object:nil];
  135. /// 离开页面,关闭直播
  136. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifleaveLive) name:@"LeaveLive" object:nil];
  137. }
  138. //广告banner
  139. -(void)youpaifinitAdvertView{
  140. SDCycleScrollView *bannerView1 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:nil placeholderImage:nil];
  141. bannerView1.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
  142. bannerView1.hidden = YES;
  143. [self.youpaipchatBgView addSubview:bannerView1];
  144. [bannerView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.right.mas_equalTo(-13.5f);
  146. make.bottom.mas_equalTo(-SafeHeight - 50 - 30.0f);
  147. make.size.mas_equalTo(CGSizeMake(50, 50));
  148. }];
  149. self.youpaipSDCscrollView = bannerView1;
  150. bannerView1.autoScrollTimeInterval = 3.0;//2s轮播
  151. bannerView1.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
  152. bannerView1.backgroundColor = [UIColor clearColor];
  153. @weakify(self);
  154. [bannerView1 setClickItemOperationBlock:^(NSInteger currentIndex) {
  155. @strongify(self);
  156. if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
  157. [ZCHUDHelper showTitle:@"你在直播中,暂时无法离开"];
  158. return;
  159. }
  160. YOUPAILCBannerModel* model = self.youpaipfirstRechargeModel.youpaiplist[currentIndex];
  161. if (model.youpaiplink_type==1) {
  162. ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
  163. baseWeb.contentUrl = model.youpaiplink_url;
  164. self.youpaipisNotPanClose = YES;
  165. [self.navigationController pushViewController:baseWeb animated:YES];
  166. }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){
  167. [self youpaifpageToStr:model.youpaiplink_url];
  168. }
  169. }];
  170. }
  171. //首页充值数据
  172. -(void)youpaifloadAdvertRecharge{
  173. @weakify(self);
  174. [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"3"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  175. NSDictionary* dict = (NSDictionary*)responseObject;
  176. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  177. if (code==0) {//成功
  178. @strongify(self);
  179. self.youpaipfirstRechargeModel = [YOUPAILCFirstRechargeModel mj_objectWithKeyValues:dict[@"data"]];
  180. NSMutableArray *imgUrlArray = [NSMutableArray new];
  181. for (YOUPAILCBannerModel* model in self.youpaipfirstRechargeModel.youpaiplist) {
  182. [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]];
  183. }
  184. self.youpaipSDCscrollView.imageURLStringsGroup = imgUrlArray;
  185. if (self.youpaipfirstRechargeModel.youpaipis_open == 1) {
  186. self.youpaipSDCscrollView.hidden = NO;
  187. }else{
  188. self.youpaipSDCscrollView.hidden = YES;
  189. }
  190. }
  191. } failure:^(NSError *error) {}];
  192. }
  193. - (void)youpaifinsufficientBalanceNotice{
  194. self.youpaipisNotPanClose = YES;
  195. }
  196. - (void)youpaifleaveLive{
  197. self.youpaipisNotPanClose = NO;
  198. [self youpaifleaveChannel];
  199. }
  200. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  201. NSDictionary *dict = [notification userInfo];
  202. if ([dict[@"follow_uid"] isEqual:self.youpaipto_uid] && self.youpaipremoteVideo.hidden == NO) {
  203. if ([dict[@"is_follow"] integerValue] != 0) { // 加关注
  204. self.youpaipfollowBgV.hidden = YES;
  205. }else{ // 取消关注
  206. self.youpaipfollowBgV.hidden = NO;
  207. }
  208. }
  209. }
  210. // 设置背景
  211. - (void)youpaifsetupBackgoundColor{
  212. UIImageView *bgV = [[UIImageView alloc] initWithFrame:self.view.bounds];
  213. bgV.image = [UIImage imageNamed:@"vqu_images_L_live_bg"];
  214. bgV.contentMode = UIViewContentModeScaleAspectFill;
  215. [self.view addSubview:bgV];
  216. if(self.youpaipliveModel.youpaipis_virtual == 1){
  217. [bgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipliveModel.youpaipcoverimg]];
  218. }else{
  219. // UIImageView *youpaipheaderBgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, StatusBarHeight + 78.0f)];
  220. // youpaipheaderBgV.image = [UIImage imageNamed:@"vqu_images_L_live_bg_header"];
  221. // youpaipheaderBgV.hidden = YES;
  222. // [self.view addSubview:youpaipheaderBgV];
  223. // self.youpaipheaderBgV = youpaipheaderBgV;
  224. }
  225. bgV.clipsToBounds = YES;
  226. }
  227. - (void)youpaifsetupSDK{
  228. if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
  229. [self youpaifinitializeAgoraEngine];
  230. [self youpaifsetupLocalVideo];
  231. [self youpaifsetupbBeauty];
  232. [self.youpaipagoraKit startPreview];
  233. }else{
  234. [self youpaifsetupAudioSession];
  235. [self youpaifinitializeAgoraEngine];
  236. // [self youpaifsetupbBeauty];
  237. [self youpaifjoin];
  238. [self youpaifsetupChatMessageView];
  239. }
  240. }
  241. - (void)youpaifinitSvga{
  242. self.youpaipcarSvgaPlayer = [[SVGAPlayer alloc] initWithFrame:[UIScreen mainScreen].bounds];
  243. self.youpaipcarSvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
  244. self.youpaipcarSvgaPlayer.delegate = self;
  245. [self.view addSubview:self.youpaipcarSvgaPlayer];
  246. self.youpaipcarSvgaPlayer.hidden = YES;
  247. self.youpaipcarSvgaPlayer.loops = 1;
  248. self.youpaipcarSvgaPlayer.clearsAfterStop = true;
  249. self.youpaipcarParser = [[SVGAParser alloc] init];
  250. self.youpaipcarSvgaPlayer.userInteractionEnabled = NO;
  251. self.youpaipsvgaPlayer = [[SVGAPlayer alloc] initWithFrame:[UIScreen mainScreen].bounds];
  252. self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
  253. self.youpaipsvgaPlayer.delegate = self;
  254. [self.view addSubview:self.youpaipsvgaPlayer];
  255. self.youpaipsvgaPlayer.hidden = YES;
  256. self.youpaipsvgaPlayer.loops = 1;
  257. self.youpaipsvgaPlayer.clearsAfterStop = true;
  258. self.youpaipparser = [[SVGAParser alloc] init];
  259. self.youpaipsvgaPlayer.userInteractionEnabled = NO;
  260. }
  261. /// 设置视频承载容器
  262. - (void)youpaifinitVideoView{
  263. [self.view addSubview:self.youpaiplocalVideo];
  264. [self.view addSubview:self.youpaipremoteVideo];
  265. }
  266. /// pk数据承载容器
  267. - (void)youpaifinitPKDataView{
  268. YOUPAILZPKDataView *youpaippkdataView = [[YOUPAILZPKDataView alloc] initWithFrame:CGRectMake(0.0f, StatusBarHeight + 348.0f - 30.0f, KScreenWidth, 54.0f) model:self.youpaipliveModel];
  269. @weakify(self);
  270. [youpaippkdataView setShowDrawBlock:^(BOOL show) {
  271. @strongify(self);
  272. self.youpaipdrawImgV.hidden = !show;
  273. }];
  274. [self.view addSubview:youpaippkdataView];
  275. self.youpaippkdataView = youpaippkdataView;
  276. }
  277. /// 平局承载容器
  278. - (void)youpaifinitDrawImgV{
  279. UIImageView *youpaipdrawImgV = [[UIImageView alloc] init];
  280. youpaipdrawImgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_draw"];
  281. youpaipdrawImgV.hidden = YES;
  282. [self.view addSubview:youpaipdrawImgV];
  283. self.youpaipdrawImgV = youpaipdrawImgV;
  284. [youpaipdrawImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  285. make.centerX.equalTo(self.view.mas_centerX);
  286. make.centerY.equalTo(self.youpaipremoteVideo.mas_centerY);
  287. make.size.mas_offset(CGSizeMake(90.0f, 67.0f));
  288. }];
  289. }
  290. /// 消息列表背景View
  291. - (void)youpaifinitChatBgView{
  292. UIView *panBgView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, 0.0f, KScreenWidth - 16.0f, KScreenHeight)];
  293. [self.view addSubview:panBgView];
  294. // 添加平移手势
  295. UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifhandlePan:)];
  296. [panBgView addGestureRecognizer:panGestureRecognizer];
  297. UIView *youpaipchatBgView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, panBgView.mj_w, KScreenHeight)];
  298. youpaipchatBgView.clipsToBounds = YES;
  299. [panBgView addSubview:youpaipchatBgView];
  300. self.youpaipchatBgView = youpaipchatBgView;
  301. }
  302. - (void)youpaifhandlePan:(UIPanGestureRecognizer*) recognizer{
  303. CGPoint translation = [recognizer translationInView:self.view];
  304. if(recognizer.state == UIViewAnimatingPositionStart){
  305. self.youpaipchatBgX = self.youpaipchatBgView.mj_x;
  306. }else if (recognizer.state == UIGestureRecognizerStateChanged) {
  307. self.youpaipchatBgView.mj_x = self.youpaipchatBgX + translation.x;
  308. if (self.youpaipchatBgView.mj_x < 0.0f) {
  309. self.youpaipchatBgView.mj_x = 0.0f;
  310. }else if (self.youpaipchatBgView.mj_x > KScreenWidth){
  311. self.youpaipchatBgView.mj_x = KScreenWidth;
  312. }
  313. }else if(recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) {
  314. CGFloat x = self.youpaipchatBgX;
  315. if(self.youpaipchatBgX == 0 && self.youpaipchatBgView.mj_x > KScreenWidth * 0.25f) {
  316. x = KScreenWidth;
  317. }
  318. if(self.youpaipchatBgX == KScreenWidth && self.youpaipchatBgView.mj_x < KScreenWidth - KScreenWidth * 0.25f) {
  319. x = 0.0f;
  320. }
  321. [UIView animateWithDuration:0.25f animations:^{
  322. self.youpaipchatBgView.mj_x = x;
  323. }];
  324. if (self.youpaipchatBgX == 0 && translation.x < -(KScreenWidth * 0.25)) {
  325. if (self.youpaipaudienceRecommendMoreAnchorBlock) {
  326. self.youpaipaudienceRecommendMoreAnchorBlock();
  327. }
  328. }
  329. }
  330. }
  331. /// 设置关闭对方音频按钮
  332. - (void)youpaifsetupCloseEnemyAudioBtn{
  333. UIButton *youpaipcloseEnemyAudioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  334. youpaipcloseEnemyAudioBtn.hidden = YES;
  335. [youpaipcloseEnemyAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_remote_audio_on"] forState:UIControlStateNormal];
  336. [youpaipcloseEnemyAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_remote_audio_off"] forState:UIControlStateSelected];
  337. [youpaipcloseEnemyAudioBtn addTarget:self action:@selector(youpaifcloseEnemyAudioBtnvClick:) forControlEvents:UIControlEventTouchUpInside];
  338. [self.view addSubview:youpaipcloseEnemyAudioBtn];
  339. self.youpaipcloseEnemyAudioBtn = youpaipcloseEnemyAudioBtn;
  340. [youpaipcloseEnemyAudioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  341. make.right.offset(-5.0f);
  342. make.top.offset(78.0f + StatusBarHeight + 270.0f - 5.0f - 19.0f);
  343. make.size.mas_offset(CGSizeMake(19.0f, 19.0f));
  344. }];
  345. }
  346. /// 远端女神点击
  347. - (void)youpaifinitRemoteVideoBtn{
  348. UIButton *youpaipremoteVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  349. youpaipremoteVideoBtn.hidden = YES;
  350. youpaipremoteVideoBtn.frame = CGRectMake(KScreenWidth / 2.0f + 1.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 1.0f, 270.0f);
  351. [youpaipremoteVideoBtn addTarget:self action:@selector(youpaifremoteVideoClick) forControlEvents:UIControlEventTouchUpInside];
  352. [self.view addSubview:youpaipremoteVideoBtn];
  353. self.youpaipremoteVideoBtn = youpaipremoteVideoBtn;
  354. }
  355. /// 设置关注View
  356. - (void)youpaifinitFollowView{
  357. UIButton *youpaipfollowBgV = [UIButton buttonWithType:UIButtonTypeCustom];
  358. youpaipfollowBgV.hidden = YES;
  359. youpaipfollowBgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
  360. youpaipfollowBgV.layer.cornerRadius = 11.0f;
  361. youpaipfollowBgV.clipsToBounds = YES;
  362. [youpaipfollowBgV addTarget:self action:@selector(youpaiffollowBgVClick) forControlEvents:UIControlEventTouchUpInside];
  363. [self.view addSubview:youpaipfollowBgV];
  364. self.youpaipfollowBgV = youpaipfollowBgV;
  365. [youpaipfollowBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  366. make.top.offset(StatusBarHeight + 70.0f + 10.0f);
  367. make.right.offset(-5.0f);
  368. make.height.offset(22.0f);
  369. make.width.lessThanOrEqualTo(100.0f);
  370. }];
  371. UIButton *youpaipfollowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  372. [youpaipfollowBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(30.0f, 16.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  373. youpaipfollowBtn.layer.cornerRadius = 8.0f;
  374. youpaipfollowBtn.clipsToBounds = YES;
  375. youpaipfollowBtn.titleLabel.font = LCFont(10.0f);
  376. [youpaipfollowBtn setTitle:@"关注" forState:UIControlStateNormal];
  377. [youpaipfollowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  378. [youpaipfollowBtn addTarget:self action:@selector(youpaiffollowBtnClick) forControlEvents:UIControlEventTouchUpInside];
  379. [youpaipfollowBgV addSubview:youpaipfollowBtn];
  380. self.youpaipfollowBtn = youpaipfollowBtn;
  381. [youpaipfollowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  382. make.right.offset(-3.0f);
  383. make.width.offset(30.0f);
  384. make.height.offset(16.0f);
  385. make.centerY.equalTo(youpaipfollowBgV.mas_centerY);
  386. }];
  387. UILabel *youpaipnickNameL = [[UILabel alloc] init];
  388. youpaipnickNameL.font = LCFont(12.0f);
  389. youpaipnickNameL.textColor = [UIColor whiteColor];
  390. [youpaipfollowBgV addSubview:youpaipnickNameL];
  391. self.youpaipnickNameL = youpaipnickNameL;
  392. [youpaipnickNameL mas_makeConstraints:^(MASConstraintMaker *make) {
  393. make.left.offset(10.0f);
  394. make.right.equalTo(youpaipfollowBtn.mas_left).offset(-5.0f);
  395. make.top.bottom.offset(0.0f);
  396. }];
  397. }
  398. - (void)youpaifremoteVideoClick{
  399. if (self.youpaipclickRemoteVideoViewBlock != nil) {
  400. self.youpaipclickRemoteVideoViewBlock(self.youpaipto_uid,self.youpaiptoRoomId);
  401. }
  402. }
  403. - (void)youpaiffollowBgVClick{
  404. [self youpaifshowUserInfoWithUserId:self.youpaipto_uid];
  405. }
  406. - (void)youpaiffollowBtnClick{
  407. self.youpaipfollowBgV.hidden = YES;
  408. [LCCommonHttp followUserId:self.youpaipto_uid liveId:@"1"];
  409. }
  410. - (void)youpaifreloadWithFollowModel:(YOUPAILCUserShowInfo *)model{
  411. self.youpaipnickNameL.text = model.youpaipnickname;
  412. self.youpaiptoRoomId = model.youpaiproom_id;
  413. if (model.youpaipis_follow == 0) {
  414. self.youpaipfollowBgV.hidden = NO;
  415. }else{
  416. self.youpaipfollowBgV.hidden = YES;
  417. }
  418. }
  419. - (void)youpaifsetupChatMessageView{
  420. //消息列表
  421. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(-1.0f, 0.0f, 276.0f, KScreenHeight * 0.35f) style:UITableViewStyleGrouped];
  422. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  423. tableView.showsVerticalScrollIndicator = NO;
  424. tableView.delegate = self;
  425. tableView.dataSource = self;
  426. tableView.backgroundColor = [UIColor clearColor];
  427. tableView.transform = CGAffineTransformMakeRotation(M_PI * 1.0001f);
  428. tableView.rowHeight = UITableViewAutomaticDimension;
  429. tableView.estimatedSectionHeaderHeight = 0.0f;
  430. tableView.estimatedSectionFooterHeight = 0.0f;
  431. self.youpaipchatTableView = tableView;
  432. [self.youpaipchatBgView addSubview:tableView];
  433. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  434. make.left.offset(-1.0f);
  435. make.bottom.offset(-(SafeHeight + 10.0f + 40.0f + 10.0f));
  436. make.size.mas_offset(CGSizeMake(276.0f, KScreenHeight * 0.35f));
  437. }];
  438. //发送消息输入框
  439. UITextField *sendMessageTF = [[UITextField alloc] init];
  440. sendMessageTF.placeholder = @"说点什么吧";
  441. sendMessageTF.font = LCFont15;
  442. sendMessageTF.textColor = HexColorFromRGB(0x333333);
  443. sendMessageTF.tintColor = ZYPinkColor;
  444. sendMessageTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)];
  445. sendMessageTF.leftViewMode = UITextFieldViewModeAlways;
  446. sendMessageTF.rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)];
  447. sendMessageTF.rightViewMode = UITextFieldViewModeAlways;
  448. sendMessageTF.backgroundColor = [UIColor whiteColor];
  449. sendMessageTF.returnKeyType = UIReturnKeyDone;
  450. sendMessageTF.delegate = self;
  451. sendMessageTF.hidden = YES;
  452. [self.view addSubview:sendMessageTF];
  453. self.youpaipsendMessageTF = sendMessageTF;
  454. [sendMessageTF mas_makeConstraints:^(MASConstraintMaker *make) {
  455. make.top.equalTo(tableView.mas_bottom).offset(10.0f);
  456. make.left.right.offset(0.0f);
  457. make.height.offset(44.0f);
  458. }];
  459. }
  460. /// 初始化 AgoraRtcEngineKit 类。
  461. - (void)youpaifinitializeAgoraEngine{
  462. self.youpaipagoraKit = [AgoraRtcEngineKit sharedEngineWithAppId:AgoraID delegate:self];
  463. //设置频道场景
  464. [self.youpaipagoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting];
  465. //设置用户角色
  466. [self.youpaipagoraKit setClientRole:[self youpaifclientRole]];
  467. //初始化并返回新分配的具有指定视频分辨率的AgoraVideoEncoderConfiguration对象
  468. AgoraVideoEncoderConfiguration *configuration = [[AgoraVideoEncoderConfiguration alloc] initWithSize:AgoraVideoDimension1280x720 frameRate:AgoraVideoFrameRateFps24 bitrate:AgoraVideoBitrateCompatible orientationMode:AgoraVideoOutputOrientationModeAdaptative mirrorMode:AgoraVideoMirrorModeAuto];
  469. [self.youpaipagoraKit setVideoEncoderConfiguration:configuration];
  470. //设置本地视频镜像模式
  471. [self.youpaipagoraKit setLocalVideoMirrorMode:AgoraVideoMirrorModeDisabled];
  472. //启用与Agora Web SDK的互操作性。
  473. [self.youpaipagoraKit enableWebSdkInteroperability:YES];
  474. //启用视频
  475. [self.youpaipagoraKit enableVideo];
  476. //设置视频源
  477. [self.youpaipagoraKit setExternalVideoSource:YES useTexture:YES sourceType:AgoraExternalVideoSourceTypeVideoFrame]; //只允许外部源
  478. }
  479. /// 设置本地视频
  480. - (void)youpaifsetupLocalVideo{
  481. self.youpaiplocalVideo.hidden = NO;
  482. AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  483. videoCanvas.uid = 0;
  484. videoCanvas.view = self.youpaiplocalVideo.youpaipvideoView;
  485. videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  486. // 设置本地视图。
  487. self.youpaiplocalCanvas = videoCanvas;
  488. [self.youpaipagoraKit setupLocalVideo:videoCanvas];
  489. }
  490. /// 设置美颜
  491. - (void)youpaifsetupbBeauty{
  492. //设置默认曝光度
  493. [self.youpaipmCamera setExposureValue:0];
  494. [self.youpaipmCamera startCapture];
  495. [[FUManager shareManager] loadFilter] ;
  496. [[FUManager shareManager] setAsyncTrackFaceEnable:NO];
  497. }
  498. /// 加入频道
  499. - (void)youpaifjoin{
  500. // self.youpaipheaderBgV.hidden = NO;
  501. [self youpaifjoinChannel];
  502. [self youpaifjoinChatRoom];
  503. }
  504. - (void)youpaifjoinChannel{
  505. @weakify(self);
  506. [self.youpaipagoraKit joinChannelByToken:nil channelId:self.youpaipliveModel.youpaiproomid info:nil uid:[[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
  507. @strongify(self);
  508. //检查扬声器是否已启用
  509. if([self.youpaipagoraKit isSpeakerphoneEnabled]){
  510. //设置扬声器
  511. [self.youpaipagoraKit setEnableSpeakerphone:YES];
  512. }
  513. // 设置不自动锁屏
  514. [UIApplication sharedApplication].idleTimerDisabled = YES;
  515. }];
  516. }
  517. /// 离开频道
  518. - (void)youpaifleaveChannel{
  519. [self.youpaippkdataView youpaifstopTimer];
  520. [self.youpaipagoraKit setupLocalVideo:nil];
  521. // 离开频道。
  522. [self.youpaipagoraKit leaveChannel:nil];
  523. self.youpaipagoraKit.delegate = nil;
  524. // 如果是女神就停止本地视频预览和视频
  525. if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
  526. [self.youpaipagoraKit stopPreview];
  527. [self.youpaipmCamera stopCapture];
  528. }
  529. self.youpaipagoraKit = nil;
  530. [self youpaifleaveChatRoom];
  531. }
  532. /// 加入聊天室
  533. - (void)youpaifjoinChatRoom{
  534. @weakify(self);
  535. NIMChatroomEnterRequest *request = [[NIMChatroomEnterRequest alloc] init];
  536. request.roomId = self.youpaipliveModel.youpaiproomid;
  537. NSDictionary *roomNotifyExt = @{
  538. @"is_comein_room_hide":@(self.youpaipliveModel.youpaipis_comein_room_hide)
  539. };
  540. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:roomNotifyExt options:0 error:0];
  541. NSString *dataStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  542. request.roomNotifyExt = dataStr;
  543. [[[NIMSDK sharedSDK] chatroomManager] enterChatroom:request
  544. completion:^(NSError *error,NIMChatroom *chatroom,NIMChatroomMember *me) {
  545. @strongify(self);
  546. if (error == nil){ // 加入成功
  547. /// 监听聊天室连接变化
  548. [[NIMSDK sharedSDK].chatroomManager addDelegate:self];
  549. /// 添加聊天委托
  550. [[NIMSDK sharedSDK].chatManager addDelegate:self];
  551. if (self.youpaifclientRole == AgoraClientRoleAudience && self.youpaipliveModel.youpaipuser_info.youpaipis_follow == 0) {
  552. [self.youpaipmessages addObject:self.youpaipliveModel];
  553. [self youpaifreloadTableView];
  554. }
  555. if (self.youpaipliveModel.youpaipis_fly == 1) {
  556. [self youpaifhandleBarrageAttachment:self.youpaipliveModel.youpaipu_data];
  557. }
  558. if (self.youpaipliveModel.youpaipis_fly_car == 1) {
  559. self.youpaipcarAttachment = self.youpaipliveModel.youpaipcar_data;
  560. [self youpaifstartPlayCarSvga];
  561. }
  562. if (self.youpaipliveModel.youpaipis_fly_noble == 1) {
  563. [self youpaifhandleVipBarrageAttachment:self.youpaipliveModel.youpaipb_box_data];
  564. }
  565. }else{ // 加入失败
  566. NSString *toast = [NSString stringWithFormat:@"%@ code:%zd",
  567. @"进入失败",
  568. error.code];
  569. }
  570. }];
  571. }
  572. /// 离开聊天室
  573. - (void)youpaifleaveChatRoom{
  574. @weakify(self);
  575. [[[NIMSDK sharedSDK] chatroomManager] exitChatroom:self.youpaipliveModel.youpaiproomid completion:^(NSError * _Nullable error) {
  576. @strongify(self);
  577. [[NIMSDK sharedSDK].chatroomManager removeDelegate:self];
  578. [[NIMSDK sharedSDK].chatManager removeDelegate:self];
  579. }];
  580. }
  581. /// 停止其他应用音频
  582. - (void)youpaifsetupAudioSession{
  583. NSError *error;
  584. AVAudioSession *session = [AVAudioSession sharedInstance];
  585. [session setCategory:AVAudioSessionCategoryPlayback error:&error];
  586. [session setActive:YES error:&error];
  587. }
  588. /// UI添加消息
  589. - (void)youpaifuiAddMessages:(NSArray<NIMMessage *> *)messages{
  590. NSArray <NIMMessage *>* newMessages = [self youpaifdealMessage:messages];
  591. if (newMessages.count != 0) {
  592. [self.youpaipmessages insertObjects:newMessages atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, newMessages.count)]];
  593. // [self.messages addObjectsFromArray:newMessages];
  594. NIMMessage *joinLiveMessage = nil;
  595. for (NSInteger i = 0; i < self.youpaipmessages.count; i ++) {
  596. NIMMessage *msg = self.youpaipmessages[i];
  597. if ([msg isKindOfClass:[NIMMessage class]]) {
  598. if (msg.session.sessionType == NIMSessionTypeChatroom
  599. && msg.messageType == NIMMessageTypeNotification){ /// 如果是聊天室并且消息类型为通知类型
  600. NIMNotificationObject *object = msg.messageObject;
  601. if (![object.content isKindOfClass:[NIMUnsupportedNotificationContent class]]) {
  602. NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)object.content;
  603. if (content.eventType == NIMChatroomEventTypeEnter) { /// 有成员加入聊天室
  604. if (joinLiveMessage == nil) {
  605. joinLiveMessage = msg;
  606. }
  607. [self.youpaipmessages removeObject:msg];
  608. i --;
  609. }
  610. }
  611. }
  612. }
  613. }
  614. if (joinLiveMessage != nil) {
  615. [self.youpaipmessages insertObject:joinLiveMessage atIndex:0];
  616. // [self.messages addObject:joinLiveMessage];
  617. NSTimeInterval timeBetween = [[NSDate new] timeIntervalSinceDate:self.youpaipjoinLiveMessageDate];
  618. if (timeBetween >= 3.0f) {
  619. [self.youpaipmessages removeObject:joinLiveMessage];
  620. }
  621. // else{
  622. // [self performSelector:@selector(removeJoinLiveMessage:) withObject:joinLiveMessage afterDelay:3.0];
  623. // }
  624. }
  625. [self youpaifreloadTableView];
  626. }
  627. }
  628. - (void)youpaifreloadTableView{
  629. [self.youpaipchatTableView reloadData];
  630. if (self.youpaipmessages.count != 0) {
  631. [self.youpaipchatTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  632. }
  633. // }
  634. }
  635. /// 聊天室消息处理
  636. - (NSArray <NIMMessage *>*)youpaifdealMessage:(NSArray <NIMMessage *>*)messages{
  637. NSMutableArray *n_messages = [NSMutableArray array];
  638. /// 聊天室通知处理
  639. for (NIMMessage *message in messages) {
  640. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[message.from] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  641. // NIMUser* user = users[0];
  642. }];
  643. if (message.session.sessionType == NIMSessionTypeChatroom
  644. && message.messageType == NIMMessageTypeNotification){ /// 如果是聊天室并且消息类型为通知类型
  645. NIMNotificationObject *object = message.messageObject;
  646. if (![object.content isKindOfClass:[NIMUnsupportedNotificationContent class]]) {
  647. NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)object.content;
  648. NSString *fromId = nil;
  649. for (NIMChatroomNotificationMember *memebr in content.targets) {
  650. fromId = memebr.userId;
  651. }
  652. if (content.eventType == NIMChatroomEventTypeEnter) { /// 有成员加入聊天室
  653. if (![message.from isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
  654. NSData *jsonData = [content.notifyExt dataUsingEncoding:NSUTF8StringEncoding];
  655. if (jsonData != nil) {
  656. NSError *err;
  657. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  658. if (!([dic.allKeys containsObject:@"is_comein_room_hide"] && [[dic objectForKey:@"is_comein_room_hide"] integerValue] == 1)) {
  659. [n_messages insertObject:message atIndex:0];
  660. self.youpaipjoinLiveMessageDate = [NSDate new];
  661. }
  662. }
  663. }
  664. [self youpaifuploadLiveMemberCount];
  665. [self youpaifmemberJoinLiveWithUserId:message.from];
  666. // [self loadLiveMemberList];
  667. }else if(content.eventType == NIMChatroomEventTypeExit){ /// 有成员离开聊天室
  668. // [n_messages addObject:message];
  669. [self youpaifuploadLiveMemberCount];
  670. [self youpaifmemberLeaveLiveWithUserId:message.from];
  671. // [self loadLiveMemberList];
  672. }else if(content.eventType == NIMChatroomEventTypeKicked){ /// 聊天室成员被踢
  673. [self youpaifuploadLiveMemberCount];
  674. // [self loadLiveMemberList];
  675. }else if(content.eventType == NIMChatroomEventTypeKicked){ /// 聊天室成员被踢
  676. [self youpaifuploadLiveMemberCount];
  677. // [self loadLiveMemberList];
  678. }else if (content.eventType == NIMChatroomEventTypeAddMute){ // 成员被禁言
  679. [n_messages insertObject:message atIndex:0];
  680. if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  681. [ZCHUDHelper showTitle:@"你被禁言"];
  682. }
  683. }else if (content.eventType == NIMChatroomEventTypeRemoveMute){ // 成员被取消禁言
  684. [n_messages insertObject:message atIndex:0];
  685. if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  686. [ZCHUDHelper showTitle:@"你被取消禁言"];
  687. }
  688. }else if (content.eventType == NIMChatroomEventTypeAddManager){ // 设置为管理员
  689. [n_messages insertObject:message atIndex:0];
  690. [[YOUPAILZLiveManagerListUtils shared] youpaifreloadManagerListWithLiveId:self.youpaipliveModel.youpaiplive_id];
  691. if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  692. [ZCHUDHelper showTitle:@"你被设置为管理员"];
  693. }
  694. }else if (content.eventType == NIMChatroomEventTypeRemoveManager){ // 移除管理员
  695. [n_messages insertObject:message atIndex:0];
  696. [[YOUPAILZLiveManagerListUtils shared] youpaifreloadManagerListWithLiveId:self.youpaipliveModel.youpaiplive_id];
  697. if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  698. [ZCHUDHelper showTitle:@"你被取消设置为管理员"];
  699. }
  700. }else if (content.eventType == NIMChatroomEventTypeAddMuteTemporarily){ // 聊天室成员被临时禁言
  701. [n_messages insertObject:message atIndex:0];
  702. if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  703. [ZCHUDHelper showTitle:@"你被禁言"];
  704. }
  705. }else if (content.eventType == NIMChatroomEventTypeRemoveMuteTemporarily){ // 聊天室成员被解除临时禁言
  706. [n_messages insertObject:message atIndex:0];
  707. if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  708. [ZCHUDHelper showTitle:@"你被取消禁言"];
  709. }
  710. }
  711. }
  712. }else if (message.messageType == NIMMessageTypeText){ // 文本消息
  713. [n_messages insertObject:message atIndex:0];
  714. }else if(message.messageType == NIMMessageTypeCustom){ // 自定义消息
  715. NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
  716. if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]]){ // 礼物
  717. YOUPAILCGiftAttachment *attachment = (YOUPAILCGiftAttachment *)object.attachment;
  718. YOUPAILZLiveGIftModel *youpaipgiftModel = [[YOUPAILZLiveGIftModel alloc] init];
  719. youpaipgiftModel.youpaipavatar = attachment.from_avatar;
  720. youpaipgiftModel.youpaipnickName = attachment.from_nickname;
  721. youpaipgiftModel.youpaipgiftDesc = [NSString stringWithFormat:@"赠送了%@",attachment.gift_name];
  722. youpaipgiftModel.youpaipgiftImage = attachment.gift_url;
  723. youpaipgiftModel.youpaipgiftCount = attachment.gift_count;
  724. youpaipgiftModel.youpaipuser_id = attachment.from_uid;
  725. youpaipgiftModel.youpaipgift_id = attachment.gift_id;
  726. youpaipgiftModel.youpaipgift_svga = attachment.gift_svga;
  727. youpaipgiftModel.youpaipgift_type = attachment.gift_type;
  728. if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqual:message.from]) {
  729. [self.youpaipgifts insertObject:youpaipgiftModel atIndex:0];
  730. }else{
  731. [self.youpaipgifts addObject:youpaipgiftModel];
  732. }
  733. [self youpaifeditGiftView];
  734. [n_messages insertObject:message atIndex:0];
  735. }
  736. if ([object.attachment isKindOfClass:[YOUPAILZGuardAttachment class]]){ // 守护
  737. YOUPAILZGuardAttachment *attachment = (YOUPAILZGuardAttachment *)object.attachment;
  738. YOUPAILZLiveGIftModel *youpaipgiftModel = [[YOUPAILZLiveGIftModel alloc] init];
  739. youpaipgiftModel.youpaipavatar = ((NIMMessageChatroomExtension *)message.messageExt).roomAvatar;
  740. youpaipgiftModel.youpaipnickName = ((NIMMessageChatroomExtension *)message.messageExt).roomNickname;
  741. youpaipgiftModel.youpaipgiftDesc = [NSString stringWithFormat:@"赠送了%@",attachment.guard_name];
  742. youpaipgiftModel.youpaipgiftImage = attachment.guard_url;
  743. youpaipgiftModel.youpaipgiftCount = attachment.guard_count;
  744. youpaipgiftModel.youpaipuser_id = attachment.from_uid;
  745. youpaipgiftModel.youpaipgift_id = -1;
  746. youpaipgiftModel.youpaipgift_svga = attachment.gift_svga;
  747. youpaipgiftModel.youpaipgift_type = attachment.gift_type;
  748. if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqual:message.from]) {
  749. [self.youpaipgifts insertObject:youpaipgiftModel atIndex:0];
  750. }else{
  751. [self.youpaipgifts addObject:youpaipgiftModel];
  752. }
  753. [self youpaifeditGiftView];
  754. [n_messages insertObject:message atIndex:0];
  755. }
  756. if ([object.attachment isKindOfClass:[YOUPAILZLiveInfoUpdateAttachment class]]) { //直播间信息
  757. YOUPAILZLiveInfoUpdateAttachment* attachment = (YOUPAILZLiveInfoUpdateAttachment*)object.attachment;
  758. [LCSaveData saveLiveRankTopThere:attachment.rank_top_three];
  759. if (self.youpaipliveInfoUpdateBlock != nil) {
  760. self.youpaipliveInfoUpdateBlock(attachment.anchor_charm,attachment.fans,attachment.anchor_rank_info);
  761. }
  762. }
  763. if ([object.attachment isKindOfClass:[YOUPAILZLiveCloseAttachment class]]) { //直播结束
  764. if (self.youpaipliveCloseBlock != nil) {
  765. self.youpaipliveCloseBlock();
  766. }
  767. }
  768. if ([object.attachment isKindOfClass:[YOUPAILZLivePKAttachment class]]) { //pk
  769. YOUPAILZLivePKAttachment *attachment = (YOUPAILZLivePKAttachment*)object.attachment;
  770. if (self.youpaippkBlock != nil) {
  771. self.youpaippkBlock(attachment);
  772. }
  773. if([attachment.type isEqual:@"hangup"]){
  774. self.youpaippkdataView.youpaipattachment = nil;
  775. self.youpaippkdataView.hidden = YES;
  776. self.youpaipdrawImgV.hidden = YES;
  777. }
  778. }
  779. if ([object.attachment isKindOfClass:[YOUPAILZLiveLianMaiAttachment class]]) { //lianmai
  780. YOUPAILZLiveLianMaiAttachment *attachment = (YOUPAILZLiveLianMaiAttachment*)object.attachment;
  781. if (self.youpaiplianmaiBlock != nil) {
  782. self.youpaiplianmaiBlock(attachment);
  783. }
  784. }
  785. if ([object.attachment isKindOfClass:[YOUPAILZLivePKDataAttachment class]]) { //pk数据消息
  786. if (self.youpaippkdataView.youpaipattachment == nil){
  787. self.youpaippkdataView.hidden = NO;
  788. }
  789. YOUPAILZLivePKDataAttachment *attachment = (YOUPAILZLivePKDataAttachment*)object.attachment;
  790. [self.youpaippkdataView youpaifreloadWithAttachment:attachment];
  791. if (self.youpaipresetPKDataBlock != nil) {
  792. self.youpaipresetPKDataBlock(attachment);
  793. }
  794. }
  795. if ([object.attachment isKindOfClass:[YOUPAILZLiveFollowAttachment class]]) { //关注信息
  796. [n_messages insertObject:message atIndex:0];
  797. }
  798. if ([object.attachment isKindOfClass:[YOUPAILZLiveRankAttachment class]]) { //排行信息
  799. YOUPAILZLiveRankAttachment *attachment = (YOUPAILZLiveRankAttachment*)object.attachment;
  800. if (self.youpaipliveMemberListChangeBlock != nil) {
  801. self.youpaipliveMemberListChangeBlock(attachment.rank);
  802. }
  803. }
  804. if ([object.attachment isKindOfClass:[YOUPAILZLiveBarrageAttachment class]]) { //弹幕信息
  805. YOUPAILZLiveBarrageAttachment *attachment = (YOUPAILZLiveBarrageAttachment*)object.attachment;
  806. [self youpaifhandleBarrageAttachment:attachment];
  807. }
  808. if ([object.attachment isKindOfClass:[YOUPAILZLiveVipBarrageAttachment class]]) { //VIP弹幕信息
  809. YOUPAILZLiveVipBarrageAttachment *attachment = (YOUPAILZLiveVipBarrageAttachment*)object.attachment;
  810. [self youpaifhandleVipBarrageAttachment:attachment];
  811. }
  812. if ([object.attachment isKindOfClass:[YOUPAILZLiveCarAttachment class]]) { //座驾
  813. YOUPAILZLiveCarAttachment *attachment = (YOUPAILZLiveCarAttachment*)object.attachment;
  814. self.youpaipcarAttachment = attachment;
  815. [self youpaifstartPlayCarSvga];
  816. }
  817. if ([object.attachment isKindOfClass:[YOUPAILZLiveManageAttachment class]]) { //管理
  818. YOUPAILZLiveManageAttachment *attachment = (YOUPAILZLiveManageAttachment*)object.attachment;
  819. [n_messages insertObject:message atIndex:0];
  820. if ([message.from isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  821. [ZCHUDHelper showTitle:attachment.user_des];
  822. [self youpaifleaveChannel];
  823. [self.navigationController popViewControllerAnimated:YES];
  824. }
  825. }
  826. }
  827. }
  828. return n_messages.copy;
  829. }
  830. /// 处理VIP弹幕消息
  831. - (void)youpaifhandleVipBarrageAttachment:(YOUPAILZLiveVipBarrageAttachment *)barrageAttachment{
  832. YOUPAIRCDDanmaku *danmaku = [[YOUPAIRCDDanmaku alloc]init];
  833. danmaku.playView = [YOUPAILZLiveBarrageTool youpaifhandleVipBarrageAttachment:barrageAttachment];
  834. [self.view sendDanmaku:danmaku];
  835. }
  836. /// 处理弹幕消息
  837. - (void)youpaifhandleBarrageAttachment:(YOUPAILZLiveBarrageAttachment *)barrageAttachment{
  838. // YOUPAIRCDDanmaku *danmaku = [[YOUPAIRCDDanmaku alloc]init];
  839. // danmaku.playView = [YOUPAILZLiveBarrageTool youpaifhandleBarrageAttachment:barrageAttachment];
  840. // [self.view sendDanmaku:danmaku];
  841. }
  842. /// 有成员加入直播间
  843. - (void)youpaifmemberJoinLiveWithUserId:(NSString *)userId{
  844. if (self.youpaifclientRole == AgoraClientRoleBroadcaster && ![userId isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
  845. [LCHttpHelper requestWithURLString:MemberJoinLive parameters:@{@"room_id":self.youpaipliveModel.youpaiproomid,@"live_id":self.youpaipliveModel.youpaiplive_id,@"comein_user_id":userId} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  846. NSDictionary* dict = (NSDictionary*)responseObject;
  847. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  848. if (code == 0) {
  849. }
  850. } failure:^(NSError *error) {
  851. }];
  852. }
  853. }
  854. /// 有成员离开直播间
  855. - (void)youpaifmemberLeaveLiveWithUserId:(NSString *)userId{
  856. if (self.youpaifclientRole == AgoraClientRoleBroadcaster && ![userId isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
  857. [LCHttpHelper requestWithURLString:MemberOutLive parameters:@{@"room_id":self.youpaipliveModel.youpaiproomid,@"live_id":self.youpaipliveModel.youpaiplive_id,@"out_user_id":userId} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  858. NSDictionary* dict = (NSDictionary*)responseObject;
  859. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  860. if (code == 0) {
  861. }
  862. } failure:^(NSError *error) {
  863. }];
  864. }
  865. }
  866. /// 更新聊天室人员数
  867. - (void)youpaifuploadLiveMemberCount{
  868. @weakify(self);
  869. [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomInfo:self.youpaipliveModel.youpaiproomid completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom) {
  870. if (!error) {
  871. @strongify(self);
  872. if (self.youpaipliveMemberCountChangeBlock != nil) {
  873. NSInteger count = chatroom.onlineUserCount;
  874. if (self.youpaipliveModel.youpaipis_virtual != 1) {
  875. count = chatroom.onlineUserCount - 1;
  876. }
  877. self.youpaipliveMemberCountChangeBlock(count);
  878. }
  879. }
  880. }];
  881. }
  882. /// 处理礼物
  883. - (void)youpaifeditGiftView{
  884. NSInteger maxCount = 2;
  885. NSInteger count = maxCount - self.youpaipgiftViews.count;
  886. if (count > self.youpaipgifts.count) {
  887. count = self.youpaipgifts.count;
  888. }
  889. if (count <= 0) {
  890. for (NSInteger i = 0; i < self.youpaipgiftViews.count; i ++) {
  891. if (self.youpaipgifts.count <= 0) {
  892. return;
  893. }
  894. YOUPAILZLiveGIftModel *youpaipgiftModel = self.youpaipgifts[i];
  895. YOUPAILZLiveGiftView *giftView = nil;
  896. for (YOUPAILZLiveGiftView *f_giftView in self.youpaipgiftViews) {
  897. if (f_giftView.youpaipgiftModel.youpaipuser_id == youpaipgiftModel.youpaipuser_id && f_giftView.youpaipgiftModel.youpaipgift_id == youpaipgiftModel.youpaipgift_id && youpaipgiftModel.youpaipgift_id != -1) {
  898. giftView = f_giftView;
  899. break;
  900. }
  901. }
  902. if (giftView != nil) {
  903. i --;
  904. [giftView youpaifupdateGiftCount:youpaipgiftModel.youpaipgiftCount];
  905. [self.youpaipgifts removeObject:youpaipgiftModel];
  906. if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
  907. [self.youpaipsvgas addObject:youpaipgiftModel];
  908. [self youpaifstartPlaySvga];
  909. }
  910. [self.youpaipgifts removeObject:youpaipgiftModel];
  911. }
  912. }
  913. }else{
  914. for (NSInteger i = 0; i < count; i ++) {
  915. if (self.youpaipgifts.count <= 0) {
  916. return;
  917. }
  918. YOUPAILZLiveGIftModel *youpaipgiftModel = self.youpaipgifts[i];
  919. YOUPAILZLiveGiftView *giftView = nil;
  920. for (YOUPAILZLiveGiftView *f_giftView in self.youpaipgiftViews) {
  921. if (f_giftView.youpaipgiftModel.youpaipuser_id == youpaipgiftModel.youpaipuser_id && f_giftView.youpaipgiftModel.youpaipgift_id == youpaipgiftModel.youpaipgift_id && youpaipgiftModel.youpaipgift_id != -1) {
  922. giftView = f_giftView;
  923. break;
  924. }
  925. }
  926. if (giftView != nil) {
  927. i --;
  928. [giftView youpaifupdateGiftCount:youpaipgiftModel.youpaipgiftCount];
  929. [self.youpaipgifts removeObject:youpaipgiftModel];
  930. if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
  931. [self.youpaipsvgas addObject:youpaipgiftModel];
  932. [self youpaifstartPlaySvga];
  933. }
  934. }else{
  935. if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
  936. [self.youpaipsvgas addObject:youpaipgiftModel];
  937. [self youpaifstartPlaySvga];
  938. }
  939. YOUPAILZLiveGiftView *giftView = [[YOUPAILZLiveGiftView alloc] initWithModel:youpaipgiftModel];
  940. [giftView addTarget:self action:@selector(youpaifgiftAnimationViewClick:) forControlEvents:UIControlEventTouchUpInside];
  941. NSInteger tag = 0;
  942. if (self.youpaipgiftViews.count == 1){
  943. if (self.youpaipgiftViews.lastObject.tag == 1) {
  944. tag = 0;
  945. }else{
  946. tag = 1;
  947. }
  948. }
  949. giftView.tag = tag;
  950. [self.youpaipchatBgView addSubview:giftView];
  951. [self.youpaipgiftViews addObject:giftView];
  952. if (giftView != nil) {
  953. UIView *view = self.youpaipgiftViews.lastObject;
  954. if (view != nil) {
  955. [giftView mas_makeConstraints:^(MASConstraintMaker *make) {
  956. make.left.offset(-200.0f);
  957. if (view.tag == 0) {
  958. make.bottom.equalTo(self.youpaipchatTableView.mas_top).offset(-15.0f);
  959. }else{
  960. make.bottom.equalTo(self.youpaipchatTableView.mas_top).offset(-30.0f-42.0f);
  961. }
  962. make.height.offset(42.0f);
  963. }];
  964. }
  965. }
  966. [giftView.superview layoutIfNeeded];
  967. [giftView youpaifshowAnimation];
  968. giftView.delegate = self;
  969. [self.youpaipgifts removeObject:youpaipgiftModel];
  970. }
  971. }
  972. }
  973. }
  974. - (void)youpaifanimatiomFinishWithView:(YOUPAILZLiveGiftView *)liveGiftView{
  975. [self.youpaipgiftViews removeObject:liveGiftView];
  976. [liveGiftView removeFromSuperview];
  977. [self youpaifeditGiftView];
  978. }
  979. - (void)youpaifstartPlayCarSvga{
  980. if (self.youpaipisPlayCarSvga == NO && self.youpaipcarAttachment != nil) {
  981. self.youpaipisPlayCarSvga = YES;
  982. [self.youpaipcarSvgaPlayer stopAnimation];
  983. if (self.youpaipcarAttachment.car_big_preview_img_svga.length != 0) {
  984. self.youpaipcarSvgaPlayer.hidden = NO;
  985. }
  986. NSString* svgaName = [[self.youpaipcarAttachment.car_big_preview_img_svga componentsSeparatedByString:@"/"] lastObject];
  987. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  988. NSString *svgaPath =[svgaCanchesPath stringByAppendingPathComponent:svgaName];
  989. if (![[NSFileManager defaultManager] fileExistsAtPath:svgaPath]){
  990. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,self.youpaipcarAttachment.car_big_preview_img_svga];
  991. @weakify(self);
  992. [self.youpaipcarParser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  993. @strongify(self);
  994. if (videoItem != nil) {
  995. self.youpaipcarSvgaPlayer.videoItem = videoItem;
  996. [self.youpaipcarSvgaPlayer startAnimation];
  997. }
  998. } failureBlock:^(NSError * _Nullable error) {
  999. @strongify(self);
  1000. self.youpaipcarSvgaPlayer.hidden = YES;
  1001. self.youpaipisPlayCarSvga = NO;
  1002. [self youpaifstartPlayCarSvga];
  1003. }];
  1004. [LCTools giftSVGAWithSvgaUrlStr:self.youpaipcarAttachment.car_big_preview_img_svga];
  1005. }else{
  1006. @weakify(self);
  1007. [self.youpaipcarParser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:self.youpaipcarAttachment.car_big_preview_img_svga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  1008. @strongify(self);
  1009. if (videoItem != nil) {
  1010. self.youpaipcarSvgaPlayer.videoItem = videoItem;
  1011. [self.youpaipcarSvgaPlayer startAnimation];
  1012. }
  1013. } failureBlock:^(NSError * _Nonnull error) {
  1014. @strongify(self);
  1015. self.youpaipcarSvgaPlayer.hidden = YES;
  1016. self.youpaipisPlayCarSvga = NO;
  1017. [self youpaifstartPlayCarSvga];
  1018. }];
  1019. }
  1020. self.youpaipcarAttachment = nil;
  1021. }
  1022. }
  1023. - (void)youpaifstartPlaySvga{
  1024. if (self.youpaipisPlaySvga == NO && self.youpaipsvgas.count != 0) {
  1025. self.youpaipisPlaySvga = YES;
  1026. YOUPAILZLiveGIftModel* youpaipgiftModel = self.youpaipsvgas[0];
  1027. [self.youpaipsvgaPlayer stopAnimation];
  1028. if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
  1029. self.youpaipsvgaPlayer.hidden = NO;
  1030. }
  1031. NSString* svgaName = [[youpaipgiftModel.youpaipgift_svga componentsSeparatedByString:@"/"] lastObject];
  1032. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  1033. if (![LCTools giftSVGAWithSvgaUrlStr:youpaipgiftModel.youpaipgift_svga]){
  1034. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,youpaipgiftModel.youpaipgift_svga];
  1035. @weakify(self);
  1036. [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  1037. @strongify(self);
  1038. if (videoItem != nil) {
  1039. self.youpaipsvgaPlayer.videoItem = videoItem;
  1040. [self.youpaipsvgaPlayer startAnimation];
  1041. }
  1042. } failureBlock:^(NSError * _Nullable error) {
  1043. @strongify(self);
  1044. self.youpaipsvgaPlayer.hidden = YES;
  1045. self.youpaipisPlaySvga = NO;
  1046. [self youpaifstartPlaySvga];
  1047. }];
  1048. [LCTools giftSVGAWithSvgaUrlStr:youpaipgiftModel.youpaipgift_svga];
  1049. }else{
  1050. @weakify(self);
  1051. [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:youpaipgiftModel.youpaipgift_svga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  1052. @strongify(self);
  1053. if (videoItem != nil) {
  1054. self.youpaipsvgaPlayer.videoItem = videoItem;
  1055. [self.youpaipsvgaPlayer startAnimation];
  1056. }
  1057. } failureBlock:^(NSError * _Nonnull error) {
  1058. @strongify(self);
  1059. self.youpaipsvgaPlayer.hidden = YES;
  1060. self.youpaipisPlaySvga = NO;
  1061. [self youpaifstartPlaySvga];
  1062. }];
  1063. }
  1064. [self.youpaipsvgas removeObject:youpaipgiftModel];
  1065. }
  1066. }
  1067. #pragma mark - Click
  1068. //关闭对方音频事件
  1069. - (void)youpaifcloseEnemyAudioBtnvClick:(UIButton *)sender{
  1070. sender.selected = !sender.selected;
  1071. [self.youpaipagoraKit muteRemoteAudioStream:[self.youpaipto_uid integerValue] mute:sender.selected];
  1072. }
  1073. ///// 直播间人员列表
  1074. //- (void)loadLiveMemberList{
  1075. // NIMChatroomMemberRequest *request = [[NIMChatroomMemberRequest alloc] init];
  1076. // request.roomId = self.youpaipliveModel.roomid;
  1077. // request.type = NIMChatroomFetchMemberTypeTemp;
  1078. // request.limit = 50;
  1079. // __weak typeof(self) weakSelf = self;
  1080. // [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomMembers:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
  1081. // if (!error && weakSelf.youpaipliveMemberListChangeBlock) {
  1082. // weakSelf.youpaipliveMemberListChangeBlock(members);
  1083. // }
  1084. // }];
  1085. //}
  1086. /// 左边小礼物动画点击
  1087. - (void)youpaifgiftAnimationViewClick:(YOUPAILZLiveGiftView *)sender{
  1088. [self youpaifshowUserInfoWithUserId:[NSString stringWithFormat:@"%@",@(sender.youpaipgiftModel.youpaipuser_id)]];
  1089. }
  1090. //键盘即将隐藏
  1091. - (void)youpaifkeyboardWillHide:(NSNotification *)note{
  1092. [self.view layoutIfNeeded];
  1093. [self.youpaipchatTableView mas_updateConstraints:^(MASConstraintMaker *make) {
  1094. make.bottom.offset(-(SafeHeight + 16.0f + 40.0f + 10.0f));
  1095. }];
  1096. }
  1097. //键盘即将弹出
  1098. - (void)youpaifkeyboardWillShow:(NSNotification *)note{
  1099. CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  1100. CGFloat keyboardH = keyboardF.size.height;
  1101. [self.youpaipchatTableView mas_updateConstraints:^(MASConstraintMaker *make) {
  1102. make.bottom.offset(-(SafeHeight + 16.0f + 40.0f + 10.0f) - keyboardH + 12.0f + SafeHeight);
  1103. }];
  1104. }
  1105. //设置是否推送视频流
  1106. - (void)youpaifsetupMuteLocalVideoStream:(NSNotification *)note{
  1107. if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
  1108. if ([note.name isEqual:UIApplicationWillResignActiveNotification]) {
  1109. [self.youpaipagoraKit muteLocalVideoStream:YES];
  1110. }else{
  1111. [self.youpaipagoraKit muteLocalVideoStream:NO];
  1112. }
  1113. }
  1114. }
  1115. // 异常退出登录
  1116. - (void)youpaiflogoutCloseLive{
  1117. if (self.youpaipliveCloseBlock) {
  1118. self.youpaipliveCloseBlock();
  1119. }
  1120. }
  1121. #pragma mark - SVGAPlayerDelegate
  1122. - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player{
  1123. if (self.youpaipsvgaPlayer == player) {
  1124. self.youpaipsvgaPlayer.hidden = YES;
  1125. self.youpaipisPlaySvga = NO;
  1126. [self youpaifstartPlaySvga];
  1127. }else{
  1128. self.youpaipcarSvgaPlayer.hidden = YES;
  1129. self.youpaipisPlayCarSvga = NO;
  1130. [self youpaifstartPlayCarSvga];
  1131. }
  1132. }
  1133. #pragma mark - NIMChatroomManagerDelegate
  1134. /// 被踢回调
  1135. - (void)chatroomBeKicked:(NIMChatroomBeKickedResult *)result{
  1136. NSLog(@"被踢了");
  1137. }
  1138. #pragma mark - NIMChatManagerDelegate
  1139. /// 发送消息完成回调
  1140. - (void)sendMessage:(NIMMessage *)message didCompleteWithError:(nullable NSError *)error{
  1141. NIMSession *session = message.session;
  1142. if (![session.sessionId isEqual:self.youpaipliveModel.youpaiproomid]){
  1143. return;
  1144. }
  1145. if (error == nil) {
  1146. [self youpaifuiAddMessages:@[message]];
  1147. }else if(error.code == 13004){
  1148. [ZCHUDHelper showTitle:@"您已被禁言,不能发送消息"];
  1149. }
  1150. }
  1151. /// 收到消息回调
  1152. - (void)onRecvMessages:(NSArray<NIMMessage *> *)messages{
  1153. /// 新消息处理
  1154. NIMMessage *message = messages.firstObject;
  1155. NIMSession *session = message.session;
  1156. if (![session.sessionId isEqual:self.youpaipliveModel.youpaiproomid] || !messages.count){
  1157. return;
  1158. }
  1159. [self youpaifuiAddMessages:messages];
  1160. // [self.interactor markRead:NO];
  1161. }
  1162. #pragma mark - AgoraRtcEngineDelegate
  1163. /// 重新连接
  1164. - (void)rtcEngine:(AgoraRtcEngineKit *)engine didRejoinChannel:(NSString * _Nonnull)channel withUid:(NSUInteger)uid elapsed:(NSInteger)elapsed{
  1165. if (self.youpaipisNetworkInterrupt && self.youpaifclientRole == AgoraClientRoleBroadcaster) {
  1166. self.youpaipisNetworkInterrupt = NO;
  1167. self.youpaippkdataView.hidden = YES;
  1168. self.youpaippkdataView.youpaipattachment = nil;
  1169. [self.youpaipagoraKit stopChannelMediaRelay];
  1170. if (self.youpaipliveCloseBlock != nil) {
  1171. self.youpaipliveCloseBlock();
  1172. }
  1173. }
  1174. }
  1175. ///网络连接中断,且 SDK 无法在 10 秒内连接服务器回调
  1176. - (void)rtcEngineConnectionDidLost:(AgoraRtcEngineKit *_Nonnull)engine{
  1177. self.youpaipisNetworkInterrupt = YES;
  1178. }
  1179. // 远端视频状态发生改变回调。
  1180. - (void)rtcEngine:(AgoraRtcEngineKit * _Nonnull)engine
  1181. remoteVideoStateChangedOfUid:(NSUInteger)uid state:(AgoraVideoRemoteState)state reason:(AgoraVideoRemoteReason)reason elapsed:(NSInteger)elapsed{
  1182. YOUPAILZLiveVideoView *videoView = nil;
  1183. if ([[NSString stringWithFormat:@"%@",@(uid)] isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
  1184. videoView = self.youpaiplocalVideo;
  1185. }else{
  1186. videoView = self.youpaipremoteVideo;
  1187. }
  1188. if (state == AgoraVideoRemoteStateStopped /* || state == AgoraVideoRemoteStateFrozen*/) {
  1189. videoView.youpaipisOff = YES;
  1190. }else{
  1191. videoView.youpaipisOff = NO;
  1192. }
  1193. }
  1194. // 在远程用户的音频流静音/取消静音时发生。
  1195. - (void)rtcEngine:(AgoraRtcEngineKit *)engine didAudioMuted:(BOOL)muted byUid:(NSUInteger)uid{
  1196. if (muted) {//关闭了音频
  1197. }else{
  1198. }
  1199. }
  1200. - (void)rtcEngine:(AgoraRtcEngineKit *)engine didJoinedOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed{
  1201. [self.youpaipagoraKit muteRemoteAudioStream:uid mute:NO];
  1202. if (self.youpaifclientRole == AgoraClientRoleAudience) {
  1203. if ([[NSString stringWithFormat:@"%@",@(uid)] isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
  1204. self.youpaiplocalVideo.hidden = NO;
  1205. AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  1206. videoCanvas.uid = uid;
  1207. videoCanvas.view = self.youpaiplocalVideo.youpaipvideoView;
  1208. videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  1209. // 设置本地视图。
  1210. self.youpaiplocalCanvas = videoCanvas;
  1211. [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
  1212. }else{
  1213. self.youpaipremoteVideo.hidden = NO;
  1214. self.youpaipremoteVideoBtn.hidden = NO;
  1215. self.youpaipto_uid = [NSString stringWithFormat:@"%@",@(uid)];
  1216. [self youpaifrequestLiveGetUser];
  1217. AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  1218. videoCanvas.uid = uid;
  1219. videoCanvas.view = self.youpaipremoteVideo.youpaipvideoView;
  1220. videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  1221. // 设置本地视图。
  1222. self.youpaipremoteCanvas = videoCanvas;
  1223. [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
  1224. [UIView animateWithDuration:0.25f animations:^{
  1225. self.youpaiplocalVideo.layer.cornerRadius = 5.0f;
  1226. self.youpaiplocalVideo.clipsToBounds = YES;
  1227. self.youpaipremoteVideo.layer.cornerRadius = 5.0f;
  1228. self.youpaipremoteVideo.clipsToBounds = YES;
  1229. self.youpaiplocalVideo.frame = CGRectMake(0.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 0.5f, 270.0f);
  1230. self.youpaipremoteVideo.frame = CGRectMake(KScreenWidth / 2.0f + 1.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 1.0f, 270.0f);
  1231. }];
  1232. self.youpaipcloseEnemyAudioBtn.hidden = NO;
  1233. }
  1234. }else{
  1235. self.youpaipremoteVideo.hidden = NO;
  1236. self.youpaipremoteVideoBtn.hidden = NO;
  1237. self.youpaipto_uid = [NSString stringWithFormat:@"%@",@(uid)];
  1238. [self youpaifrequestLiveGetUser];
  1239. AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  1240. videoCanvas.uid = uid;
  1241. videoCanvas.view = self.youpaipremoteVideo.youpaipvideoView;
  1242. videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  1243. // 设置本地视图。
  1244. self.youpaipremoteCanvas = videoCanvas;
  1245. [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
  1246. [UIView animateWithDuration:0.25f animations:^{
  1247. self.youpaiplocalVideo.layer.cornerRadius = 5.0f;
  1248. self.youpaiplocalVideo.clipsToBounds = YES;
  1249. self.youpaipremoteVideo.layer.cornerRadius = 5.0f;
  1250. self.youpaipremoteVideo.clipsToBounds = YES;
  1251. self.youpaiplocalVideo.frame = CGRectMake(0.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 0.5f, 270.0f);
  1252. self.youpaipremoteVideo.frame = CGRectMake(KScreenWidth / 2.0f + 1.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 1.0f, 270.0f);
  1253. }];
  1254. self.youpaipcloseEnemyAudioBtn.hidden = NO;
  1255. }
  1256. }
  1257. - (void)rtcEngine:(AgoraRtcEngineKit *)engine didOfflineOfUid:(NSUInteger)uid reason:(AgoraUserOfflineReason)reason{
  1258. if (![[NSString stringWithFormat:@"%@",@(uid)] isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
  1259. self.youpaipremoteVideo.hidden = YES;
  1260. [UIView animateWithDuration:0.25f animations:^{
  1261. self.youpaiplocalVideo.layer.cornerRadius = 0.0f;
  1262. self.youpaiplocalVideo.clipsToBounds = YES;
  1263. self.youpaiplocalVideo.frame = self.view.bounds;
  1264. }];
  1265. AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  1266. videoCanvas.uid = uid;
  1267. videoCanvas.view = nil;
  1268. // 视图的渲染模式
  1269. videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  1270. // 设置远端视图。
  1271. [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
  1272. self.youpaipcloseEnemyAudioBtn.hidden = YES;
  1273. self.youpaipcloseEnemyAudioBtn.selected = NO;
  1274. self.youpaipfollowBgV.hidden = YES;
  1275. self.youpaipremoteVideoBtn.hidden = YES;
  1276. if (self.youpaipremoteVideoCloseBlock != nil) {
  1277. self.youpaipremoteVideoCloseBlock();
  1278. }
  1279. }else{
  1280. // if (self.youpaifclientRole == AgoraClientRoleAudience) {
  1281. // if (self.youpaipliveCloseBlock != nil) {
  1282. // self.youpaipliveCloseBlock();
  1283. // }
  1284. // }
  1285. }
  1286. }
  1287. /// 本地音乐文件播放已结束回调
  1288. - (void)rtcEngineLocalAudioMixingDidFinish:(AgoraRtcEngineKit *)engine{
  1289. if (self.youpaipmusicPlayFinishBlock != nil) {
  1290. self.youpaipmusicPlayFinishBlock();
  1291. }
  1292. }
  1293. ///// 本地用户的音乐文件播放状态已改变回调
  1294. //- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioMixingStateDidChanged:(AgoraAudioMixingStateCode)state errorCode:(AgoraAudioMixingErrorCode)errorCode{
  1295. // if (self.youpaipmusicPlayStateBlock != nil) {
  1296. // self.youpaipmusicPlayStateBlock(state);
  1297. // }
  1298. //}
  1299. #pragma mark - AgoraVideoSourceProtocol
  1300. // 初始化视频源
  1301. - (BOOL)shouldInitialize{
  1302. return YES;
  1303. }
  1304. // 启用视频源
  1305. - (void)shouldStart{
  1306. // [self.youpaipmCamera startCapture];
  1307. }
  1308. // 停止视频源
  1309. - (void)shouldStop{
  1310. // [self.youpaipmCamera stopCapture];
  1311. }
  1312. // 释放视频源
  1313. - (void)shouldDispose{
  1314. }
  1315. //// 检索缓冲区类型
  1316. //- (AgoraVideoBufferType)bufferType{
  1317. // // 使用像素缓冲区传输视频数据
  1318. // return AgoraVideoBufferTypePixelBuffer;
  1319. //}
  1320. //- (AgoraVideoCaptureType)captureType{
  1321. // return AgoraVideoCaptureTypeCamera;
  1322. //}
  1323. #pragma mark - FUCameraDelegate
  1324. -(void)didOutputVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer {
  1325. CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer) ;
  1326. CVPixelBufferLockBaseAddress(pixelBuffer, 0);
  1327. [[FUManager shareManager] renderItemsToPixelBuffer:pixelBuffer];
  1328. CGSize frameSize;
  1329. if (CVPixelBufferGetPixelFormatType(pixelBuffer) == kCVPixelFormatType_32BGRA) {
  1330. frameSize = CGSizeMake(CVPixelBufferGetBytesPerRow(pixelBuffer) / 4, CVPixelBufferGetHeight(pixelBuffer));
  1331. }else{
  1332. frameSize = CGSizeMake(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
  1333. }
  1334. // push video frame to agora
  1335. // [self.consumer consumePixelBuffer:pixelBuffer withTimestamp:CMSampleBufferGetPresentationTimeStamp(sampleBuffer) rotation:AgoraVideoRotationNone];
  1336. CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
  1337. }
  1338. #pragma mark - UITableViewDataSource
  1339. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  1340. return self.youpaipmessages.count;
  1341. }
  1342. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  1343. NIMMessage *message = self.youpaipmessages[indexPath.row];
  1344. if ([message isKindOfClass:[YOUPAILZLiveModel class]]) {
  1345. NSString *cellID = @"YOUPAILZLiveFollowCell";
  1346. YOUPAILZLiveFollowCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  1347. if (cell == nil) {
  1348. cell = [[YOUPAILZLiveFollowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  1349. }
  1350. [cell youpaifreloadWithModel:self.youpaipliveModel indexPath:indexPath];
  1351. @weakify(self);
  1352. [cell setYoupaipfollowBlock:^(YOUPAILZLiveModel * _Nonnull model, NSIndexPath * _Nonnull indexPath) {
  1353. @strongify(self);
  1354. [LCCommonHttp followUserId:model.youpaipuser_info.youpaipuser_id liveId:@"1"];
  1355. [self.youpaipmessages removeObjectAtIndex:indexPath.row];
  1356. [self.youpaipchatTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  1357. [self youpaifreloadTableView];
  1358. }];
  1359. return cell;
  1360. }else{
  1361. NSString *cellID = @"YOUPAILZLiveChatMessageCell";
  1362. YOUPAILZLiveChatMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  1363. if (cell == nil) {
  1364. cell = [[YOUPAILZLiveChatMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  1365. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  1366. }
  1367. [cell youpaifreloadWithModel:message font:self.youpaipliveModel.youpaipisMaxFont ? self.youpaipliveModel.youpaipmaxFont : self.youpaipliveModel.youpaipminFont indexPath:indexPath];
  1368. @weakify(self);
  1369. [cell setShowUserInfoBlock:^(NSIndexPath * _Nonnull indexPath1) {
  1370. @strongify(self);
  1371. NIMMessage *message = self.youpaipmessages[indexPath1.row];
  1372. if (message.session.sessionType == NIMSessionTypeChatroom
  1373. && message.messageType == NIMMessageTypeNotification){ /// 如果是聊天室并且消息类型为通知类型
  1374. NIMNotificationObject *object = message.messageObject;
  1375. if (![object.content isKindOfClass:[NIMUnsupportedNotificationContent class]]) {
  1376. NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)object.content;
  1377. NSString *fromId = nil;
  1378. for (NIMChatroomNotificationMember *memebr in content.targets) {
  1379. fromId = memebr.userId;
  1380. }
  1381. if (content.eventType == NIMChatroomEventTypeEnter) { /// 有成员加入聊天室
  1382. fromId = message.from;
  1383. }else if(content.eventType == NIMChatroomEventTypeExit){ /// 有成员离开聊天室
  1384. fromId = message.from;
  1385. }else if(content.eventType == NIMChatroomEventTypeKicked){ /// 聊天室成员被踢
  1386. fromId = message.from;
  1387. }
  1388. [self youpaifshowUserInfoWithUserId:fromId];
  1389. }
  1390. }else{
  1391. [self youpaifshowUserInfoWithUserId:message.from];
  1392. }
  1393. }];
  1394. [cell setYoupaipreplyBlock:^(NSIndexPath * _Nonnull indexPath) {
  1395. @strongify(self);
  1396. NSString *nick = [NIMKitUtil showNick:message.from inMessage:message];
  1397. self.youpaipsendMessageTF.text = [NSString stringWithFormat:@"@%@ ",nick];
  1398. [self youpaifsendMessageBecomeFirstResponder];
  1399. }];
  1400. return cell;
  1401. }
  1402. }
  1403. #pragma mark - UITableViewDelegate
  1404. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  1405. return [self.youpaipliveModel youpaifnoticeTextHeight];
  1406. }
  1407. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  1408. return CGFLOAT_MIN;
  1409. }
  1410. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  1411. UIView *v = [[UIView alloc] initWithFrame:CGRectMake(.0f, 0.0f, 276.0f, [self.youpaipliveModel youpaifnoticeTextHeight])];
  1412. v.transform = CGAffineTransformMakeRotation(M_PI);
  1413. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(5.0f, 0, 266.0f, [self.youpaipliveModel youpaifnoticeTextHeight])];
  1414. bgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
  1415. bgV.layer.cornerRadius = 10.0f;
  1416. bgV.clipsToBounds = YES;
  1417. UILabel *youpaiptextL = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 10.0f, 236.0f, bgV.mj_h - 20.0f)];
  1418. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:self.youpaipliveModel.youpaipnotice_text];
  1419. NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  1420. paragraphStyle1.alignment=NSTextAlignmentJustified;
  1421. NSDictionary * dic =@{
  1422. NSParagraphStyleAttributeName:paragraphStyle1,
  1423. NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],
  1424. };
  1425. [attributedString1 setAttributes:dic range:NSMakeRange(0, attributedString1.length)];
  1426. youpaiptextL.attributedText = attributedString1;
  1427. youpaiptextL.numberOfLines = 0;
  1428. youpaiptextL.textColor = HexColorFromRGB(0xFFA68B);
  1429. youpaiptextL.font = self.youpaipliveModel.youpaipisMaxFont ? self.youpaipliveModel.youpaipmaxFont : self.youpaipliveModel.youpaipminFont;
  1430. [bgV addSubview:youpaiptextL];
  1431. [v addSubview:bgV];
  1432. return v;
  1433. }
  1434. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  1435. // NIMMessage *message = self.messages[indexPath.row];
  1436. // if ([message isKindOfClass:[YOUPAILZLiveModel class]]) {
  1437. // [self youpaifshowUserInfoWithUserId:self.youpaipliveModel.user_info.user_id];
  1438. // }else{
  1439. // [self youpaifshowUserInfoWithUserId:message.from];
  1440. // }
  1441. }
  1442. #pragma mark - UITextFieldDelegate
  1443. -(BOOL)textFieldShouldReturn:(UITextField *)textField{
  1444. NSString *text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  1445. if (text.length != 0) {
  1446. @weakify(self);
  1447. [LCHttpHelper requestWithURLString:LiveSendMessage parameters:@{@"roomid":self.youpaipliveModel.youpaiproomid,@"content":text} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1448. @strongify(self);
  1449. NSDictionary* dict = (NSDictionary*)responseObject;
  1450. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1451. if (code == 0) {
  1452. NIMSession *session = [NIMSession session:self.youpaipliveModel.youpaiproomid type:NIMSessionTypeChatroom];
  1453. NIMMessage *imMessage = [NIMMessageMaker msgWithText:[[dict objectForKey:@"data"] objectForKey:@"content"]];
  1454. if ([[[NIMSDK sharedSDK] chatManager] sendMessage:imMessage toSession:session error:nil]) {
  1455. self.youpaipsendMessageTF.text = @"";
  1456. [self youpaifhideKayboard];
  1457. }
  1458. }else{
  1459. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1460. }
  1461. } failure:^(NSError *error) {
  1462. [ZCHUDHelper showTitle:error.localizedDescription];
  1463. }];
  1464. }
  1465. return YES;
  1466. }
  1467. #pragma mark - getter and setter
  1468. - (FUCamera *)youpaipmCamera {
  1469. if (!_youpaipmCamera) {
  1470. _youpaipmCamera = [[FUCamera alloc] init];
  1471. _youpaipmCamera.delegate = self;
  1472. }
  1473. return _youpaipmCamera;
  1474. }
  1475. - (YOUPAILZLiveVideoView *)youpaiplocalVideo{
  1476. if (!_youpaiplocalVideo) {
  1477. _youpaiplocalVideo = [[YOUPAILZLiveVideoView alloc] initWithFrame:self.view.bounds];
  1478. _youpaiplocalVideo.hidden = YES;
  1479. }
  1480. return _youpaiplocalVideo;
  1481. }
  1482. - (YOUPAILZLiveVideoView *)youpaipremoteVideo{
  1483. if (!_youpaipremoteVideo) {
  1484. _youpaipremoteVideo = [[YOUPAILZLiveVideoView alloc] initWithFrame:self.view.bounds];
  1485. _youpaipremoteVideo.hidden = YES;
  1486. }
  1487. return _youpaipremoteVideo;
  1488. }
  1489. - (NSMutableArray<NIMMessage *> *)youpaipmessages{
  1490. if (!_youpaipmessages) {
  1491. _youpaipmessages = [NSMutableArray array];
  1492. }
  1493. return _youpaipmessages;
  1494. }
  1495. - (NSMutableArray *)youpaipgifts{// 礼物数据
  1496. if (!_youpaipgifts) {
  1497. _youpaipgifts = [NSMutableArray array];
  1498. }
  1499. return _youpaipgifts;
  1500. }
  1501. - (NSMutableArray<YOUPAILZLiveGiftView *> *)youpaipgiftViews{// 礼物
  1502. if (!_youpaipgiftViews) {
  1503. _youpaipgiftViews = [NSMutableArray array];
  1504. }
  1505. return _youpaipgiftViews;
  1506. }
  1507. - (NSMutableArray *)youpaipsvgas{
  1508. if (!_youpaipsvgas) {
  1509. _youpaipsvgas = [NSMutableArray array];
  1510. }
  1511. return _youpaipsvgas;
  1512. }
  1513. /// 设置用户角色
  1514. - (AgoraClientRole)youpaifclientRole{
  1515. return AgoraClientRoleBroadcaster;
  1516. }
  1517. /// 设置输入框焦点
  1518. - (void)youpaifsendMessageBecomeFirstResponder{
  1519. self.youpaipsendMessageTF.hidden = NO;
  1520. [self.youpaipsendMessageTF becomeFirstResponder];
  1521. }
  1522. /// 隐藏键盘
  1523. - (void)youpaifhideKayboard{
  1524. dispatch_async(dispatch_get_main_queue(), ^{
  1525. [self.view endEditing:YES];
  1526. self.youpaipsendMessageTF.hidden = YES;
  1527. });
  1528. }
  1529. /// 刷新列表
  1530. - (void)youpaifreloadChatList{
  1531. [self.youpaipchatTableView reloadData];
  1532. }
  1533. /// 隐藏聊天列表
  1534. - (void)youpaifhiddenChatList{
  1535. CGFloat x = self.youpaipchatBgView.mj_x;
  1536. x = x == 0.0f ? KScreenWidth : 0.0f;
  1537. [UIView animateWithDuration:0.25f animations:^{
  1538. self.youpaipchatBgView.mj_x = x;
  1539. }];
  1540. }
  1541. /// 关注
  1542. - (void)youpaiffollow{
  1543. NSInteger index = -1;
  1544. for (NSInteger i = 0; i < self.youpaipmessages.count; i ++) {
  1545. if ([self.youpaipmessages[i] isKindOfClass:[YOUPAILZLiveModel class]]) {
  1546. index = i;
  1547. }
  1548. }
  1549. if (index != -1) {
  1550. [self.youpaipmessages removeObjectAtIndex:index];
  1551. [self.youpaipchatTableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
  1552. [self youpaifreloadTableView];
  1553. }
  1554. }
  1555. /// 展示用户信息
  1556. bool youpaipisShowUserInfo = YES;
  1557. - (void)youpaifshowUserInfoWithUserId:(NSString *)userId{
  1558. if (youpaipisShowUserInfo) {
  1559. youpaipisShowUserInfo = NO;
  1560. @weakify(self);
  1561. [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":userId,@"no_visitor":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  1562. youpaipisShowUserInfo = YES;
  1563. NSDictionary* dict = (NSDictionary*)responseObject;
  1564. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1565. if (code==0) {//成功
  1566. @strongify(self);
  1567. YOUPAILCUserShowModel *showModel = [YOUPAILCUserShowModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  1568. NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc] init];
  1569. request.roomId = self.youpaipliveModel.youpaiproomid;
  1570. request.userIds = @[[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id,showModel.youpaipinfo.youpaipuserid];
  1571. [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
  1572. @strongify(self);
  1573. if (members.count == 2) {
  1574. NIMChatroomMember *mamber0 = members[0];
  1575. NIMChatroomMember *mamber1 = members[1];
  1576. BOOL youpaipisManage = NO;
  1577. for (NSInteger i = 0; i < members.count; i ++) {
  1578. NIMChatroomMember *member = members[i];
  1579. if ([member.userId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  1580. youpaipisManage = member.type == NIMChatroomMemberTypeManager;
  1581. }
  1582. }
  1583. if (mamber0.type == NIMChatroomMemberTypeManager && mamber1.type == NIMChatroomMemberTypeManager) {
  1584. youpaipisManage = NO;
  1585. }
  1586. [self youpaifshowUserInfoWithModel:showModel youpaipisAnchor:self.youpaifclientRole == AgoraClientRoleBroadcaster youpaipisManage:youpaipisManage];
  1587. }else if (members.count == 1){
  1588. NIMChatroomMember *member = members[0];
  1589. BOOL youpaipisManage = member.type == NIMChatroomMemberTypeManager;
  1590. [self youpaifshowUserInfoWithModel:showModel youpaipisAnchor:self.youpaifclientRole == AgoraClientRoleBroadcaster youpaipisManage:youpaipisManage];
  1591. }
  1592. }];
  1593. }
  1594. } failure:^(NSError *error) {
  1595. youpaipisShowUserInfo = YES;
  1596. }];
  1597. }
  1598. }
  1599. - (void)youpaifshowUserInfoWithModel:(YOUPAILCUserShowModel *)showModel youpaipisAnchor:(BOOL)youpaipisAnchor youpaipisManage:(BOOL)youpaipisManage{
  1600. if ([showModel.youpaipinfo.youpaipuserid isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id] || [showModel.youpaipinfo.youpaipuserid isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  1601. youpaipisAnchor = NO;
  1602. youpaipisManage = NO;
  1603. }
  1604. @weakify(self);
  1605. YOUPAILZLiveUserInfoWindow *vc = [[YOUPAILZLiveUserInfoWindow alloc] initWithModel:showModel isAnchor:youpaipisAnchor isManage:youpaipisManage];
  1606. vc.isTouchDismiss = YES;
  1607. [vc setYoupaipuserShowBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
  1608. @strongify(self);
  1609. if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
  1610. self.youpaipisNotPanClose = YES;
  1611. YOUPAILZUserShowVC *vc = [[YOUPAILZUserShowVC alloc] init];
  1612. vc.youpaipuserId = model.youpaipinfo.youpaipuserid;
  1613. [self.navigationController pushViewController:vc animated:YES];
  1614. }
  1615. }];
  1616. [vc setYoupaipreportBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
  1617. @strongify(self);
  1618. if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
  1619. self.youpaipisNotPanClose = YES;
  1620. ZCAlertAction *action = [ZCAlertAction actionWithTitle:@"举报" andblock:^{//举报
  1621. @strongify(self);
  1622. YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init];
  1623. report.youpaipreport_uid = model.youpaipinfo.youpaipuserid;
  1624. report.youpaiptype = 5;
  1625. [self.navigationController pushViewController:report animated:YES];
  1626. }];
  1627. ZCAlertAction *action1 = [ZCAlertAction actionWithTitle:@"拉黑" andblock:^{//举报
  1628. @strongify(self);
  1629. [self youpaifshowAddBlackWithUserId:model.youpaipinfo.youpaipuserid];
  1630. }];
  1631. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[action,action1]];
  1632. //modify by leo --fix bug ios13 20191009
  1633. //alertSheet.alertWindow.rootViewController = self;
  1634. alertSheet.alertWindow.hidden = NO;
  1635. [alertSheet show];
  1636. }
  1637. // [weakSelf ReportOrBlackSelector];
  1638. }];
  1639. [vc setYoupaipgiftBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
  1640. @strongify(self);
  1641. if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
  1642. NSInteger type = 1;
  1643. NSString *youpaipto_uid = model.youpaipinfo.youpaipuserid;
  1644. BOOL youpaipisCurrentAnchor = NO;
  1645. if ([self.youpaipliveModel.youpaipuser_info.youpaipuser_id isEqual:model.youpaipinfo.youpaipuserid]) {
  1646. type = 5;
  1647. youpaipto_uid = self.youpaipliveModel.youpaipuser_info.youpaipuser_id;
  1648. youpaipisCurrentAnchor = YES;
  1649. }
  1650. YOUPAILZCommonGiftView *view = [YOUPAILZCommonGiftView new];
  1651. view.isTouchDismiss = YES;
  1652. view.youpaipcountDown = 3;
  1653. view.youpaipisAnchor = youpaipisAnchor;
  1654. [view setYoupaiplzgiftblock:^(YOUPAILCGiftModel * _Nonnull model, NSInteger count,NSString*categoryID) {
  1655. //1个人详情页 2IM页面 3视频中 4收到礼物页面赠送
  1656. NSMutableDictionary *params = @{@"type":@(type),@"to_uid":youpaipto_uid,@"gift_id":model.youpaipid,@"num":@(count),@"gift_type_id":categoryID}.mutableCopy;
  1657. if (youpaipisCurrentAnchor) {
  1658. [params setValue:self.youpaipliveModel.youpaiplive_id forKey:@"live_id"];
  1659. }
  1660. [LCHttpHelper requestWithURLString:SendGift_New parameters:params.copy needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  1661. NSDictionary* dict = (NSDictionary*)responseObject;
  1662. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1663. if (code==0) {//成功
  1664. [ZCHUDHelper showTitle:@"礼物赠送成功"];
  1665. }
  1666. } failure:^(NSError *error) {
  1667. }];
  1668. }];
  1669. [view setYoupaiptouchAdvertBlock:^(YOUPAILCBannerModel * _Nonnull bannerModel) {
  1670. @strongify(self);
  1671. if (bannerModel.youpaiplink_type==1) {
  1672. ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
  1673. baseWeb.contentUrl = bannerModel.youpaiplink_url;
  1674. self.youpaipisNotPanClose = YES;
  1675. [self.navigationController pushViewController:baseWeb animated:YES];
  1676. }else if (bannerModel.youpaiplink_type==2||bannerModel.youpaiplink_type==3){
  1677. [self youpaifpageToStr:bannerModel.youpaiplink_url];
  1678. }
  1679. }];
  1680. [self TFPresentVC:view completion:^{
  1681. }];
  1682. }else{
  1683. [ZCHUDHelper showTitle:@"你在直播中,暂时不可以送礼物"];
  1684. }
  1685. }];
  1686. [vc setYoupaipguardBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
  1687. @strongify(self);
  1688. if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
  1689. BOOL youpaipisCurrentAnchor = NO;
  1690. if ([self.youpaipliveModel.youpaipuser_info.youpaipuser_id isEqual:model.youpaipinfo.youpaipuserid]) {
  1691. youpaipisCurrentAnchor = YES;
  1692. }
  1693. [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id,@"no_visitor":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  1694. NSDictionary* dict = (NSDictionary*)responseObject;
  1695. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1696. if (code==0) {//成功
  1697. @strongify(self);
  1698. YOUPAILCUserShowModel *showModel = [YOUPAILCUserShowModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  1699. YOUPAILPGuardHerVC *VC= [[YOUPAILPGuardHerVC alloc]init];
  1700. VC.youpaipdelegate = self;
  1701. VC.youpaipuser_id = self.youpaipliveModel.youpaipuser_info.youpaipuser_id;
  1702. VC.vWidth = KScreenWidth-54;
  1703. VC.vHeight = ((KScreenWidth-54)*165)/321.0+261.5;
  1704. VC.youpaipinfoModel = showModel.youpaipguard;
  1705. if (youpaipisCurrentAnchor) {
  1706. VC.youpaipliveid = self.youpaipliveModel.youpaiplive_id;
  1707. }
  1708. VC.isTouchDismiss = YES;
  1709. if(VC.youpaipinfoModel!=nil)
  1710. [self TFPresentVC:VC completion:^{
  1711. }];
  1712. }else{
  1713. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1714. }
  1715. } failure:^(NSError *error) {
  1716. [ZCHUDHelper showTitle:error.localizedDescription];
  1717. }];
  1718. }else{
  1719. [ZCHUDHelper showTitle:@"你在直播中,暂时不可以送守护"];
  1720. }
  1721. }];
  1722. [vc setYoupaipsiXinBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
  1723. @strongify(self);
  1724. if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
  1725. NIMSession *session = [NIMSession session:model.youpaipinfo.youpaipuserid type:NIMSessionTypeP2P];
  1726. if (session) {
  1727. self.youpaipisNotPanClose = YES;
  1728. [ZCHUDHelper show];
  1729. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  1730. @strongify(self);
  1731. [ZCHUDHelper dismiss];
  1732. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  1733. [self.navigationController pushViewController:vc animated:YES];
  1734. }];
  1735. }
  1736. }else{
  1737. [ZCHUDHelper showTitle:@"你在直播中,暂时不可以私信"];
  1738. }
  1739. }];
  1740. [vc setYoupaipmanageBlock:^(YOUPAILCUserShowModel * _Nonnull model, BOOL youpaipisAnchor) {
  1741. @strongify(self);
  1742. [self youpaifshowliveMembersManageWithModel:model youpaipisAnchor:youpaipisAnchor];
  1743. }];
  1744. [self TFPresentVC:vc completion:^{}];
  1745. }
  1746. /// 直播间管理
  1747. - (void)youpaifshowliveMembersManageWithModel:(YOUPAILCUserShowModel *)model youpaipisAnchor:(BOOL)youpaipisAnchor{
  1748. NSMutableArray* actionArray = [NSMutableArray array];
  1749. @weakify(self);
  1750. if (youpaipisAnchor) {
  1751. ZCAlertAction *manageAction = [ZCAlertAction actionWithTitle:@"设为管理员" andblock:^{
  1752. @strongify(self);
  1753. NIMChatroomMemberUpdateRequest *request = [[NIMChatroomMemberUpdateRequest alloc] init];
  1754. request.roomId = self.youpaipliveModel.youpaiproomid;
  1755. request.userId = model.youpaipinfo.youpaipuserid;
  1756. request.enable = YES;
  1757. NIMChatroomMembersByIdsRequest *idRequest = [[NIMChatroomMembersByIdsRequest alloc] init];
  1758. idRequest.roomId = self.youpaipliveModel.youpaiproomid;
  1759. idRequest.userIds = @[model.youpaipinfo.youpaipuserid];
  1760. [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomMembersByIds:idRequest completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
  1761. if (members.count != 0 && members[0].type == NIMChatroomMemberTypeManager) {
  1762. [ZCHUDHelper showTitle:@"TA已经是管理员"];
  1763. }else{
  1764. [[[NIMSDK sharedSDK] chatroomManager] markMemberManager:request completion:^(NSError * _Nullable error) {
  1765. if (error) {
  1766. [ZCHUDHelper showTitle:@"设置管理员失败"];
  1767. }else{
  1768. [ZCHUDHelper showTitle:@"设置管理员成功"];
  1769. }
  1770. }];
  1771. }
  1772. }];
  1773. }];
  1774. [actionArray addObject:manageAction];
  1775. ZCAlertAction *membersManageAction = [ZCAlertAction actionWithTitle:@"成员管理" andblock:^{
  1776. @strongify(self);
  1777. [self youpaifshowMemberManageAlert];
  1778. }];
  1779. [actionArray addObject:membersManageAction];
  1780. }
  1781. ZCAlertAction *disableSendMsgAction = [ZCAlertAction actionWithTitle:@"禁言" andblock:^{
  1782. @strongify(self);
  1783. [self youpaifshowDisableSendMessageAlertWithUserId:model.youpaipinfo.youpaipuserid];
  1784. }];
  1785. [actionArray addObject:disableSendMsgAction];
  1786. ZCAlertAction *outRoomAction = [ZCAlertAction actionWithTitle:@"踢出房间" andblock:^{
  1787. @strongify(self);
  1788. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
  1789. @strongify(self);
  1790. NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"kick",@"forbidden_uid":model.youpaipinfo.youpaipuserid};
  1791. [self youpaifhandleLiveMemberWithParams:params];
  1792. }];
  1793. cancelAction.cornerRadius = 24.0f;
  1794. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  1795. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  1796. }];
  1797. confimAction.cornerRadius = 24.0f;
  1798. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  1799. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"" content:@"踢出房间后\n本场直播该用户将无法进入" action:@[cancelAction,confimAction]];
  1800. alert.contentTextAlignment = NSTextAlignmentCenter;
  1801. [self TFPresentVC:alert completion:^{}];
  1802. }];
  1803. [actionArray addObject:outRoomAction];
  1804. if (youpaipisAnchor) {
  1805. ZCAlertAction *addBlockAction = [ZCAlertAction actionWithTitle:@"拉黑" andblock:^{
  1806. @strongify(self);
  1807. [self youpaifshowAddBlackWithUserId:model.youpaipinfo.youpaipuserid];
  1808. }];
  1809. [actionArray addObject:addBlockAction];
  1810. }
  1811. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray];
  1812. alertSheet.alertWindow.hidden = NO;
  1813. [alertSheet show];
  1814. }
  1815. /// 拉黑弹框
  1816. - (void)youpaifshowAddBlackWithUserId:(NSString *)userId{
  1817. @weakify(self);
  1818. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  1819. }];
  1820. cancelAction.cornerRadius = 24.0f;
  1821. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  1822. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
  1823. @strongify(self);
  1824. [LCCommonHttp blackUserId:userId liveId:self.youpaipliveModel.youpaiplive_id];
  1825. }];
  1826. confimAction.cornerRadius = 24.0f;
  1827. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  1828. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"拉黑后,你将不再收到对方的消息,并且你们互相看不到对方的动态更新。可以在“设置-黑名单”中解除。" action:@[cancelAction,confimAction]];
  1829. alert.contentTextAlignment = NSTextAlignmentCenter;
  1830. [self TFPresentVC:alert completion:^{}];
  1831. }
  1832. /// 显示禁言弹框
  1833. - (void)youpaifshowDisableSendMessageAlertWithUserId:(NSString *)userId{
  1834. @weakify(self);
  1835. NSMutableArray* actionArray = [NSMutableArray array];
  1836. ZCAlertAction *disableSendMessageAction1 = [ZCAlertAction actionWithTitle:@"禁言5分钟" andblock:^{
  1837. @strongify(self);
  1838. NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(5*60)]};
  1839. [self youpaifhandleLiveMemberWithParams:params];
  1840. }];
  1841. [actionArray addObject:disableSendMessageAction1];
  1842. ZCAlertAction *disableSendMessageAction2 = [ZCAlertAction actionWithTitle:@"禁言1小时" andblock:^{
  1843. @strongify(self);
  1844. NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(60*60)]};
  1845. [self youpaifhandleLiveMemberWithParams:params];
  1846. }];
  1847. [actionArray addObject:disableSendMessageAction2];
  1848. ZCAlertAction *disableSendMessageAction3 = [ZCAlertAction actionWithTitle:@"禁言24小时" andblock:^{
  1849. @strongify(self);
  1850. NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(24*60*60)]};
  1851. [self youpaifhandleLiveMemberWithParams:params];
  1852. }];
  1853. [actionArray addObject:disableSendMessageAction3];
  1854. ZCAlertAction *disableSendMessageAction4 = [ZCAlertAction actionWithTitle:@"永久禁言" andblock:^{
  1855. @strongify(self);
  1856. NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(-1)]};
  1857. [self youpaifhandleLiveMemberWithParams:params];
  1858. }];
  1859. [actionArray addObject:disableSendMessageAction4];
  1860. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:NO andAction:actionArray];
  1861. alertSheet.alertWindow.hidden = NO;
  1862. [alertSheet show];
  1863. }
  1864. /// 成员管理弹框
  1865. - (void)youpaifshowMemberManageAlert{
  1866. @weakify(self);
  1867. NSMutableArray* actionArray = [NSMutableArray array];
  1868. ZCAlertAction *manageListAction = [ZCAlertAction actionWithTitle:@"管理员列表" andblock:^{
  1869. @strongify(self);
  1870. [self youpaifshowManageListWindowWithType:LZLiveManageListTypeWithManage title:@"管理员管理"];
  1871. }];
  1872. [actionArray addObject:manageListAction];
  1873. ZCAlertAction *disableSendMessageListAction = [ZCAlertAction actionWithTitle:@"禁言列表" andblock:^{
  1874. @strongify(self);
  1875. [self youpaifshowManageListWindowWithType:LZLiveManageListTypeWithDisableSendMessage title:@"禁言管理"];
  1876. }];
  1877. [actionArray addObject:disableSendMessageListAction];
  1878. ZCAlertAction *outRoomListAction = [ZCAlertAction actionWithTitle:@"踢人列表" andblock:^{
  1879. @strongify(self);
  1880. [self youpaifshowManageListWindowWithType:LZLiveManageListTypeWithForbidden title:@"踢人管理"];
  1881. }];
  1882. [actionArray addObject:outRoomListAction];
  1883. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:NO andAction:actionArray];
  1884. alertSheet.alertWindow.hidden = NO;
  1885. [alertSheet show];
  1886. }
  1887. - (void)youpaifshowManageListWindowWithType:(LZLiveManageListType)type title:(NSString *)title{
  1888. YOUPAILZLiveManageListWindow *window = [[YOUPAILZLiveManageListWindow alloc] init];
  1889. window.youpaiptype = type;
  1890. window.youpaiptitleText = title;
  1891. window.youpaipliveModel = self.youpaipliveModel;
  1892. window.isTouchDismiss = YES;
  1893. [self TFPresentVC:window completion:^{
  1894. }];
  1895. }
  1896. - (void)youpaifhandleLiveMemberWithParams:(NSDictionary *)params{
  1897. [LCHttpHelper requestWithURLString:ForBiddenUser parameters:params needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  1898. } failure:^(NSError *error) {
  1899. [ZCHUDHelper showTitle:error.localizedDescription];
  1900. }];
  1901. }
  1902. /// 直播中对方女神的信息
  1903. - (void)youpaifrequestLiveGetUser{
  1904. @weakify(self);
  1905. [LCHttpHelper requestWithURLString:LiveGetUser parameters:@{@"user_id":self.youpaipto_uid} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  1906. NSDictionary* dict = (NSDictionary*)responseObject;
  1907. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1908. @strongify(self);
  1909. if (code==0) {//成功
  1910. [self youpaifreloadWithFollowModel:[YOUPAILCUserShowInfo mj_objectWithKeyValues:[dict objectForKey:@"data"]]];
  1911. }
  1912. } failure:^(NSError *error) {
  1913. }];
  1914. }
  1915. @end