123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091 |
- //
- // YOUPAILZLiveBaseVC.m
- // TIANYAN
- //
- // Created by CY on 2021/5/7.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZLiveBaseVC.h"
- #import "FUOpenGLView.h"
- #import "FUManager.h"
- //#import "YOUPAIAGVideoProcessing.h"
- #import "NIMMessageMaker.h"
- #import "YOUPAILCIMTool.h"
- #import "YOUPAILZLiveChatMessageCell.h"
- //#import "YOUPAILZLiveConsumeMemberListVC.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAILCGiftAttachment.h"
- #import "YOUPAILZGuardAttachment.h"
- #import "YOUPAILZLiveInfoUpdateAttachment.h"
- #import "YOUPAILZLiveCloseAttachment.h"
- #import "YOUPAILZLivePKDataAttachment.h"
- #import "YOUPAILZLiveRankAttachment.h"
- #import "YOUPAILZLiveBarrageAttachment.h"
- #import "YOUPAILZLiveManageAttachment.h"
- #import "YOUPAILZLiveVipBarrageAttachment.h"
- #import "YOUPAILZLiveCarAttachment.h"
- #import "YOUPAILZLiveGiftView.h"
- #import "NIMKitUtil.h"
- #import "NIMKitInfoFetchOption.h"
- #import <SVGAPlayer.h>
- #import <SVGAParser.h>
- #import "YOUPAILZLiveFollowCell.h"
- #import "YOUPAILZLiveFollowAttachment.h"
- #import "YOUPAILZLiveUserInfoWindow.h"
- #import "YOUPAILZUserShowVC.h"
- #import "YOUPAILCReportVC.h"
- #import "YOUPAILPGuardHerVC.h"
- #import "YOUPAILCIMSessionVC.h"
- #import "UIView+YOUPAIRCDDanmaku.h"
- #import "YOUPAIRCDDanmaku.h"
- #import "YOUPAIRCDDanmakuManager.h"
- #import "YOUPAILZCommonGiftView.h"
- #import "LZAlertWindow.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAILZLiveManageListWindow.h"
- #import "YOUPAILZLiveBarrageTool.h"
- #import "YOUPAILZLiveManagerListUtils.h"
- #import "SDCycleScrollView.h"
- #import "YOUPAILCFirstRechargeModel.h"
- #import "UIViewController+TFPresent.h"
- @interface YOUPAILZLiveBaseVC ()<AgoraRtcEngineDelegate,FUCameraDelegate,NIMChatroomManagerDelegate,NIMChatManagerDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,SVGAPlayerDelegate,LPGuardHerDelegate,LZLiveGiftViewDelegate,SDCycleScrollViewDelegate>
- @property (nonatomic,strong) AgoraRtcVideoCanvas *youpaiplocalCanvas; // 本地画布
- @property (nonatomic,strong) AgoraRtcVideoCanvas *youpaipremoteCanvas; // 远程画布
- @property (nonatomic,strong) YOUPAILZLiveVideoView *youpaiplocalVideo; // 本地视频容器
- @property (nonatomic,strong) YOUPAILZLiveVideoView *youpaipremoteVideo; // 远程视频容器
- @property (nonatomic, strong) UITableView *youpaipchatTableView; /// 消息列表
- @property (nonatomic, strong) UITextField *youpaipsendMessageTF; /// 发送消息输入框
- @property (nonatomic, strong) NSMutableArray <NIMMessage *>*youpaipmessages; // 消息数据
- @property (nonatomic, strong) NSMutableArray *youpaipgifts; // 礼物数据
- @property (nonatomic, strong) NSMutableArray <YOUPAILZLiveGiftView *>* youpaipgiftViews;// 礼物
- @property (nonatomic, strong) NSMutableArray *youpaipsvgas; /// svga礼物数据
- @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer;
- @property (nonatomic, strong) SVGAParser *youpaipparser;
- @property (nonatomic, assign) BOOL youpaipisPlaySvga;
- @property (nonatomic, assign) BOOL youpaipisNetworkInterrupt; // 是否网络中断
- @property (nonatomic, strong) UIImageView *youpaipdrawImgV; // 平局View
- @property (nonatomic, strong) UIButton *youpaipcloseEnemyAudioBtn; // 关闭对方音频按钮
- //@property (nonatomic, weak) UIImageView *youpaipheaderBgV;
- @property (nonatomic,strong) UIButton *youpaipfollowBgV;
- @property (nonatomic,strong) UILabel *youpaipnickNameL;
- @property (nonatomic,strong) UIButton *youpaipfollowBtn;
- @property (nonatomic,copy) NSString *youpaipto_uid; // 对方女神id
- @property (nonatomic,copy) NSString *youpaiptoRoomId; // 对方直播间id;
- @property (nonatomic,strong) UIButton *youpaipremoteVideoBtn;
- @property (nonatomic, assign) CGFloat youpaipchatBgX;
- @property (nonatomic, strong) NSDate *youpaipjoinLiveMessageDate; /// 直播间加入消息时间
- @property (nonatomic, strong) YOUPAILZLiveCarAttachment *youpaipcarAttachment; // 直播间座驾动画
- @property (nonatomic, strong) SVGAPlayer *youpaipcarSvgaPlayer;
- @property (nonatomic, strong) SVGAParser *youpaipcarParser;
- @property (nonatomic, assign) BOOL youpaipisPlayCarSvga;
- //广告相关
- @property(nonatomic,strong)SDCycleScrollView* youpaipSDCscrollView;
- @property (strong, nonatomic) YOUPAILCFirstRechargeModel *youpaipfirstRechargeModel;
- @end
- @implementation YOUPAILZLiveBaseVC
- //@synthesize consumer;
- +(instancetype)youpaifLiveWithModel:(YOUPAILZLiveModel *)youpaipliveModel{
- return [[self alloc] initWithModel:youpaipliveModel];
- }
- -(instancetype)initWithModel:(YOUPAILZLiveModel *)youpaipliveModel{
- if (self = [super init]) {
- _youpaipliveModel = youpaipliveModel;
- }
- return self;
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- self.navigationController.navigationBarHidden = YES;
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
- self.youpaipisNotPanClose = NO;
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- self.navigationController.navigationBarHidden = NO;
- [self.view youpaifstopDanmaku];
- }
- - (void)dealloc{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.sx_disableInteractivePop = YES;
- [self youpaifsetupBackgoundColor];
- [self youpaifinitVideoView];
- [self youpaifinitPKDataView];
- [self youpaifinitDrawImgV];
-
- [self youpaifinitChatBgView];
- [self youpaifinitRemoteVideoBtn];
- [self youpaifsetupCloseEnemyAudioBtn];
- [self youpaifinitFollowView];
- [self youpaifinitSvga];
- [self youpaifinitAdvertView];
-
- [self performSelector:@selector(youpaifsetupSDK) withObject:nil afterDelay:1.0];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifsetupMuteLocalVideoStream:) name:UIApplicationWillResignActiveNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifsetupMuteLocalVideoStream:) name:UIApplicationDidBecomeActiveNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaiflogoutCloseLive) name:@"AbnormalLogout" object:nil];
- /// 关注状态改变,接收通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
- /// 离开页面,不关闭直播
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifinsufficientBalanceNotice) name:@"InsufficientBalanceNotice" object:nil];
- /// 离开页面,关闭直播
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifleaveLive) name:@"LeaveLive" object:nil];
- }
- //广告banner
- -(void)youpaifinitAdvertView{
-
-
-
- SDCycleScrollView *bannerView1 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:nil placeholderImage:nil];
- bannerView1.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
- bannerView1.hidden = YES;
- [self.youpaipchatBgView addSubview:bannerView1];
- [bannerView1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-13.5f);
- make.bottom.mas_equalTo(-SafeHeight - 50 - 30.0f);
- make.size.mas_equalTo(CGSizeMake(50, 50));
-
- }];
- self.youpaipSDCscrollView = bannerView1;
-
- bannerView1.autoScrollTimeInterval = 3.0;//2s轮播
- bannerView1.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
- bannerView1.backgroundColor = [UIColor clearColor];
- @weakify(self);
- [bannerView1 setClickItemOperationBlock:^(NSInteger currentIndex) {
- @strongify(self);
- if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
- [ZCHUDHelper showTitle:@"你在直播中,暂时无法离开"];
- return;
- }
- YOUPAILCBannerModel* model = self.youpaipfirstRechargeModel.youpaiplist[currentIndex];
- if (model.youpaiplink_type==1) {
- ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
- baseWeb.contentUrl = model.youpaiplink_url;
- self.youpaipisNotPanClose = YES;
- [self.navigationController pushViewController:baseWeb animated:YES];
- }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){
- [self youpaifpageToStr:model.youpaiplink_url];
- }
- }];
-
-
- }
- //首页充值数据
- -(void)youpaifloadAdvertRecharge{
- @weakify(self);
- [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"3"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- @strongify(self);
- self.youpaipfirstRechargeModel = [YOUPAILCFirstRechargeModel mj_objectWithKeyValues:dict[@"data"]];
-
- NSMutableArray *imgUrlArray = [NSMutableArray new];
- for (YOUPAILCBannerModel* model in self.youpaipfirstRechargeModel.youpaiplist) {
- [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]];
- }
-
- self.youpaipSDCscrollView.imageURLStringsGroup = imgUrlArray;
- if (self.youpaipfirstRechargeModel.youpaipis_open == 1) {
- self.youpaipSDCscrollView.hidden = NO;
-
- }else{
- self.youpaipSDCscrollView.hidden = YES;
-
- }
- }
- } failure:^(NSError *error) {}];
-
- }
- - (void)youpaifinsufficientBalanceNotice{
- self.youpaipisNotPanClose = YES;
- }
- - (void)youpaifleaveLive{
- self.youpaipisNotPanClose = NO;
- [self youpaifleaveChannel];
- }
- - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
- NSDictionary *dict = [notification userInfo];
- if ([dict[@"follow_uid"] isEqual:self.youpaipto_uid] && self.youpaipremoteVideo.hidden == NO) {
- if ([dict[@"is_follow"] integerValue] != 0) { // 加关注
- self.youpaipfollowBgV.hidden = YES;
- }else{ // 取消关注
- self.youpaipfollowBgV.hidden = NO;
- }
- }
- }
- // 设置背景
- - (void)youpaifsetupBackgoundColor{
- UIImageView *bgV = [[UIImageView alloc] initWithFrame:self.view.bounds];
- bgV.image = [UIImage imageNamed:@"vqu_images_L_live_bg"];
- bgV.contentMode = UIViewContentModeScaleAspectFill;
- [self.view addSubview:bgV];
- if(self.youpaipliveModel.youpaipis_virtual == 1){
- [bgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipliveModel.youpaipcoverimg]];
- }else{
- // UIImageView *youpaipheaderBgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, StatusBarHeight + 78.0f)];
- // youpaipheaderBgV.image = [UIImage imageNamed:@"vqu_images_L_live_bg_header"];
- // youpaipheaderBgV.hidden = YES;
- // [self.view addSubview:youpaipheaderBgV];
- // self.youpaipheaderBgV = youpaipheaderBgV;
- }
- bgV.clipsToBounds = YES;
- }
- - (void)youpaifsetupSDK{
- if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
- [self youpaifinitializeAgoraEngine];
- [self youpaifsetupLocalVideo];
- [self youpaifsetupbBeauty];
- [self.youpaipagoraKit startPreview];
- }else{
- [self youpaifsetupAudioSession];
- [self youpaifinitializeAgoraEngine];
- // [self youpaifsetupbBeauty];
- [self youpaifjoin];
-
- [self youpaifsetupChatMessageView];
- }
- }
- - (void)youpaifinitSvga{
- self.youpaipcarSvgaPlayer = [[SVGAPlayer alloc] initWithFrame:[UIScreen mainScreen].bounds];
- self.youpaipcarSvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
- self.youpaipcarSvgaPlayer.delegate = self;
- [self.view addSubview:self.youpaipcarSvgaPlayer];
- self.youpaipcarSvgaPlayer.hidden = YES;
- self.youpaipcarSvgaPlayer.loops = 1;
- self.youpaipcarSvgaPlayer.clearsAfterStop = true;
- self.youpaipcarParser = [[SVGAParser alloc] init];
- self.youpaipcarSvgaPlayer.userInteractionEnabled = NO;
-
- self.youpaipsvgaPlayer = [[SVGAPlayer alloc] initWithFrame:[UIScreen mainScreen].bounds];
- self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
- self.youpaipsvgaPlayer.delegate = self;
- [self.view addSubview:self.youpaipsvgaPlayer];
- self.youpaipsvgaPlayer.hidden = YES;
- self.youpaipsvgaPlayer.loops = 1;
- self.youpaipsvgaPlayer.clearsAfterStop = true;
- self.youpaipparser = [[SVGAParser alloc] init];
- self.youpaipsvgaPlayer.userInteractionEnabled = NO;
- }
- /// 设置视频承载容器
- - (void)youpaifinitVideoView{
- [self.view addSubview:self.youpaiplocalVideo];
- [self.view addSubview:self.youpaipremoteVideo];
- }
- /// pk数据承载容器
- - (void)youpaifinitPKDataView{
- YOUPAILZPKDataView *youpaippkdataView = [[YOUPAILZPKDataView alloc] initWithFrame:CGRectMake(0.0f, StatusBarHeight + 348.0f - 30.0f, KScreenWidth, 54.0f) model:self.youpaipliveModel];
- @weakify(self);
- [youpaippkdataView setShowDrawBlock:^(BOOL show) {
- @strongify(self);
- self.youpaipdrawImgV.hidden = !show;
- }];
- [self.view addSubview:youpaippkdataView];
- self.youpaippkdataView = youpaippkdataView;
- }
- /// 平局承载容器
- - (void)youpaifinitDrawImgV{
- UIImageView *youpaipdrawImgV = [[UIImageView alloc] init];
- youpaipdrawImgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_draw"];
- youpaipdrawImgV.hidden = YES;
- [self.view addSubview:youpaipdrawImgV];
- self.youpaipdrawImgV = youpaipdrawImgV;
- [youpaipdrawImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.view.mas_centerX);
- make.centerY.equalTo(self.youpaipremoteVideo.mas_centerY);
- make.size.mas_offset(CGSizeMake(90.0f, 67.0f));
- }];
- }
- /// 消息列表背景View
- - (void)youpaifinitChatBgView{
- UIView *panBgView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, 0.0f, KScreenWidth - 16.0f, KScreenHeight)];
- [self.view addSubview:panBgView];
- // 添加平移手势
- UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifhandlePan:)];
- [panBgView addGestureRecognizer:panGestureRecognizer];
-
- UIView *youpaipchatBgView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, panBgView.mj_w, KScreenHeight)];
- youpaipchatBgView.clipsToBounds = YES;
- [panBgView addSubview:youpaipchatBgView];
- self.youpaipchatBgView = youpaipchatBgView;
- }
- - (void)youpaifhandlePan:(UIPanGestureRecognizer*) recognizer{
- CGPoint translation = [recognizer translationInView:self.view];
- if(recognizer.state == UIViewAnimatingPositionStart){
- self.youpaipchatBgX = self.youpaipchatBgView.mj_x;
- }else if (recognizer.state == UIGestureRecognizerStateChanged) {
- self.youpaipchatBgView.mj_x = self.youpaipchatBgX + translation.x;
- if (self.youpaipchatBgView.mj_x < 0.0f) {
- self.youpaipchatBgView.mj_x = 0.0f;
- }else if (self.youpaipchatBgView.mj_x > KScreenWidth){
- self.youpaipchatBgView.mj_x = KScreenWidth;
- }
- }else if(recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) {
- CGFloat x = self.youpaipchatBgX;
- if(self.youpaipchatBgX == 0 && self.youpaipchatBgView.mj_x > KScreenWidth * 0.25f) {
- x = KScreenWidth;
- }
- if(self.youpaipchatBgX == KScreenWidth && self.youpaipchatBgView.mj_x < KScreenWidth - KScreenWidth * 0.25f) {
- x = 0.0f;
- }
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaipchatBgView.mj_x = x;
- }];
- if (self.youpaipchatBgX == 0 && translation.x < -(KScreenWidth * 0.25)) {
- if (self.youpaipaudienceRecommendMoreAnchorBlock) {
- self.youpaipaudienceRecommendMoreAnchorBlock();
- }
- }
- }
- }
- /// 设置关闭对方音频按钮
- - (void)youpaifsetupCloseEnemyAudioBtn{
- UIButton *youpaipcloseEnemyAudioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- youpaipcloseEnemyAudioBtn.hidden = YES;
- [youpaipcloseEnemyAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_remote_audio_on"] forState:UIControlStateNormal];
- [youpaipcloseEnemyAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_remote_audio_off"] forState:UIControlStateSelected];
- [youpaipcloseEnemyAudioBtn addTarget:self action:@selector(youpaifcloseEnemyAudioBtnvClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:youpaipcloseEnemyAudioBtn];
- self.youpaipcloseEnemyAudioBtn = youpaipcloseEnemyAudioBtn;
- [youpaipcloseEnemyAudioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(-5.0f);
- make.top.offset(78.0f + StatusBarHeight + 270.0f - 5.0f - 19.0f);
- make.size.mas_offset(CGSizeMake(19.0f, 19.0f));
- }];
- }
- /// 远端女神点击
- - (void)youpaifinitRemoteVideoBtn{
- UIButton *youpaipremoteVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- youpaipremoteVideoBtn.hidden = YES;
- youpaipremoteVideoBtn.frame = CGRectMake(KScreenWidth / 2.0f + 1.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 1.0f, 270.0f);
- [youpaipremoteVideoBtn addTarget:self action:@selector(youpaifremoteVideoClick) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:youpaipremoteVideoBtn];
- self.youpaipremoteVideoBtn = youpaipremoteVideoBtn;
- }
- /// 设置关注View
- - (void)youpaifinitFollowView{
- UIButton *youpaipfollowBgV = [UIButton buttonWithType:UIButtonTypeCustom];
- youpaipfollowBgV.hidden = YES;
- youpaipfollowBgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
- youpaipfollowBgV.layer.cornerRadius = 11.0f;
- youpaipfollowBgV.clipsToBounds = YES;
- [youpaipfollowBgV addTarget:self action:@selector(youpaiffollowBgVClick) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:youpaipfollowBgV];
- self.youpaipfollowBgV = youpaipfollowBgV;
- [youpaipfollowBgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(StatusBarHeight + 70.0f + 10.0f);
- make.right.offset(-5.0f);
- make.height.offset(22.0f);
- make.width.lessThanOrEqualTo(100.0f);
- }];
-
- UIButton *youpaipfollowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipfollowBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(30.0f, 16.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
- youpaipfollowBtn.layer.cornerRadius = 8.0f;
- youpaipfollowBtn.clipsToBounds = YES;
- youpaipfollowBtn.titleLabel.font = LCFont(10.0f);
- [youpaipfollowBtn setTitle:@"关注" forState:UIControlStateNormal];
- [youpaipfollowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [youpaipfollowBtn addTarget:self action:@selector(youpaiffollowBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [youpaipfollowBgV addSubview:youpaipfollowBtn];
- self.youpaipfollowBtn = youpaipfollowBtn;
- [youpaipfollowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(-3.0f);
- make.width.offset(30.0f);
- make.height.offset(16.0f);
- make.centerY.equalTo(youpaipfollowBgV.mas_centerY);
- }];
-
- UILabel *youpaipnickNameL = [[UILabel alloc] init];
- youpaipnickNameL.font = LCFont(12.0f);
- youpaipnickNameL.textColor = [UIColor whiteColor];
- [youpaipfollowBgV addSubview:youpaipnickNameL];
- self.youpaipnickNameL = youpaipnickNameL;
- [youpaipnickNameL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(10.0f);
- make.right.equalTo(youpaipfollowBtn.mas_left).offset(-5.0f);
- make.top.bottom.offset(0.0f);
- }];
- }
- - (void)youpaifremoteVideoClick{
- if (self.youpaipclickRemoteVideoViewBlock != nil) {
- self.youpaipclickRemoteVideoViewBlock(self.youpaipto_uid,self.youpaiptoRoomId);
- }
- }
- - (void)youpaiffollowBgVClick{
- [self youpaifshowUserInfoWithUserId:self.youpaipto_uid];
- }
- - (void)youpaiffollowBtnClick{
- self.youpaipfollowBgV.hidden = YES;
- [LCCommonHttp followUserId:self.youpaipto_uid liveId:@"1"];
- }
- - (void)youpaifreloadWithFollowModel:(YOUPAILCUserShowInfo *)model{
- self.youpaipnickNameL.text = model.youpaipnickname;
- self.youpaiptoRoomId = model.youpaiproom_id;
- if (model.youpaipis_follow == 0) {
- self.youpaipfollowBgV.hidden = NO;
- }else{
- self.youpaipfollowBgV.hidden = YES;
- }
- }
- - (void)youpaifsetupChatMessageView{
-
- //消息列表
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(-1.0f, 0.0f, 276.0f, KScreenHeight * 0.35f) style:UITableViewStyleGrouped];
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.showsVerticalScrollIndicator = NO;
- tableView.delegate = self;
- tableView.dataSource = self;
- tableView.backgroundColor = [UIColor clearColor];
- tableView.transform = CGAffineTransformMakeRotation(M_PI * 1.0001f);
- tableView.rowHeight = UITableViewAutomaticDimension;
- tableView.estimatedSectionHeaderHeight = 0.0f;
- tableView.estimatedSectionFooterHeight = 0.0f;
- self.youpaipchatTableView = tableView;
- [self.youpaipchatBgView addSubview:tableView];
-
- [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(-1.0f);
- make.bottom.offset(-(SafeHeight + 10.0f + 40.0f + 10.0f));
- make.size.mas_offset(CGSizeMake(276.0f, KScreenHeight * 0.35f));
- }];
- //发送消息输入框
- UITextField *sendMessageTF = [[UITextField alloc] init];
- sendMessageTF.placeholder = @"说点什么吧";
- sendMessageTF.font = LCFont15;
- sendMessageTF.textColor = HexColorFromRGB(0x333333);
- sendMessageTF.tintColor = ZYPinkColor;
- sendMessageTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)];
- sendMessageTF.leftViewMode = UITextFieldViewModeAlways;
- sendMessageTF.rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)];
- sendMessageTF.rightViewMode = UITextFieldViewModeAlways;
- sendMessageTF.backgroundColor = [UIColor whiteColor];
- sendMessageTF.returnKeyType = UIReturnKeyDone;
- sendMessageTF.delegate = self;
- sendMessageTF.hidden = YES;
- [self.view addSubview:sendMessageTF];
- self.youpaipsendMessageTF = sendMessageTF;
- [sendMessageTF mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(tableView.mas_bottom).offset(10.0f);
- make.left.right.offset(0.0f);
- make.height.offset(44.0f);
- }];
- }
- /// 初始化 AgoraRtcEngineKit 类。
- - (void)youpaifinitializeAgoraEngine{
- self.youpaipagoraKit = [AgoraRtcEngineKit sharedEngineWithAppId:AgoraID delegate:self];
- //设置频道场景
- [self.youpaipagoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting];
- //设置用户角色
- [self.youpaipagoraKit setClientRole:[self youpaifclientRole]];
- //初始化并返回新分配的具有指定视频分辨率的AgoraVideoEncoderConfiguration对象
- AgoraVideoEncoderConfiguration *configuration = [[AgoraVideoEncoderConfiguration alloc] initWithSize:AgoraVideoDimension1280x720 frameRate:AgoraVideoFrameRateFps24 bitrate:AgoraVideoBitrateCompatible orientationMode:AgoraVideoOutputOrientationModeAdaptative mirrorMode:AgoraVideoMirrorModeAuto];
- [self.youpaipagoraKit setVideoEncoderConfiguration:configuration];
- //设置本地视频镜像模式
- [self.youpaipagoraKit setLocalVideoMirrorMode:AgoraVideoMirrorModeDisabled];
- //启用与Agora Web SDK的互操作性。
- [self.youpaipagoraKit enableWebSdkInteroperability:YES];
- //启用视频
- [self.youpaipagoraKit enableVideo];
- //设置视频源
- [self.youpaipagoraKit setExternalVideoSource:YES useTexture:YES sourceType:AgoraExternalVideoSourceTypeVideoFrame]; //只允许外部源
- }
- /// 设置本地视频
- - (void)youpaifsetupLocalVideo{
- self.youpaiplocalVideo.hidden = NO;
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.uid = 0;
- videoCanvas.view = self.youpaiplocalVideo.youpaipvideoView;
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- // 设置本地视图。
- self.youpaiplocalCanvas = videoCanvas;
- [self.youpaipagoraKit setupLocalVideo:videoCanvas];
- }
- /// 设置美颜
- - (void)youpaifsetupbBeauty{
- //设置默认曝光度
- [self.youpaipmCamera setExposureValue:0];
- [self.youpaipmCamera startCapture];
- [[FUManager shareManager] loadFilter] ;
- [[FUManager shareManager] setAsyncTrackFaceEnable:NO];
- }
- /// 加入频道
- - (void)youpaifjoin{
- // self.youpaipheaderBgV.hidden = NO;
- [self youpaifjoinChannel];
- [self youpaifjoinChatRoom];
- }
- - (void)youpaifjoinChannel{
- @weakify(self);
- [self.youpaipagoraKit joinChannelByToken:nil channelId:self.youpaipliveModel.youpaiproomid info:nil uid:[[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
- @strongify(self);
- //检查扬声器是否已启用
- if([self.youpaipagoraKit isSpeakerphoneEnabled]){
- //设置扬声器
- [self.youpaipagoraKit setEnableSpeakerphone:YES];
- }
- // 设置不自动锁屏
- [UIApplication sharedApplication].idleTimerDisabled = YES;
- }];
- }
- /// 离开频道
- - (void)youpaifleaveChannel{
- [self.youpaippkdataView youpaifstopTimer];
- [self.youpaipagoraKit setupLocalVideo:nil];
- // 离开频道。
- [self.youpaipagoraKit leaveChannel:nil];
- self.youpaipagoraKit.delegate = nil;
- // 如果是女神就停止本地视频预览和视频
- if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
- [self.youpaipagoraKit stopPreview];
- [self.youpaipmCamera stopCapture];
- }
- self.youpaipagoraKit = nil;
- [self youpaifleaveChatRoom];
- }
- /// 加入聊天室
- - (void)youpaifjoinChatRoom{
- @weakify(self);
- NIMChatroomEnterRequest *request = [[NIMChatroomEnterRequest alloc] init];
- request.roomId = self.youpaipliveModel.youpaiproomid;
-
- NSDictionary *roomNotifyExt = @{
- @"is_comein_room_hide":@(self.youpaipliveModel.youpaipis_comein_room_hide)
- };
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:roomNotifyExt options:0 error:0];
- NSString *dataStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- request.roomNotifyExt = dataStr;
- [[[NIMSDK sharedSDK] chatroomManager] enterChatroom:request
- completion:^(NSError *error,NIMChatroom *chatroom,NIMChatroomMember *me) {
- @strongify(self);
- if (error == nil){ // 加入成功
- /// 监听聊天室连接变化
- [[NIMSDK sharedSDK].chatroomManager addDelegate:self];
- /// 添加聊天委托
- [[NIMSDK sharedSDK].chatManager addDelegate:self];
- if (self.youpaifclientRole == AgoraClientRoleAudience && self.youpaipliveModel.youpaipuser_info.youpaipis_follow == 0) {
- [self.youpaipmessages addObject:self.youpaipliveModel];
- [self youpaifreloadTableView];
- }
- if (self.youpaipliveModel.youpaipis_fly == 1) {
- [self youpaifhandleBarrageAttachment:self.youpaipliveModel.youpaipu_data];
- }
- if (self.youpaipliveModel.youpaipis_fly_car == 1) {
- self.youpaipcarAttachment = self.youpaipliveModel.youpaipcar_data;
- [self youpaifstartPlayCarSvga];
- }
- if (self.youpaipliveModel.youpaipis_fly_noble == 1) {
- [self youpaifhandleVipBarrageAttachment:self.youpaipliveModel.youpaipb_box_data];
- }
-
- }else{ // 加入失败
- NSString *toast = [NSString stringWithFormat:@"%@ code:%zd",
- @"进入失败",
- error.code];
-
- }
- }];
- }
- /// 离开聊天室
- - (void)youpaifleaveChatRoom{
- @weakify(self);
- [[[NIMSDK sharedSDK] chatroomManager] exitChatroom:self.youpaipliveModel.youpaiproomid completion:^(NSError * _Nullable error) {
- @strongify(self);
- [[NIMSDK sharedSDK].chatroomManager removeDelegate:self];
- [[NIMSDK sharedSDK].chatManager removeDelegate:self];
- }];
- }
- /// 停止其他应用音频
- - (void)youpaifsetupAudioSession{
- NSError *error;
- AVAudioSession *session = [AVAudioSession sharedInstance];
- [session setCategory:AVAudioSessionCategoryPlayback error:&error];
- [session setActive:YES error:&error];
- }
- /// UI添加消息
- - (void)youpaifuiAddMessages:(NSArray<NIMMessage *> *)messages{
- NSArray <NIMMessage *>* newMessages = [self youpaifdealMessage:messages];
- if (newMessages.count != 0) {
- [self.youpaipmessages insertObjects:newMessages atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, newMessages.count)]];
- // [self.messages addObjectsFromArray:newMessages];
-
- NIMMessage *joinLiveMessage = nil;
- for (NSInteger i = 0; i < self.youpaipmessages.count; i ++) {
- NIMMessage *msg = self.youpaipmessages[i];
- if ([msg isKindOfClass:[NIMMessage class]]) {
- if (msg.session.sessionType == NIMSessionTypeChatroom
- && msg.messageType == NIMMessageTypeNotification){ /// 如果是聊天室并且消息类型为通知类型
- NIMNotificationObject *object = msg.messageObject;
- if (![object.content isKindOfClass:[NIMUnsupportedNotificationContent class]]) {
- NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)object.content;
- if (content.eventType == NIMChatroomEventTypeEnter) { /// 有成员加入聊天室
- if (joinLiveMessage == nil) {
- joinLiveMessage = msg;
- }
- [self.youpaipmessages removeObject:msg];
- i --;
- }
- }
- }
- }
- }
-
- if (joinLiveMessage != nil) {
- [self.youpaipmessages insertObject:joinLiveMessage atIndex:0];
- // [self.messages addObject:joinLiveMessage];
- NSTimeInterval timeBetween = [[NSDate new] timeIntervalSinceDate:self.youpaipjoinLiveMessageDate];
- if (timeBetween >= 3.0f) {
- [self.youpaipmessages removeObject:joinLiveMessage];
- }
- // else{
- // [self performSelector:@selector(removeJoinLiveMessage:) withObject:joinLiveMessage afterDelay:3.0];
- // }
- }
- [self youpaifreloadTableView];
- }
- }
- - (void)youpaifreloadTableView{
- [self.youpaipchatTableView reloadData];
- if (self.youpaipmessages.count != 0) {
- [self.youpaipchatTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
- }
-
- // }
- }
- /// 聊天室消息处理
- - (NSArray <NIMMessage *>*)youpaifdealMessage:(NSArray <NIMMessage *>*)messages{
- NSMutableArray *n_messages = [NSMutableArray array];
-
- /// 聊天室通知处理
- for (NIMMessage *message in messages) {
- [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[message.from] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
- // NIMUser* user = users[0];
- }];
- if (message.session.sessionType == NIMSessionTypeChatroom
- && message.messageType == NIMMessageTypeNotification){ /// 如果是聊天室并且消息类型为通知类型
- NIMNotificationObject *object = message.messageObject;
- if (![object.content isKindOfClass:[NIMUnsupportedNotificationContent class]]) {
- NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)object.content;
- NSString *fromId = nil;
- for (NIMChatroomNotificationMember *memebr in content.targets) {
- fromId = memebr.userId;
- }
- if (content.eventType == NIMChatroomEventTypeEnter) { /// 有成员加入聊天室
-
- if (![message.from isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
- NSData *jsonData = [content.notifyExt dataUsingEncoding:NSUTF8StringEncoding];
- if (jsonData != nil) {
- NSError *err;
- NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
- if (!([dic.allKeys containsObject:@"is_comein_room_hide"] && [[dic objectForKey:@"is_comein_room_hide"] integerValue] == 1)) {
- [n_messages insertObject:message atIndex:0];
- self.youpaipjoinLiveMessageDate = [NSDate new];
- }
- }
- }
- [self youpaifuploadLiveMemberCount];
- [self youpaifmemberJoinLiveWithUserId:message.from];
- // [self loadLiveMemberList];
- }else if(content.eventType == NIMChatroomEventTypeExit){ /// 有成员离开聊天室
- // [n_messages addObject:message];
- [self youpaifuploadLiveMemberCount];
- [self youpaifmemberLeaveLiveWithUserId:message.from];
- // [self loadLiveMemberList];
- }else if(content.eventType == NIMChatroomEventTypeKicked){ /// 聊天室成员被踢
- [self youpaifuploadLiveMemberCount];
- // [self loadLiveMemberList];
- }else if(content.eventType == NIMChatroomEventTypeKicked){ /// 聊天室成员被踢
- [self youpaifuploadLiveMemberCount];
- // [self loadLiveMemberList];
- }else if (content.eventType == NIMChatroomEventTypeAddMute){ // 成员被禁言
- [n_messages insertObject:message atIndex:0];
- if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- [ZCHUDHelper showTitle:@"你被禁言"];
- }
- }else if (content.eventType == NIMChatroomEventTypeRemoveMute){ // 成员被取消禁言
- [n_messages insertObject:message atIndex:0];
- if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- [ZCHUDHelper showTitle:@"你被取消禁言"];
- }
- }else if (content.eventType == NIMChatroomEventTypeAddManager){ // 设置为管理员
- [n_messages insertObject:message atIndex:0];
- [[YOUPAILZLiveManagerListUtils shared] youpaifreloadManagerListWithLiveId:self.youpaipliveModel.youpaiplive_id];
- if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- [ZCHUDHelper showTitle:@"你被设置为管理员"];
- }
- }else if (content.eventType == NIMChatroomEventTypeRemoveManager){ // 移除管理员
- [n_messages insertObject:message atIndex:0];
- [[YOUPAILZLiveManagerListUtils shared] youpaifreloadManagerListWithLiveId:self.youpaipliveModel.youpaiplive_id];
- if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- [ZCHUDHelper showTitle:@"你被取消设置为管理员"];
- }
- }else if (content.eventType == NIMChatroomEventTypeAddMuteTemporarily){ // 聊天室成员被临时禁言
- [n_messages insertObject:message atIndex:0];
- if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- [ZCHUDHelper showTitle:@"你被禁言"];
- }
- }else if (content.eventType == NIMChatroomEventTypeRemoveMuteTemporarily){ // 聊天室成员被解除临时禁言
- [n_messages insertObject:message atIndex:0];
- if ([fromId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- [ZCHUDHelper showTitle:@"你被取消禁言"];
- }
- }
- }
- }else if (message.messageType == NIMMessageTypeText){ // 文本消息
- [n_messages insertObject:message atIndex:0];
- }else if(message.messageType == NIMMessageTypeCustom){ // 自定义消息
- NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
- if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]]){ // 礼物
- YOUPAILCGiftAttachment *attachment = (YOUPAILCGiftAttachment *)object.attachment;
-
- YOUPAILZLiveGIftModel *youpaipgiftModel = [[YOUPAILZLiveGIftModel alloc] init];
- youpaipgiftModel.youpaipavatar = attachment.from_avatar;
- youpaipgiftModel.youpaipnickName = attachment.from_nickname;
- youpaipgiftModel.youpaipgiftDesc = [NSString stringWithFormat:@"赠送了%@",attachment.gift_name];
- youpaipgiftModel.youpaipgiftImage = attachment.gift_url;
- youpaipgiftModel.youpaipgiftCount = attachment.gift_count;
- youpaipgiftModel.youpaipuser_id = attachment.from_uid;
- youpaipgiftModel.youpaipgift_id = attachment.gift_id;
- youpaipgiftModel.youpaipgift_svga = attachment.gift_svga;
- youpaipgiftModel.youpaipgift_type = attachment.gift_type;
-
- if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqual:message.from]) {
- [self.youpaipgifts insertObject:youpaipgiftModel atIndex:0];
- }else{
- [self.youpaipgifts addObject:youpaipgiftModel];
- }
-
- [self youpaifeditGiftView];
- [n_messages insertObject:message atIndex:0];
- }
- if ([object.attachment isKindOfClass:[YOUPAILZGuardAttachment class]]){ // 守护
- YOUPAILZGuardAttachment *attachment = (YOUPAILZGuardAttachment *)object.attachment;
-
- YOUPAILZLiveGIftModel *youpaipgiftModel = [[YOUPAILZLiveGIftModel alloc] init];
- youpaipgiftModel.youpaipavatar = ((NIMMessageChatroomExtension *)message.messageExt).roomAvatar;
- youpaipgiftModel.youpaipnickName = ((NIMMessageChatroomExtension *)message.messageExt).roomNickname;
- youpaipgiftModel.youpaipgiftDesc = [NSString stringWithFormat:@"赠送了%@",attachment.guard_name];
- youpaipgiftModel.youpaipgiftImage = attachment.guard_url;
- youpaipgiftModel.youpaipgiftCount = attachment.guard_count;
- youpaipgiftModel.youpaipuser_id = attachment.from_uid;
- youpaipgiftModel.youpaipgift_id = -1;
- youpaipgiftModel.youpaipgift_svga = attachment.gift_svga;
- youpaipgiftModel.youpaipgift_type = attachment.gift_type;
- if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqual:message.from]) {
- [self.youpaipgifts insertObject:youpaipgiftModel atIndex:0];
- }else{
- [self.youpaipgifts addObject:youpaipgiftModel];
- }
- [self youpaifeditGiftView];
- [n_messages insertObject:message atIndex:0];
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveInfoUpdateAttachment class]]) { //直播间信息
- YOUPAILZLiveInfoUpdateAttachment* attachment = (YOUPAILZLiveInfoUpdateAttachment*)object.attachment;
- [LCSaveData saveLiveRankTopThere:attachment.rank_top_three];
- if (self.youpaipliveInfoUpdateBlock != nil) {
- self.youpaipliveInfoUpdateBlock(attachment.anchor_charm,attachment.fans,attachment.anchor_rank_info);
- }
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveCloseAttachment class]]) { //直播结束
- if (self.youpaipliveCloseBlock != nil) {
- self.youpaipliveCloseBlock();
- }
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLivePKAttachment class]]) { //pk
- YOUPAILZLivePKAttachment *attachment = (YOUPAILZLivePKAttachment*)object.attachment;
- if (self.youpaippkBlock != nil) {
- self.youpaippkBlock(attachment);
- }
- if([attachment.type isEqual:@"hangup"]){
- self.youpaippkdataView.youpaipattachment = nil;
- self.youpaippkdataView.hidden = YES;
- self.youpaipdrawImgV.hidden = YES;
- }
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveLianMaiAttachment class]]) { //lianmai
- YOUPAILZLiveLianMaiAttachment *attachment = (YOUPAILZLiveLianMaiAttachment*)object.attachment;
- if (self.youpaiplianmaiBlock != nil) {
- self.youpaiplianmaiBlock(attachment);
- }
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLivePKDataAttachment class]]) { //pk数据消息
- if (self.youpaippkdataView.youpaipattachment == nil){
- self.youpaippkdataView.hidden = NO;
- }
- YOUPAILZLivePKDataAttachment *attachment = (YOUPAILZLivePKDataAttachment*)object.attachment;
- [self.youpaippkdataView youpaifreloadWithAttachment:attachment];
- if (self.youpaipresetPKDataBlock != nil) {
- self.youpaipresetPKDataBlock(attachment);
- }
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveFollowAttachment class]]) { //关注信息
- [n_messages insertObject:message atIndex:0];
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveRankAttachment class]]) { //排行信息
- YOUPAILZLiveRankAttachment *attachment = (YOUPAILZLiveRankAttachment*)object.attachment;
- if (self.youpaipliveMemberListChangeBlock != nil) {
- self.youpaipliveMemberListChangeBlock(attachment.rank);
- }
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveBarrageAttachment class]]) { //弹幕信息
- YOUPAILZLiveBarrageAttachment *attachment = (YOUPAILZLiveBarrageAttachment*)object.attachment;
- [self youpaifhandleBarrageAttachment:attachment];
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveVipBarrageAttachment class]]) { //VIP弹幕信息
- YOUPAILZLiveVipBarrageAttachment *attachment = (YOUPAILZLiveVipBarrageAttachment*)object.attachment;
- [self youpaifhandleVipBarrageAttachment:attachment];
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveCarAttachment class]]) { //座驾
- YOUPAILZLiveCarAttachment *attachment = (YOUPAILZLiveCarAttachment*)object.attachment;
- self.youpaipcarAttachment = attachment;
- [self youpaifstartPlayCarSvga];
- }
- if ([object.attachment isKindOfClass:[YOUPAILZLiveManageAttachment class]]) { //管理
- YOUPAILZLiveManageAttachment *attachment = (YOUPAILZLiveManageAttachment*)object.attachment;
- [n_messages insertObject:message atIndex:0];
- if ([message.from isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- [ZCHUDHelper showTitle:attachment.user_des];
- [self youpaifleaveChannel];
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- }
- }
- return n_messages.copy;
- }
- /// 处理VIP弹幕消息
- - (void)youpaifhandleVipBarrageAttachment:(YOUPAILZLiveVipBarrageAttachment *)barrageAttachment{
- YOUPAIRCDDanmaku *danmaku = [[YOUPAIRCDDanmaku alloc]init];
- danmaku.playView = [YOUPAILZLiveBarrageTool youpaifhandleVipBarrageAttachment:barrageAttachment];
- [self.view sendDanmaku:danmaku];
- }
- /// 处理弹幕消息
- - (void)youpaifhandleBarrageAttachment:(YOUPAILZLiveBarrageAttachment *)barrageAttachment{
- // YOUPAIRCDDanmaku *danmaku = [[YOUPAIRCDDanmaku alloc]init];
- // danmaku.playView = [YOUPAILZLiveBarrageTool youpaifhandleBarrageAttachment:barrageAttachment];
- // [self.view sendDanmaku:danmaku];
- }
- /// 有成员加入直播间
- - (void)youpaifmemberJoinLiveWithUserId:(NSString *)userId{
-
- if (self.youpaifclientRole == AgoraClientRoleBroadcaster && ![userId isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
- [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) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
-
- }
- } failure:^(NSError *error) {
- }];
- }
-
- }
- /// 有成员离开直播间
- - (void)youpaifmemberLeaveLiveWithUserId:(NSString *)userId{
- if (self.youpaifclientRole == AgoraClientRoleBroadcaster && ![userId isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
- [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) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
-
- }
- } failure:^(NSError *error) {
- }];
- }
- }
- /// 更新聊天室人员数
- - (void)youpaifuploadLiveMemberCount{
- @weakify(self);
- [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomInfo:self.youpaipliveModel.youpaiproomid completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom) {
- if (!error) {
- @strongify(self);
- if (self.youpaipliveMemberCountChangeBlock != nil) {
- NSInteger count = chatroom.onlineUserCount;
- if (self.youpaipliveModel.youpaipis_virtual != 1) {
- count = chatroom.onlineUserCount - 1;
- }
- self.youpaipliveMemberCountChangeBlock(count);
- }
- }
- }];
- }
- /// 处理礼物
- - (void)youpaifeditGiftView{
- NSInteger maxCount = 2;
- NSInteger count = maxCount - self.youpaipgiftViews.count;
- if (count > self.youpaipgifts.count) {
- count = self.youpaipgifts.count;
- }
- if (count <= 0) {
- for (NSInteger i = 0; i < self.youpaipgiftViews.count; i ++) {
- if (self.youpaipgifts.count <= 0) {
- return;
- }
- YOUPAILZLiveGIftModel *youpaipgiftModel = self.youpaipgifts[i];
- YOUPAILZLiveGiftView *giftView = nil;
- for (YOUPAILZLiveGiftView *f_giftView in self.youpaipgiftViews) {
- if (f_giftView.youpaipgiftModel.youpaipuser_id == youpaipgiftModel.youpaipuser_id && f_giftView.youpaipgiftModel.youpaipgift_id == youpaipgiftModel.youpaipgift_id && youpaipgiftModel.youpaipgift_id != -1) {
- giftView = f_giftView;
- break;
- }
- }
- if (giftView != nil) {
- i --;
- [giftView youpaifupdateGiftCount:youpaipgiftModel.youpaipgiftCount];
- [self.youpaipgifts removeObject:youpaipgiftModel];
- if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
- [self.youpaipsvgas addObject:youpaipgiftModel];
- [self youpaifstartPlaySvga];
- }
- [self.youpaipgifts removeObject:youpaipgiftModel];
- }
- }
- }else{
- for (NSInteger i = 0; i < count; i ++) {
- if (self.youpaipgifts.count <= 0) {
- return;
- }
- YOUPAILZLiveGIftModel *youpaipgiftModel = self.youpaipgifts[i];
- YOUPAILZLiveGiftView *giftView = nil;
- for (YOUPAILZLiveGiftView *f_giftView in self.youpaipgiftViews) {
- if (f_giftView.youpaipgiftModel.youpaipuser_id == youpaipgiftModel.youpaipuser_id && f_giftView.youpaipgiftModel.youpaipgift_id == youpaipgiftModel.youpaipgift_id && youpaipgiftModel.youpaipgift_id != -1) {
- giftView = f_giftView;
- break;
- }
- }
- if (giftView != nil) {
- i --;
- [giftView youpaifupdateGiftCount:youpaipgiftModel.youpaipgiftCount];
- [self.youpaipgifts removeObject:youpaipgiftModel];
- if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
- [self.youpaipsvgas addObject:youpaipgiftModel];
- [self youpaifstartPlaySvga];
- }
- }else{
- if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
- [self.youpaipsvgas addObject:youpaipgiftModel];
- [self youpaifstartPlaySvga];
- }
- YOUPAILZLiveGiftView *giftView = [[YOUPAILZLiveGiftView alloc] initWithModel:youpaipgiftModel];
- [giftView addTarget:self action:@selector(youpaifgiftAnimationViewClick:) forControlEvents:UIControlEventTouchUpInside];
- NSInteger tag = 0;
- if (self.youpaipgiftViews.count == 1){
- if (self.youpaipgiftViews.lastObject.tag == 1) {
- tag = 0;
- }else{
- tag = 1;
- }
- }
- giftView.tag = tag;
- [self.youpaipchatBgView addSubview:giftView];
- [self.youpaipgiftViews addObject:giftView];
- if (giftView != nil) {
- UIView *view = self.youpaipgiftViews.lastObject;
- if (view != nil) {
- [giftView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(-200.0f);
- if (view.tag == 0) {
- make.bottom.equalTo(self.youpaipchatTableView.mas_top).offset(-15.0f);
- }else{
- make.bottom.equalTo(self.youpaipchatTableView.mas_top).offset(-30.0f-42.0f);
- }
- make.height.offset(42.0f);
- }];
- }
-
- }
- [giftView.superview layoutIfNeeded];
- [giftView youpaifshowAnimation];
-
- giftView.delegate = self;
- [self.youpaipgifts removeObject:youpaipgiftModel];
- }
- }
- }
- }
- - (void)youpaifanimatiomFinishWithView:(YOUPAILZLiveGiftView *)liveGiftView{
- [self.youpaipgiftViews removeObject:liveGiftView];
- [liveGiftView removeFromSuperview];
- [self youpaifeditGiftView];
- }
- - (void)youpaifstartPlayCarSvga{
-
- if (self.youpaipisPlayCarSvga == NO && self.youpaipcarAttachment != nil) {
- self.youpaipisPlayCarSvga = YES;
-
- [self.youpaipcarSvgaPlayer stopAnimation];
- if (self.youpaipcarAttachment.car_big_preview_img_svga.length != 0) {
- self.youpaipcarSvgaPlayer.hidden = NO;
- }
- NSString* svgaName = [[self.youpaipcarAttachment.car_big_preview_img_svga componentsSeparatedByString:@"/"] lastObject];
- NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
- NSString *svgaPath =[svgaCanchesPath stringByAppendingPathComponent:svgaName];
- if (![[NSFileManager defaultManager] fileExistsAtPath:svgaPath]){
- NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,self.youpaipcarAttachment.car_big_preview_img_svga];
-
- @weakify(self);
- [self.youpaipcarParser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
- @strongify(self);
- if (videoItem != nil) {
- self.youpaipcarSvgaPlayer.videoItem = videoItem;
- [self.youpaipcarSvgaPlayer startAnimation];
- }
- } failureBlock:^(NSError * _Nullable error) {
- @strongify(self);
- self.youpaipcarSvgaPlayer.hidden = YES;
- self.youpaipisPlayCarSvga = NO;
- [self youpaifstartPlayCarSvga];
- }];
- [LCTools giftSVGAWithSvgaUrlStr:self.youpaipcarAttachment.car_big_preview_img_svga];
- }else{
- @weakify(self);
- [self.youpaipcarParser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:self.youpaipcarAttachment.car_big_preview_img_svga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
- @strongify(self);
- if (videoItem != nil) {
- self.youpaipcarSvgaPlayer.videoItem = videoItem;
- [self.youpaipcarSvgaPlayer startAnimation];
- }
- } failureBlock:^(NSError * _Nonnull error) {
- @strongify(self);
- self.youpaipcarSvgaPlayer.hidden = YES;
- self.youpaipisPlayCarSvga = NO;
- [self youpaifstartPlayCarSvga];
- }];
- }
- self.youpaipcarAttachment = nil;
- }
- }
- - (void)youpaifstartPlaySvga{
-
- if (self.youpaipisPlaySvga == NO && self.youpaipsvgas.count != 0) {
- self.youpaipisPlaySvga = YES;
-
- YOUPAILZLiveGIftModel* youpaipgiftModel = self.youpaipsvgas[0];
- [self.youpaipsvgaPlayer stopAnimation];
- if (youpaipgiftModel.youpaipgift_type == 1 && ![youpaipgiftModel.youpaipgift_svga isEqualToString:@""]) {
- self.youpaipsvgaPlayer.hidden = NO;
- }
- NSString* svgaName = [[youpaipgiftModel.youpaipgift_svga componentsSeparatedByString:@"/"] lastObject];
- NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
- if (![LCTools giftSVGAWithSvgaUrlStr:youpaipgiftModel.youpaipgift_svga]){
- NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,youpaipgiftModel.youpaipgift_svga];
-
- @weakify(self);
- [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
- @strongify(self);
- if (videoItem != nil) {
- self.youpaipsvgaPlayer.videoItem = videoItem;
- [self.youpaipsvgaPlayer startAnimation];
- }
- } failureBlock:^(NSError * _Nullable error) {
- @strongify(self);
- self.youpaipsvgaPlayer.hidden = YES;
- self.youpaipisPlaySvga = NO;
- [self youpaifstartPlaySvga];
- }];
- [LCTools giftSVGAWithSvgaUrlStr:youpaipgiftModel.youpaipgift_svga];
- }else{
- @weakify(self);
- [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:youpaipgiftModel.youpaipgift_svga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
- @strongify(self);
- if (videoItem != nil) {
- self.youpaipsvgaPlayer.videoItem = videoItem;
- [self.youpaipsvgaPlayer startAnimation];
- }
- } failureBlock:^(NSError * _Nonnull error) {
- @strongify(self);
- self.youpaipsvgaPlayer.hidden = YES;
- self.youpaipisPlaySvga = NO;
- [self youpaifstartPlaySvga];
- }];
- }
- [self.youpaipsvgas removeObject:youpaipgiftModel];
- }
- }
- #pragma mark - Click
- //关闭对方音频事件
- - (void)youpaifcloseEnemyAudioBtnvClick:(UIButton *)sender{
- sender.selected = !sender.selected;
- [self.youpaipagoraKit muteRemoteAudioStream:[self.youpaipto_uid integerValue] mute:sender.selected];
- }
- ///// 直播间人员列表
- //- (void)loadLiveMemberList{
- // NIMChatroomMemberRequest *request = [[NIMChatroomMemberRequest alloc] init];
- // request.roomId = self.youpaipliveModel.roomid;
- // request.type = NIMChatroomFetchMemberTypeTemp;
- // request.limit = 50;
- // __weak typeof(self) weakSelf = self;
- // [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomMembers:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
- // if (!error && weakSelf.youpaipliveMemberListChangeBlock) {
- // weakSelf.youpaipliveMemberListChangeBlock(members);
- // }
- // }];
- //}
- /// 左边小礼物动画点击
- - (void)youpaifgiftAnimationViewClick:(YOUPAILZLiveGiftView *)sender{
- [self youpaifshowUserInfoWithUserId:[NSString stringWithFormat:@"%@",@(sender.youpaipgiftModel.youpaipuser_id)]];
- }
- //键盘即将隐藏
- - (void)youpaifkeyboardWillHide:(NSNotification *)note{
- [self.view layoutIfNeeded];
- [self.youpaipchatTableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.bottom.offset(-(SafeHeight + 16.0f + 40.0f + 10.0f));
- }];
- }
- //键盘即将弹出
- - (void)youpaifkeyboardWillShow:(NSNotification *)note{
- CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGFloat keyboardH = keyboardF.size.height;
- [self.youpaipchatTableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.bottom.offset(-(SafeHeight + 16.0f + 40.0f + 10.0f) - keyboardH + 12.0f + SafeHeight);
- }];
-
- }
- //设置是否推送视频流
- - (void)youpaifsetupMuteLocalVideoStream:(NSNotification *)note{
- if (self.youpaifclientRole == AgoraClientRoleBroadcaster) {
- if ([note.name isEqual:UIApplicationWillResignActiveNotification]) {
- [self.youpaipagoraKit muteLocalVideoStream:YES];
- }else{
- [self.youpaipagoraKit muteLocalVideoStream:NO];
- }
- }
- }
- // 异常退出登录
- - (void)youpaiflogoutCloseLive{
- if (self.youpaipliveCloseBlock) {
- self.youpaipliveCloseBlock();
- }
- }
- #pragma mark - SVGAPlayerDelegate
- - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player{
- if (self.youpaipsvgaPlayer == player) {
- self.youpaipsvgaPlayer.hidden = YES;
- self.youpaipisPlaySvga = NO;
- [self youpaifstartPlaySvga];
- }else{
- self.youpaipcarSvgaPlayer.hidden = YES;
- self.youpaipisPlayCarSvga = NO;
- [self youpaifstartPlayCarSvga];
- }
- }
- #pragma mark - NIMChatroomManagerDelegate
- /// 被踢回调
- - (void)chatroomBeKicked:(NIMChatroomBeKickedResult *)result{
- NSLog(@"被踢了");
- }
- #pragma mark - NIMChatManagerDelegate
- /// 发送消息完成回调
- - (void)sendMessage:(NIMMessage *)message didCompleteWithError:(nullable NSError *)error{
- NIMSession *session = message.session;
- if (![session.sessionId isEqual:self.youpaipliveModel.youpaiproomid]){
- return;
- }
- if (error == nil) {
- [self youpaifuiAddMessages:@[message]];
- }else if(error.code == 13004){
- [ZCHUDHelper showTitle:@"您已被禁言,不能发送消息"];
- }
- }
- /// 收到消息回调
- - (void)onRecvMessages:(NSArray<NIMMessage *> *)messages{
- /// 新消息处理
- NIMMessage *message = messages.firstObject;
- NIMSession *session = message.session;
- if (![session.sessionId isEqual:self.youpaipliveModel.youpaiproomid] || !messages.count){
- return;
- }
- [self youpaifuiAddMessages:messages];
- // [self.interactor markRead:NO];
- }
- #pragma mark - AgoraRtcEngineDelegate
- /// 重新连接
- - (void)rtcEngine:(AgoraRtcEngineKit *)engine didRejoinChannel:(NSString * _Nonnull)channel withUid:(NSUInteger)uid elapsed:(NSInteger)elapsed{
- if (self.youpaipisNetworkInterrupt && self.youpaifclientRole == AgoraClientRoleBroadcaster) {
- self.youpaipisNetworkInterrupt = NO;
- self.youpaippkdataView.hidden = YES;
- self.youpaippkdataView.youpaipattachment = nil;
- [self.youpaipagoraKit stopChannelMediaRelay];
- if (self.youpaipliveCloseBlock != nil) {
- self.youpaipliveCloseBlock();
- }
- }
- }
- ///网络连接中断,且 SDK 无法在 10 秒内连接服务器回调
- - (void)rtcEngineConnectionDidLost:(AgoraRtcEngineKit *_Nonnull)engine{
- self.youpaipisNetworkInterrupt = YES;
- }
- // 远端视频状态发生改变回调。
- - (void)rtcEngine:(AgoraRtcEngineKit * _Nonnull)engine
- remoteVideoStateChangedOfUid:(NSUInteger)uid state:(AgoraVideoRemoteState)state reason:(AgoraVideoRemoteReason)reason elapsed:(NSInteger)elapsed{
-
- YOUPAILZLiveVideoView *videoView = nil;
-
- if ([[NSString stringWithFormat:@"%@",@(uid)] isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
- videoView = self.youpaiplocalVideo;
- }else{
- videoView = self.youpaipremoteVideo;
- }
-
- if (state == AgoraVideoRemoteStateStopped /* || state == AgoraVideoRemoteStateFrozen*/) {
- videoView.youpaipisOff = YES;
- }else{
- videoView.youpaipisOff = NO;
- }
- }
- // 在远程用户的音频流静音/取消静音时发生。
- - (void)rtcEngine:(AgoraRtcEngineKit *)engine didAudioMuted:(BOOL)muted byUid:(NSUInteger)uid{
- if (muted) {//关闭了音频
- }else{
- }
- }
- - (void)rtcEngine:(AgoraRtcEngineKit *)engine didJoinedOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed{
- [self.youpaipagoraKit muteRemoteAudioStream:uid mute:NO];
- if (self.youpaifclientRole == AgoraClientRoleAudience) {
- if ([[NSString stringWithFormat:@"%@",@(uid)] isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
- self.youpaiplocalVideo.hidden = NO;
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.uid = uid;
- videoCanvas.view = self.youpaiplocalVideo.youpaipvideoView;
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- // 设置本地视图。
- self.youpaiplocalCanvas = videoCanvas;
- [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
- }else{
- self.youpaipremoteVideo.hidden = NO;
- self.youpaipremoteVideoBtn.hidden = NO;
- self.youpaipto_uid = [NSString stringWithFormat:@"%@",@(uid)];
- [self youpaifrequestLiveGetUser];
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.uid = uid;
- videoCanvas.view = self.youpaipremoteVideo.youpaipvideoView;
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- // 设置本地视图。
- self.youpaipremoteCanvas = videoCanvas;
- [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaiplocalVideo.layer.cornerRadius = 5.0f;
- self.youpaiplocalVideo.clipsToBounds = YES;
- self.youpaipremoteVideo.layer.cornerRadius = 5.0f;
- self.youpaipremoteVideo.clipsToBounds = YES;
- self.youpaiplocalVideo.frame = CGRectMake(0.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 0.5f, 270.0f);
- self.youpaipremoteVideo.frame = CGRectMake(KScreenWidth / 2.0f + 1.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 1.0f, 270.0f);
- }];
- self.youpaipcloseEnemyAudioBtn.hidden = NO;
-
- }
- }else{
- self.youpaipremoteVideo.hidden = NO;
- self.youpaipremoteVideoBtn.hidden = NO;
- self.youpaipto_uid = [NSString stringWithFormat:@"%@",@(uid)];
- [self youpaifrequestLiveGetUser];
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.uid = uid;
- videoCanvas.view = self.youpaipremoteVideo.youpaipvideoView;
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- // 设置本地视图。
- self.youpaipremoteCanvas = videoCanvas;
- [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaiplocalVideo.layer.cornerRadius = 5.0f;
- self.youpaiplocalVideo.clipsToBounds = YES;
- self.youpaipremoteVideo.layer.cornerRadius = 5.0f;
- self.youpaipremoteVideo.clipsToBounds = YES;
- self.youpaiplocalVideo.frame = CGRectMake(0.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 0.5f, 270.0f);
- self.youpaipremoteVideo.frame = CGRectMake(KScreenWidth / 2.0f + 1.0f, StatusBarHeight + 78.0f, KScreenWidth / 2.0f - 1.0f, 270.0f);
- }];
- self.youpaipcloseEnemyAudioBtn.hidden = NO;
- }
- }
- - (void)rtcEngine:(AgoraRtcEngineKit *)engine didOfflineOfUid:(NSUInteger)uid reason:(AgoraUserOfflineReason)reason{
- if (![[NSString stringWithFormat:@"%@",@(uid)] isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id]) {
- self.youpaipremoteVideo.hidden = YES;
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaiplocalVideo.layer.cornerRadius = 0.0f;
- self.youpaiplocalVideo.clipsToBounds = YES;
- self.youpaiplocalVideo.frame = self.view.bounds;
- }];
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.uid = uid;
- videoCanvas.view = nil;
- // 视图的渲染模式
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- // 设置远端视图。
- [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
- self.youpaipcloseEnemyAudioBtn.hidden = YES;
- self.youpaipcloseEnemyAudioBtn.selected = NO;
- self.youpaipfollowBgV.hidden = YES;
- self.youpaipremoteVideoBtn.hidden = YES;
- if (self.youpaipremoteVideoCloseBlock != nil) {
- self.youpaipremoteVideoCloseBlock();
- }
- }else{
- // if (self.youpaifclientRole == AgoraClientRoleAudience) {
- // if (self.youpaipliveCloseBlock != nil) {
- // self.youpaipliveCloseBlock();
- // }
- // }
- }
- }
- /// 本地音乐文件播放已结束回调
- - (void)rtcEngineLocalAudioMixingDidFinish:(AgoraRtcEngineKit *)engine{
- if (self.youpaipmusicPlayFinishBlock != nil) {
- self.youpaipmusicPlayFinishBlock();
- }
- }
- ///// 本地用户的音乐文件播放状态已改变回调
- //- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioMixingStateDidChanged:(AgoraAudioMixingStateCode)state errorCode:(AgoraAudioMixingErrorCode)errorCode{
- // if (self.youpaipmusicPlayStateBlock != nil) {
- // self.youpaipmusicPlayStateBlock(state);
- // }
- //}
-
- #pragma mark - AgoraVideoSourceProtocol
- // 初始化视频源
- - (BOOL)shouldInitialize{
- return YES;
- }
- // 启用视频源
- - (void)shouldStart{
- // [self.youpaipmCamera startCapture];
- }
- // 停止视频源
- - (void)shouldStop{
- // [self.youpaipmCamera stopCapture];
- }
- // 释放视频源
- - (void)shouldDispose{
-
- }
- //// 检索缓冲区类型
- //- (AgoraVideoBufferType)bufferType{
- // // 使用像素缓冲区传输视频数据
- // return AgoraVideoBufferTypePixelBuffer;
- //}
- //- (AgoraVideoCaptureType)captureType{
- // return AgoraVideoCaptureTypeCamera;
- //}
- #pragma mark - FUCameraDelegate
- -(void)didOutputVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer {
- CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer) ;
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- [[FUManager shareManager] renderItemsToPixelBuffer:pixelBuffer];
- CGSize frameSize;
- if (CVPixelBufferGetPixelFormatType(pixelBuffer) == kCVPixelFormatType_32BGRA) {
- frameSize = CGSizeMake(CVPixelBufferGetBytesPerRow(pixelBuffer) / 4, CVPixelBufferGetHeight(pixelBuffer));
- }else{
- frameSize = CGSizeMake(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
- }
- // push video frame to agora
- // [self.consumer consumePixelBuffer:pixelBuffer withTimestamp:CMSampleBufferGetPresentationTimeStamp(sampleBuffer) rotation:AgoraVideoRotationNone];
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.youpaipmessages.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NIMMessage *message = self.youpaipmessages[indexPath.row];
- if ([message isKindOfClass:[YOUPAILZLiveModel class]]) {
- NSString *cellID = @"YOUPAILZLiveFollowCell";
- YOUPAILZLiveFollowCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (cell == nil) {
- cell = [[YOUPAILZLiveFollowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- }
- [cell youpaifreloadWithModel:self.youpaipliveModel indexPath:indexPath];
- @weakify(self);
- [cell setYoupaipfollowBlock:^(YOUPAILZLiveModel * _Nonnull model, NSIndexPath * _Nonnull indexPath) {
- @strongify(self);
- [LCCommonHttp followUserId:model.youpaipuser_info.youpaipuser_id liveId:@"1"];
- [self.youpaipmessages removeObjectAtIndex:indexPath.row];
- [self.youpaipchatTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- [self youpaifreloadTableView];
- }];
- return cell;
- }else{
- NSString *cellID = @"YOUPAILZLiveChatMessageCell";
- YOUPAILZLiveChatMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (cell == nil) {
- cell = [[YOUPAILZLiveChatMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- [cell youpaifreloadWithModel:message font:self.youpaipliveModel.youpaipisMaxFont ? self.youpaipliveModel.youpaipmaxFont : self.youpaipliveModel.youpaipminFont indexPath:indexPath];
- @weakify(self);
- [cell setShowUserInfoBlock:^(NSIndexPath * _Nonnull indexPath1) {
- @strongify(self);
- NIMMessage *message = self.youpaipmessages[indexPath1.row];
-
- if (message.session.sessionType == NIMSessionTypeChatroom
- && message.messageType == NIMMessageTypeNotification){ /// 如果是聊天室并且消息类型为通知类型
- NIMNotificationObject *object = message.messageObject;
- if (![object.content isKindOfClass:[NIMUnsupportedNotificationContent class]]) {
- NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)object.content;
- NSString *fromId = nil;
- for (NIMChatroomNotificationMember *memebr in content.targets) {
- fromId = memebr.userId;
- }
- if (content.eventType == NIMChatroomEventTypeEnter) { /// 有成员加入聊天室
- fromId = message.from;
- }else if(content.eventType == NIMChatroomEventTypeExit){ /// 有成员离开聊天室
- fromId = message.from;
- }else if(content.eventType == NIMChatroomEventTypeKicked){ /// 聊天室成员被踢
- fromId = message.from;
- }
- [self youpaifshowUserInfoWithUserId:fromId];
- }
- }else{
- [self youpaifshowUserInfoWithUserId:message.from];
- }
- }];
- [cell setYoupaipreplyBlock:^(NSIndexPath * _Nonnull indexPath) {
- @strongify(self);
- NSString *nick = [NIMKitUtil showNick:message.from inMessage:message];
- self.youpaipsendMessageTF.text = [NSString stringWithFormat:@"@%@ ",nick];
- [self youpaifsendMessageBecomeFirstResponder];
- }];
- return cell;
- }
- }
- #pragma mark - UITableViewDelegate
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return [self.youpaipliveModel youpaifnoticeTextHeight];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
- UIView *v = [[UIView alloc] initWithFrame:CGRectMake(.0f, 0.0f, 276.0f, [self.youpaipliveModel youpaifnoticeTextHeight])];
- v.transform = CGAffineTransformMakeRotation(M_PI);
- UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(5.0f, 0, 266.0f, [self.youpaipliveModel youpaifnoticeTextHeight])];
- bgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
- bgV.layer.cornerRadius = 10.0f;
- bgV.clipsToBounds = YES;
- UILabel *youpaiptextL = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 10.0f, 236.0f, bgV.mj_h - 20.0f)];
- NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:self.youpaipliveModel.youpaipnotice_text];
- NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
- paragraphStyle1.alignment=NSTextAlignmentJustified;
- NSDictionary * dic =@{
- NSParagraphStyleAttributeName:paragraphStyle1,
- NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],
- };
- [attributedString1 setAttributes:dic range:NSMakeRange(0, attributedString1.length)];
- youpaiptextL.attributedText = attributedString1;
- youpaiptextL.numberOfLines = 0;
- youpaiptextL.textColor = HexColorFromRGB(0xFFA68B);
- youpaiptextL.font = self.youpaipliveModel.youpaipisMaxFont ? self.youpaipliveModel.youpaipmaxFont : self.youpaipliveModel.youpaipminFont;
- [bgV addSubview:youpaiptextL];
- [v addSubview:bgV];
- return v;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- // NIMMessage *message = self.messages[indexPath.row];
- // if ([message isKindOfClass:[YOUPAILZLiveModel class]]) {
- // [self youpaifshowUserInfoWithUserId:self.youpaipliveModel.user_info.user_id];
- // }else{
- // [self youpaifshowUserInfoWithUserId:message.from];
- // }
- }
- #pragma mark - UITextFieldDelegate
- -(BOOL)textFieldShouldReturn:(UITextField *)textField{
- NSString *text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- if (text.length != 0) {
- @weakify(self);
- [LCHttpHelper requestWithURLString:LiveSendMessage parameters:@{@"roomid":self.youpaipliveModel.youpaiproomid,@"content":text} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NIMSession *session = [NIMSession session:self.youpaipliveModel.youpaiproomid type:NIMSessionTypeChatroom];
- NIMMessage *imMessage = [NIMMessageMaker msgWithText:[[dict objectForKey:@"data"] objectForKey:@"content"]];
- if ([[[NIMSDK sharedSDK] chatManager] sendMessage:imMessage toSession:session error:nil]) {
- self.youpaipsendMessageTF.text = @"";
- [self youpaifhideKayboard];
- }
- }else{
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- return YES;
- }
- #pragma mark - getter and setter
- - (FUCamera *)youpaipmCamera {
- if (!_youpaipmCamera) {
- _youpaipmCamera = [[FUCamera alloc] init];
- _youpaipmCamera.delegate = self;
- }
- return _youpaipmCamera;
- }
- - (YOUPAILZLiveVideoView *)youpaiplocalVideo{
- if (!_youpaiplocalVideo) {
- _youpaiplocalVideo = [[YOUPAILZLiveVideoView alloc] initWithFrame:self.view.bounds];
- _youpaiplocalVideo.hidden = YES;
- }
- return _youpaiplocalVideo;
- }
- - (YOUPAILZLiveVideoView *)youpaipremoteVideo{
- if (!_youpaipremoteVideo) {
- _youpaipremoteVideo = [[YOUPAILZLiveVideoView alloc] initWithFrame:self.view.bounds];
- _youpaipremoteVideo.hidden = YES;
- }
- return _youpaipremoteVideo;
- }
- - (NSMutableArray<NIMMessage *> *)youpaipmessages{
- if (!_youpaipmessages) {
- _youpaipmessages = [NSMutableArray array];
- }
- return _youpaipmessages;
- }
- - (NSMutableArray *)youpaipgifts{// 礼物数据
- if (!_youpaipgifts) {
- _youpaipgifts = [NSMutableArray array];
- }
- return _youpaipgifts;
- }
- - (NSMutableArray<YOUPAILZLiveGiftView *> *)youpaipgiftViews{// 礼物
- if (!_youpaipgiftViews) {
- _youpaipgiftViews = [NSMutableArray array];
- }
- return _youpaipgiftViews;
- }
- - (NSMutableArray *)youpaipsvgas{
- if (!_youpaipsvgas) {
- _youpaipsvgas = [NSMutableArray array];
- }
- return _youpaipsvgas;
- }
- /// 设置用户角色
- - (AgoraClientRole)youpaifclientRole{
- return AgoraClientRoleBroadcaster;
- }
- /// 设置输入框焦点
- - (void)youpaifsendMessageBecomeFirstResponder{
- self.youpaipsendMessageTF.hidden = NO;
- [self.youpaipsendMessageTF becomeFirstResponder];
- }
- /// 隐藏键盘
- - (void)youpaifhideKayboard{
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.view endEditing:YES];
- self.youpaipsendMessageTF.hidden = YES;
- });
- }
- /// 刷新列表
- - (void)youpaifreloadChatList{
- [self.youpaipchatTableView reloadData];
- }
- /// 隐藏聊天列表
- - (void)youpaifhiddenChatList{
- CGFloat x = self.youpaipchatBgView.mj_x;
- x = x == 0.0f ? KScreenWidth : 0.0f;
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaipchatBgView.mj_x = x;
- }];
- }
- /// 关注
- - (void)youpaiffollow{
- NSInteger index = -1;
- for (NSInteger i = 0; i < self.youpaipmessages.count; i ++) {
- if ([self.youpaipmessages[i] isKindOfClass:[YOUPAILZLiveModel class]]) {
- index = i;
- }
- }
- if (index != -1) {
- [self.youpaipmessages removeObjectAtIndex:index];
- [self.youpaipchatTableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
- [self youpaifreloadTableView];
- }
- }
- /// 展示用户信息
- bool youpaipisShowUserInfo = YES;
- - (void)youpaifshowUserInfoWithUserId:(NSString *)userId{
- if (youpaipisShowUserInfo) {
- youpaipisShowUserInfo = NO;
- @weakify(self);
- [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":userId,@"no_visitor":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- youpaipisShowUserInfo = YES;
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- @strongify(self);
- YOUPAILCUserShowModel *showModel = [YOUPAILCUserShowModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
-
- NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc] init];
- request.roomId = self.youpaipliveModel.youpaiproomid;
- request.userIds = @[[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id,showModel.youpaipinfo.youpaipuserid];
- [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
- @strongify(self);
- if (members.count == 2) {
- NIMChatroomMember *mamber0 = members[0];
- NIMChatroomMember *mamber1 = members[1];
- BOOL youpaipisManage = NO;
- for (NSInteger i = 0; i < members.count; i ++) {
- NIMChatroomMember *member = members[i];
- if ([member.userId isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- youpaipisManage = member.type == NIMChatroomMemberTypeManager;
- }
- }
- if (mamber0.type == NIMChatroomMemberTypeManager && mamber1.type == NIMChatroomMemberTypeManager) {
- youpaipisManage = NO;
- }
- [self youpaifshowUserInfoWithModel:showModel youpaipisAnchor:self.youpaifclientRole == AgoraClientRoleBroadcaster youpaipisManage:youpaipisManage];
- }else if (members.count == 1){
- NIMChatroomMember *member = members[0];
- BOOL youpaipisManage = member.type == NIMChatroomMemberTypeManager;
- [self youpaifshowUserInfoWithModel:showModel youpaipisAnchor:self.youpaifclientRole == AgoraClientRoleBroadcaster youpaipisManage:youpaipisManage];
- }
- }];
- }
-
- } failure:^(NSError *error) {
- youpaipisShowUserInfo = YES;
- }];
-
- }
-
- }
- - (void)youpaifshowUserInfoWithModel:(YOUPAILCUserShowModel *)showModel youpaipisAnchor:(BOOL)youpaipisAnchor youpaipisManage:(BOOL)youpaipisManage{
- if ([showModel.youpaipinfo.youpaipuserid isEqual:self.youpaipliveModel.youpaipuser_info.youpaipuser_id] || [showModel.youpaipinfo.youpaipuserid isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- youpaipisAnchor = NO;
- youpaipisManage = NO;
- }
- @weakify(self);
- YOUPAILZLiveUserInfoWindow *vc = [[YOUPAILZLiveUserInfoWindow alloc] initWithModel:showModel isAnchor:youpaipisAnchor isManage:youpaipisManage];
- vc.isTouchDismiss = YES;
- [vc setYoupaipuserShowBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
- @strongify(self);
- if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
- self.youpaipisNotPanClose = YES;
- YOUPAILZUserShowVC *vc = [[YOUPAILZUserShowVC alloc] init];
- vc.youpaipuserId = model.youpaipinfo.youpaipuserid;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }];
- [vc setYoupaipreportBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
- @strongify(self);
- if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
- self.youpaipisNotPanClose = YES;
-
-
-
- ZCAlertAction *action = [ZCAlertAction actionWithTitle:@"举报" andblock:^{//举报
- @strongify(self);
- YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init];
- report.youpaipreport_uid = model.youpaipinfo.youpaipuserid;
- report.youpaiptype = 5;
- [self.navigationController pushViewController:report animated:YES];
- }];
-
- ZCAlertAction *action1 = [ZCAlertAction actionWithTitle:@"拉黑" andblock:^{//举报
- @strongify(self);
- [self youpaifshowAddBlackWithUserId:model.youpaipinfo.youpaipuserid];
- }];
- ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[action,action1]];
- //modify by leo --fix bug ios13 20191009
- //alertSheet.alertWindow.rootViewController = self;
- alertSheet.alertWindow.hidden = NO;
- [alertSheet show];
-
- }
- // [weakSelf ReportOrBlackSelector];
-
- }];
- [vc setYoupaipgiftBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
- @strongify(self);
- if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
- NSInteger type = 1;
- NSString *youpaipto_uid = model.youpaipinfo.youpaipuserid;
- BOOL youpaipisCurrentAnchor = NO;
- if ([self.youpaipliveModel.youpaipuser_info.youpaipuser_id isEqual:model.youpaipinfo.youpaipuserid]) {
- type = 5;
- youpaipto_uid = self.youpaipliveModel.youpaipuser_info.youpaipuser_id;
- youpaipisCurrentAnchor = YES;
- }
-
- YOUPAILZCommonGiftView *view = [YOUPAILZCommonGiftView new];
- view.isTouchDismiss = YES;
- view.youpaipcountDown = 3;
- view.youpaipisAnchor = youpaipisAnchor;
- [view setYoupaiplzgiftblock:^(YOUPAILCGiftModel * _Nonnull model, NSInteger count,NSString*categoryID) {
- //1个人详情页 2IM页面 3视频中 4收到礼物页面赠送
- NSMutableDictionary *params = @{@"type":@(type),@"to_uid":youpaipto_uid,@"gift_id":model.youpaipid,@"num":@(count),@"gift_type_id":categoryID}.mutableCopy;
- if (youpaipisCurrentAnchor) {
- [params setValue:self.youpaipliveModel.youpaiplive_id forKey:@"live_id"];
- }
- [LCHttpHelper requestWithURLString:SendGift_New parameters:params.copy needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- [ZCHUDHelper showTitle:@"礼物赠送成功"];
- }
- } failure:^(NSError *error) {
-
- }];
-
- }];
- [view setYoupaiptouchAdvertBlock:^(YOUPAILCBannerModel * _Nonnull bannerModel) {
- @strongify(self);
- if (bannerModel.youpaiplink_type==1) {
- ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
- baseWeb.contentUrl = bannerModel.youpaiplink_url;
- self.youpaipisNotPanClose = YES;
- [self.navigationController pushViewController:baseWeb animated:YES];
- }else if (bannerModel.youpaiplink_type==2||bannerModel.youpaiplink_type==3){
- [self youpaifpageToStr:bannerModel.youpaiplink_url];
- }
-
- }];
- [self TFPresentVC:view completion:^{
-
-
- }];
- }else{
- [ZCHUDHelper showTitle:@"你在直播中,暂时不可以送礼物"];
- }
-
- }];
- [vc setYoupaipguardBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
- @strongify(self);
- if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
- BOOL youpaipisCurrentAnchor = NO;
- if ([self.youpaipliveModel.youpaipuser_info.youpaipuser_id isEqual:model.youpaipinfo.youpaipuserid]) {
- youpaipisCurrentAnchor = YES;
- }
-
-
- [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id,@"no_visitor":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- @strongify(self);
- YOUPAILCUserShowModel *showModel = [YOUPAILCUserShowModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
- YOUPAILPGuardHerVC *VC= [[YOUPAILPGuardHerVC alloc]init];
- VC.youpaipdelegate = self;
- VC.youpaipuser_id = self.youpaipliveModel.youpaipuser_info.youpaipuser_id;
- VC.vWidth = KScreenWidth-54;
- VC.vHeight = ((KScreenWidth-54)*165)/321.0+261.5;
- VC.youpaipinfoModel = showModel.youpaipguard;
- if (youpaipisCurrentAnchor) {
- VC.youpaipliveid = self.youpaipliveModel.youpaiplive_id;
- }
- VC.isTouchDismiss = YES;
- if(VC.youpaipinfoModel!=nil)
- [self TFPresentVC:VC completion:^{
-
- }];
- }else{
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }else{
- [ZCHUDHelper showTitle:@"你在直播中,暂时不可以送守护"];
- }
- }];
- [vc setYoupaipsiXinBlock:^(YOUPAILCUserShowModel * _Nonnull model) {
- @strongify(self);
- if (self.youpaifclientRole != AgoraClientRoleBroadcaster) {
- NIMSession *session = [NIMSession session:model.youpaipinfo.youpaipuserid type:NIMSessionTypeP2P];
- if (session) {
- self.youpaipisNotPanClose = YES;
- [ZCHUDHelper show];
- [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
- @strongify(self);
- [ZCHUDHelper dismiss];
- YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
- [self.navigationController pushViewController:vc animated:YES];
- }];
-
- }
- }else{
-
- [ZCHUDHelper showTitle:@"你在直播中,暂时不可以私信"];
- }
- }];
- [vc setYoupaipmanageBlock:^(YOUPAILCUserShowModel * _Nonnull model, BOOL youpaipisAnchor) {
- @strongify(self);
- [self youpaifshowliveMembersManageWithModel:model youpaipisAnchor:youpaipisAnchor];
- }];
- [self TFPresentVC:vc completion:^{}];
- }
- /// 直播间管理
- - (void)youpaifshowliveMembersManageWithModel:(YOUPAILCUserShowModel *)model youpaipisAnchor:(BOOL)youpaipisAnchor{
- NSMutableArray* actionArray = [NSMutableArray array];
- @weakify(self);
- if (youpaipisAnchor) {
- ZCAlertAction *manageAction = [ZCAlertAction actionWithTitle:@"设为管理员" andblock:^{
- @strongify(self);
- NIMChatroomMemberUpdateRequest *request = [[NIMChatroomMemberUpdateRequest alloc] init];
- request.roomId = self.youpaipliveModel.youpaiproomid;
- request.userId = model.youpaipinfo.youpaipuserid;
- request.enable = YES;
-
- NIMChatroomMembersByIdsRequest *idRequest = [[NIMChatroomMembersByIdsRequest alloc] init];
- idRequest.roomId = self.youpaipliveModel.youpaiproomid;
- idRequest.userIds = @[model.youpaipinfo.youpaipuserid];
- [[[NIMSDK sharedSDK] chatroomManager] fetchChatroomMembersByIds:idRequest completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
- if (members.count != 0 && members[0].type == NIMChatroomMemberTypeManager) {
- [ZCHUDHelper showTitle:@"TA已经是管理员"];
- }else{
- [[[NIMSDK sharedSDK] chatroomManager] markMemberManager:request completion:^(NSError * _Nullable error) {
- if (error) {
- [ZCHUDHelper showTitle:@"设置管理员失败"];
- }else{
- [ZCHUDHelper showTitle:@"设置管理员成功"];
- }
- }];
- }
- }];
- }];
- [actionArray addObject:manageAction];
-
- ZCAlertAction *membersManageAction = [ZCAlertAction actionWithTitle:@"成员管理" andblock:^{
- @strongify(self);
- [self youpaifshowMemberManageAlert];
- }];
- [actionArray addObject:membersManageAction];
- }
- ZCAlertAction *disableSendMsgAction = [ZCAlertAction actionWithTitle:@"禁言" andblock:^{
- @strongify(self);
- [self youpaifshowDisableSendMessageAlertWithUserId:model.youpaipinfo.youpaipuserid];
- }];
- [actionArray addObject:disableSendMsgAction];
-
- ZCAlertAction *outRoomAction = [ZCAlertAction actionWithTitle:@"踢出房间" andblock:^{
- @strongify(self);
- LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
- @strongify(self);
- NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"kick",@"forbidden_uid":model.youpaipinfo.youpaipuserid};
- [self youpaifhandleLiveMemberWithParams:params];
- }];
- cancelAction.cornerRadius = 24.0f;
- cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
-
- }];
- confimAction.cornerRadius = 24.0f;
- confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
- LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"" content:@"踢出房间后\n本场直播该用户将无法进入" action:@[cancelAction,confimAction]];
- alert.contentTextAlignment = NSTextAlignmentCenter;
- [self TFPresentVC:alert completion:^{}];
- }];
- [actionArray addObject:outRoomAction];
- if (youpaipisAnchor) {
- ZCAlertAction *addBlockAction = [ZCAlertAction actionWithTitle:@"拉黑" andblock:^{
- @strongify(self);
- [self youpaifshowAddBlackWithUserId:model.youpaipinfo.youpaipuserid];
- }];
- [actionArray addObject:addBlockAction];
- }
- ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray];
- alertSheet.alertWindow.hidden = NO;
- [alertSheet show];
- }
- /// 拉黑弹框
- - (void)youpaifshowAddBlackWithUserId:(NSString *)userId{
- @weakify(self);
- LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
-
- }];
- cancelAction.cornerRadius = 24.0f;
- cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
- @strongify(self);
- [LCCommonHttp blackUserId:userId liveId:self.youpaipliveModel.youpaiplive_id];
- }];
- confimAction.cornerRadius = 24.0f;
- confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
- LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"拉黑后,你将不再收到对方的消息,并且你们互相看不到对方的动态更新。可以在“设置-黑名单”中解除。" action:@[cancelAction,confimAction]];
- alert.contentTextAlignment = NSTextAlignmentCenter;
- [self TFPresentVC:alert completion:^{}];
-
- }
- /// 显示禁言弹框
- - (void)youpaifshowDisableSendMessageAlertWithUserId:(NSString *)userId{
- @weakify(self);
- NSMutableArray* actionArray = [NSMutableArray array];
- ZCAlertAction *disableSendMessageAction1 = [ZCAlertAction actionWithTitle:@"禁言5分钟" andblock:^{
- @strongify(self);
- NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(5*60)]};
- [self youpaifhandleLiveMemberWithParams:params];
- }];
- [actionArray addObject:disableSendMessageAction1];
- ZCAlertAction *disableSendMessageAction2 = [ZCAlertAction actionWithTitle:@"禁言1小时" andblock:^{
- @strongify(self);
- NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(60*60)]};
- [self youpaifhandleLiveMemberWithParams:params];
- }];
- [actionArray addObject:disableSendMessageAction2];
- ZCAlertAction *disableSendMessageAction3 = [ZCAlertAction actionWithTitle:@"禁言24小时" andblock:^{
- @strongify(self);
- NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(24*60*60)]};
- [self youpaifhandleLiveMemberWithParams:params];
- }];
- [actionArray addObject:disableSendMessageAction3];
- ZCAlertAction *disableSendMessageAction4 = [ZCAlertAction actionWithTitle:@"永久禁言" andblock:^{
- @strongify(self);
- NSDictionary *params = @{@"live_id":self.youpaipliveModel.youpaiplive_id,@"type":@"mute",@"forbidden_uid":userId,@"time":[NSString stringWithFormat:@"%@",@(-1)]};
- [self youpaifhandleLiveMemberWithParams:params];
- }];
- [actionArray addObject:disableSendMessageAction4];
- ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:NO andAction:actionArray];
- alertSheet.alertWindow.hidden = NO;
- [alertSheet show];
- }
- /// 成员管理弹框
- - (void)youpaifshowMemberManageAlert{
- @weakify(self);
- NSMutableArray* actionArray = [NSMutableArray array];
- ZCAlertAction *manageListAction = [ZCAlertAction actionWithTitle:@"管理员列表" andblock:^{
- @strongify(self);
- [self youpaifshowManageListWindowWithType:LZLiveManageListTypeWithManage title:@"管理员管理"];
- }];
- [actionArray addObject:manageListAction];
- ZCAlertAction *disableSendMessageListAction = [ZCAlertAction actionWithTitle:@"禁言列表" andblock:^{
- @strongify(self);
- [self youpaifshowManageListWindowWithType:LZLiveManageListTypeWithDisableSendMessage title:@"禁言管理"];
- }];
- [actionArray addObject:disableSendMessageListAction];
- ZCAlertAction *outRoomListAction = [ZCAlertAction actionWithTitle:@"踢人列表" andblock:^{
- @strongify(self);
- [self youpaifshowManageListWindowWithType:LZLiveManageListTypeWithForbidden title:@"踢人管理"];
- }];
- [actionArray addObject:outRoomListAction];
-
- ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:NO andAction:actionArray];
- alertSheet.alertWindow.hidden = NO;
- [alertSheet show];
- }
- - (void)youpaifshowManageListWindowWithType:(LZLiveManageListType)type title:(NSString *)title{
- YOUPAILZLiveManageListWindow *window = [[YOUPAILZLiveManageListWindow alloc] init];
- window.youpaiptype = type;
- window.youpaiptitleText = title;
- window.youpaipliveModel = self.youpaipliveModel;
- window.isTouchDismiss = YES;
- [self TFPresentVC:window completion:^{
- }];
- }
- - (void)youpaifhandleLiveMemberWithParams:(NSDictionary *)params{
- [LCHttpHelper requestWithURLString:ForBiddenUser parameters:params needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- /// 直播中对方女神的信息
- - (void)youpaifrequestLiveGetUser{
- @weakify(self);
- [LCHttpHelper requestWithURLString:LiveGetUser parameters:@{@"user_id":self.youpaipto_uid} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- @strongify(self);
- if (code==0) {//成功
- [self youpaifreloadWithFollowModel:[YOUPAILCUserShowInfo mj_objectWithKeyValues:[dict objectForKey:@"data"]]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- @end
|