YOUPAILZLiveBaseVC.m 112 KB

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