BGLiveServiceController.m 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257
  1. //
  2. // BGLiveServiceController.m
  3. // BugoLive
  4. //
  5. // Created by xfg on 16/11/23.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "BGLiveServiceController.h"
  9. #import "BGMD5UTils.h"
  10. #import "PKUserListViewController.h"
  11. #define MESSAGE_SURVIVAL_TIME 20
  12. #define BARRAGE_VIEW_ANIMATE_TIME 10
  13. #import "CarAnimationPlayer.h"
  14. #import "WardPopView.h"
  15. //#import "WardOpenView.h"
  16. #import "BogoWardOpenView.h"
  17. #import "WardTipView.h"
  18. #import "WardPrivilegeButton.h"
  19. #import "WardPopViewModel.h"
  20. #import "MGShopView.h"
  21. #import "BogoShopKit.h"
  22. #import "BogoNetworkKit.h"
  23. #import "BogoGoodDetailViewController.h"
  24. #import "BogoRechargePopView.h"
  25. #import <ImSDK_Plus/ImSDK_Plus.h>
  26. #import "BGOpenRedPackView.h"
  27. #import "BGRedPackModel.h"
  28. #import "BogoGuardianModel.h"
  29. #import "BGOpenRedPackView.h"
  30. #import "BGRedPackModel.h"
  31. @interface BGLiveServiceController ()<CarAnimationPlayerDelegate,BogoLiveCartPopViewDelegate>
  32. @property (nonatomic, strong) WardTipView *tipView;
  33. @property(nonatomic, strong) MMAlertView *pkAcceptAlert;
  34. @property(nonatomic, strong) MGShopView *shopView;
  35. @property(nonatomic, strong) BogoLiveCartPopView *cartPopView;
  36. @property(nonatomic, strong) BogoRechargePopView *rechargePopView;
  37. @end
  38. @implementation BGLiveServiceController
  39. #pragma mark ------------------------ 直播生命周期 -----------------------
  40. - (void)releaseAll
  41. {
  42. _liveController = nil;
  43. _addGiftRunLoopRef = nil;
  44. _getGiftRunLoopRef = nil;
  45. [[NSNotificationCenter defaultCenter] removeObserver:self];
  46. if (_giftLoopTimer)
  47. {
  48. [_giftLoopTimer invalidate];
  49. _giftLoopTimer = nil;
  50. }
  51. if (_heartTimer)
  52. {
  53. [_heartTimer invalidate];
  54. _heartTimer = nil;
  55. }
  56. // // 关闭竞拍相关的定时器
  57. // [self.auctionTool closeTimer];
  58. self.rechargeView.viewController = nil;
  59. }
  60. - (void)dealloc
  61. {
  62. [self releaseAll];
  63. }
  64. #pragma mark 开始直播
  65. - (void)startLive
  66. {
  67. [_liveUIViewController startLive];
  68. }
  69. #pragma mark 暂停直播
  70. - (void)pauseLive
  71. {
  72. if (_heartTimer)
  73. {
  74. [_heartTimer invalidate];
  75. _heartTimer = nil;
  76. }
  77. if (_giftLoopTimer)
  78. {
  79. [_giftLoopTimer invalidate];
  80. _giftLoopTimer = nil;
  81. }
  82. [_liveUIViewController pauseLive];
  83. }
  84. #pragma mark 重新开始直播
  85. - (void)resumeLive
  86. {
  87. if (_isHost)
  88. {
  89. [self startLiveTimer];
  90. }
  91. [self biginGiftLoop];
  92. [_liveUIViewController resumeLive];
  93. }
  94. #pragma mark 重新加载直播间的游戏数据
  95. - (void)reloadGame
  96. {
  97. _liveUIViewController.liveView.shouldReloadGame = YES;
  98. _liveUIViewController.liveView.sureOnceGame = NO;
  99. [self reloadGameData];
  100. }
  101. #pragma mark 结束直播
  102. - (void)endLive
  103. {
  104. [self releaseAll];
  105. [_liveUIViewController endLive];
  106. [_liveUIViewController.view removeFromSuperview];
  107. }
  108. #pragma mark 初始化房间信息等
  109. - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem liveController:(id<FWLiveControllerAble>)liveController
  110. {
  111. if (self = [super init])
  112. {
  113. _liveItem = liveItem;
  114. [GlobalVariables sharedInstance].isBeingPK = NO;
  115. _roomIDStr = StringFromInt([_liveItem liveAVRoomId]);
  116. _isHost = [liveItem isHost];
  117. _liveController = liveController;
  118. _liveUIViewController = [[BGLiveUIViewController alloc] initWith:_liveItem liveController:liveController];
  119. _liveUIViewController.serviceDelegate = self;
  120. [self addChild:_liveUIViewController inRect:self.view.bounds];
  121. [self.view bringSubviewToFront:_closeBtn];
  122. _liveUIViewController.liveView.serveceDelegate = self;
  123. _liveUIViewController.liveView.topView.toServicedelegate = self;
  124. _liveUIViewController.liveView.msgView.delegate = self;
  125. _iMMsgHandler = [BGIMMsgHandler sharedInstance];
  126. _iMMsgHandler.iMMsgListener = self;
  127. // 创建插件中心
  128. if (_isHost)
  129. {
  130. [self creatPluginCenter];
  131. }
  132. }
  133. return self;
  134. }
  135. - (void)viewWillAppear:(BOOL)animated{
  136. [super viewWillAppear:animated];
  137. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pkToPunish:) name:kPKChangeToPunish object:nil];
  138. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endPunish) name:@"endPunish" object:nil];
  139. //把某个人静音
  140. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMuteUser:) name:@"NOTIFY_onMuteUser" object:nil];
  141. }
  142. - (void)onMuteUser:(NSNotification *)noti {
  143. NSDictionary *responseDict = noti.object;
  144. NSString *uid = responseDict[@"uid"];
  145. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  146. sendCustomMsgModel.msgType = MSG_LianMai_Mute;
  147. sendCustomMsgModel.to_user_id = uid;
  148. sendCustomMsgModel.chatGroupID = [_liveItem liveIMChatRoomId];
  149. sendCustomMsgModel.mute_status = 1;
  150. [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  151. }
  152. #pragma mark - kPKChangeToPunish
  153. - (void)pkToPunish:(NSNotification *)noti{
  154. NSDictionary *responseDict = noti.object;
  155. NSString *win_user_id = [NSString stringWithFormat:@"%@",responseDict[@"win_user_id"]];
  156. NSString *time = [NSString stringWithFormat:@"%@",responseDict[@"time"]];
  157. NSString *pk_ticket1 = responseDict[@"pk_ticket1"];
  158. NSString *pk_ticket2 = responseDict[@"pk_ticket2"];
  159. if([win_user_id isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier])
  160. {
  161. [FanweMessage alert:ASLocalizedString(@"恭贺您pk取得胜利")];
  162. }
  163. //2020-1-4 pk结束
  164. self.pluginCenterBgView.hidden = YES;
  165. [self->_liveUIViewController pkVivewEnd:win_user_id anddic:responseDict];
  166. dispatch_async(dispatch_get_main_queue(), ^{
  167. NSInteger emcee_user_id1 = [responseDict[@"emcee_user_id1"] integerValue];
  168. NSInteger user_id = _currentLiveInfo.user_id.integerValue;
  169. NSInteger imUserId = [IMAPlatform sharedInstance].host.imUserId.integerValue;
  170. if (emcee_user_id1 == user_id || emcee_user_id1 == imUserId) {
  171. [self->_liveUIViewController.fpkProgress setLeftValue:pk_ticket1.floatValue];
  172. [self->_liveUIViewController.fpkProgress setRightValue:pk_ticket2.floatValue];
  173. }else{
  174. [self->_liveUIViewController.fpkProgress setLeftValue:pk_ticket2.floatValue];
  175. [self->_liveUIViewController.fpkProgress setRightValue:pk_ticket1.floatValue];
  176. }
  177. [self->_liveUIViewController switchToPunish:117+time.intValue];
  178. });
  179. }
  180. #pragma mark - pk操作
  181. -(void)pkController:(int)type WidthData:(id)obj
  182. {
  183. if ([GlobalVariables sharedInstance].isBeingLinkMic) {
  184. [FanweMessage alertHUD:ASLocalizedString(@"连麦中不能pk")];
  185. return;
  186. }
  187. //发起pk
  188. if(type == 0)
  189. {
  190. UserModel *user = obj;
  191. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  192. sendCustomMsgModel.msgType = MSG_REQEUST_PK;
  193. sendCustomMsgModel.msgReceiver = user;
  194. sendCustomMsgModel.pkid = user.pk_id;
  195. [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:^{
  196. NSLog(ASLocalizedString(@"发送PK消息成功"));
  197. } fail:^(int code, NSString *msg) {
  198. NSLog(ASLocalizedString(@"发送PK消息失败msg:%@"),msg);
  199. }];
  200. // [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  201. }
  202. else if(type == 1)//同意操作
  203. {
  204. UserModel *user = obj;
  205. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  206. if(![GlobalVariables sharedInstance].openAgora)
  207. {
  208. [mDict setObject:@"pk_tencent" forKey:@"ctl"];
  209. }
  210. else
  211. {
  212. [mDict setObject:@"pk_agora" forKey:@"ctl"];
  213. }
  214. [mDict setObject:@"request_accept_pk" forKey:@"act"];
  215. [mDict setObject:user.user_id.length ? user.user_id : @"" forKey:@"pk_emcee_id"];
  216. [mDict setObject:user.pk_id.length ? user.pk_id : @"" forKey:@"pk_id"];
  217. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  218. if ([responseJson toInt:@"status"] == 1)
  219. {
  220. NSString *pid = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"pk_id"]];
  221. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  222. sendCustomMsgModel.msgType = MSG_ACCEPT_PK;
  223. sendCustomMsgModel.msgReceiver = user;
  224. [_liveUIViewController pkViewWith:pid ];
  225. [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel widthPID:pid succ:^{
  226. } fail:^(int code, NSString *msg) {
  227. }];
  228. }
  229. else
  230. {
  231. [[BGHUDHelper sharedInstance] tipMessage:[responseJson valueForKey:@"error"]];
  232. }
  233. } FailureBlock:^(NSError *error) {
  234. }];
  235. // request_start_pk
  236. }
  237. else if(type == 2)//拒绝pk
  238. {
  239. UserModel *user = obj;
  240. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  241. if(![GlobalVariables sharedInstance].openAgora)
  242. {
  243. [mDict setObject:@"pk_tencent" forKey:@"ctl"];
  244. }
  245. else
  246. {
  247. [mDict setObject:@"pk_agora" forKey:@"ctl"];
  248. }
  249. [mDict setObject:@"request_refused_pk" forKey:@"act"];
  250. [mDict setObject:user.user_id.length ? user.user_id : @"" forKey:@"pk_emcee_id"];
  251. [mDict setObject:user.pk_id.length ? user.pk_id : @"" forKey:@"pk_id"];
  252. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  253. if ([responseJson toInt:@"status"] == 1)
  254. {
  255. NSString *pid = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"pk_id"]];
  256. UserModel *user = obj;
  257. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  258. sendCustomMsgModel.msgType = MSG_REJECT_PK;
  259. sendCustomMsgModel.msgReceiver = user;
  260. [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:^{
  261. } fail:^(int code, NSString *msg) {
  262. }];
  263. }
  264. else
  265. {
  266. // [[BGHUDHelper sharedInstance] tipMessage:[responseJson valueForKey:@"error"]];
  267. }
  268. } FailureBlock:^(NSError *error) {
  269. }];
  270. }else if(type == 3)//取消pk
  271. {
  272. UserModel *user = obj;
  273. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  274. if(![GlobalVariables sharedInstance].openAgora)
  275. {
  276. [mDict setObject:@"pk_tencent" forKey:@"ctl"];
  277. }
  278. else
  279. {
  280. [mDict setObject:@"pk_agora" forKey:@"ctl"];
  281. }
  282. [mDict setObject:@"request_refused_pk" forKey:@"act"];
  283. [mDict setObject:user.user_id.length ? user.user_id : @"" forKey:@"pk_emcee_id"];
  284. [mDict setObject:user.pk_id.length ? user.pk_id : @"" forKey:@"pk_id"];
  285. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  286. if ([responseJson toInt:@"status"] == 1)
  287. {
  288. NSString *pid = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"pk_id"]];
  289. UserModel *user = obj;
  290. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  291. sendCustomMsgModel.msgType = MSG_CANCEL_PK;
  292. sendCustomMsgModel.msgReceiver = user;
  293. [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:^{
  294. } fail:^(int code, NSString *msg) {
  295. }];
  296. }
  297. else
  298. {
  299. }
  300. } FailureBlock:^(NSError *error) {
  301. }];
  302. }
  303. [_pkAcceptAlert hide];
  304. _pkAcceptAlert = nil;
  305. }
  306. #pragma mark 请求完接口后,刷新直播间相关信息
  307. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  308. {
  309. _liveItem = liveItem;
  310. _roomIDStr = StringFromInt([_liveItem liveAVRoomId]);
  311. _isHost = [liveItem isHost];
  312. [_liveUIViewController refreshLiveItem:_liveItem liveInfo:liveInfo];
  313. [self setupFinishView:liveInfo];
  314. }
  315. - (void)viewDidLoad
  316. {
  317. [super viewDidLoad];
  318. self.view.backgroundColor = kClearColor;
  319. }
  320. #pragma mark 初始化变量
  321. - (void)initFWVariables
  322. {
  323. [super initFWVariables];
  324. // 礼物相关
  325. // 为了不影响视频,runloop线程优先级较低,可根据自身需要去调整
  326. _addGiftRunLoopRef = [AddGiftRunLoop sharedAddGiftRunLoop];
  327. _getGiftRunLoopRef = [GetGiftRunLoop sharedGetGiftRunLoop];
  328. _gifAnimateArray = [NSMutableArray array];
  329. _aCYCarViewwArray = [NSMutableArray array];
  330. _gifAnimateArray = [NSMutableArray array];
  331. _giftMessageMArray = [NSMutableArray array];
  332. _giftMessageMDict = [NSMutableDictionary dictionary];
  333. _giftMessageViewMArray = [NSMutableArray array];
  334. _otherRoomBitGiftArray = [NSMutableArray array];
  335. [self loadGiftView:[GiftListManager sharedInstance].giftMArray];
  336. [self performSelector:@selector(biginGiftLoop) onThread:_getGiftRunLoopRef.thread withObject:_giftMessageMArray waitUntilDone:NO];
  337. // 弹幕消息视图队列
  338. _barrageViewArray = [[NSMutableArray alloc] init];
  339. // 高级别观众进入视图队列
  340. _aETViewArray = [[NSMutableArray alloc] init];
  341. //中奖队列
  342. _winTipViewArray = [[NSMutableArray alloc]init];
  343. //座驾视图
  344. _aCYCarView = [[CarAnimationPlayer alloc] initWithFrame:self.view.bounds];
  345. _aCYCarView.delegate = self;
  346. [self.view addSubview:_aCYCarView];
  347. _aCYCarView.hidden = YES;
  348. }
  349. #pragma mark UI创建
  350. - (void)initFWUI
  351. {
  352. [super initFWUI];
  353. _closeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  354. _closeBtn.frame = CGRectMake(kScreenW-kDefaultMargin-kLogoContainerViewHeight, kStatusBarHeight+kDefaultMargin/2, kLogoContainerViewHeight, kLogoContainerViewHeight);
  355. _closeBtn.backgroundColor = [UIColor clearColor];
  356. [_closeBtn setBackgroundImage:[UIImage imageNamed:@"lr_top_close"] forState:UIControlStateNormal];
  357. [_closeBtn addTarget:self action:@selector(onClickClose:) forControlEvents:UIControlEventTouchUpInside];
  358. _closeBtn.hidden = YES;
  359. [self.view addSubview:_closeBtn];
  360. _anchorLeaveTipLabel = [[UILabel alloc]initWithFrame:CGRectMake(kDefaultMargin, (kScreenH-35)/3, kScreenW-kDefaultMargin*2, 35)];
  361. _anchorLeaveTipLabel.textColor = [UIColor whiteColor];
  362. _anchorLeaveTipLabel.text = ASLocalizedString(@"主播暂时离开下,马上回来!");
  363. _anchorLeaveTipLabel.font = [UIFont systemFontOfSize:15.0];
  364. _anchorLeaveTipLabel.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
  365. _anchorLeaveTipLabel.shadowOffset = CGSizeMake(1, 1);
  366. _anchorLeaveTipLabel.textAlignment = NSTextAlignmentCenter;
  367. [self.view addSubview:_anchorLeaveTipLabel];
  368. _anchorLeaveTipLabel.hidden = YES;
  369. // // 高级别观众进入提示动画页面
  370. // _aETView = [[AudienceEnteringTipView alloc]initWithMyFrame:CGRectMake(-kScreenW, kAudienceEnteringTipViewHeight, kScreenW, 35)];
  371. // [_liveUIViewController.liveView addSubview:_aETView];
  372. // _aETView.hidden = YES;
  373. //中奖提示
  374. _winTipView = [[WinTipView alloc]initWithFrame:CGRectMake(kScreenW, kOpenTipViewHeight, kScreenW - 20, 44)];
  375. [_liveUIViewController.liveView addSubview:_winTipView];
  376. _winTipView.hidden = YES;
  377. }
  378. #pragma mark 加载数据
  379. - (void)initFWData
  380. {
  381. [super initFWData];
  382. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadGame) name:UIApplicationWillEnterForegroundNotification object:nil];
  383. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onClickClose:) name:KLOGIN_OUT_Notification object:nil];
  384. // 是否显示关注
  385. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isShowFollow:) name:@"liveIsShowFollow" object:nil];
  386. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endPunish) name:@"endPunish" object:nil];
  387. // 今日任务完成关闭每日任务
  388. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeEverydayTask) name:@"closeEverydayTask" object:nil];
  389. }
  390. #pragma mark - ----------------------- 非SDK业务逻辑 -----------------------
  391. #pragma mark 开启主播心跳监听定时器
  392. - (void)startLiveTimer
  393. {
  394. if (_heartTimer)
  395. {
  396. [_heartTimer invalidate];
  397. _heartTimer = nil;
  398. }
  399. NSInteger monitorSecond = 0;
  400. if (self.BuguLive.appModel.monitor_second)
  401. {
  402. monitorSecond = self.BuguLive.appModel.monitor_second;
  403. }
  404. else
  405. {
  406. monitorSecond = 5;
  407. }
  408. _heartTimer = [NSTimer scheduledTimerWithTimeInterval:monitorSecond target:self selector:@selector(onPostHeartBeat) userInfo:nil repeats:YES];
  409. [[NSRunLoop currentRunLoop] addTimer:_heartTimer forMode:NSRunLoopCommonModes];
  410. }
  411. #pragma mark 主播心跳监听
  412. - (void)onPostHeartBeat
  413. {
  414. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  415. [mDict setObject:@"video" forKey:@"ctl"];
  416. [mDict setObject:@"monitor" forKey:@"act"];
  417. [mDict setObject:_roomIDStr.length ? _roomIDStr : @"" forKey:@"room_id"];
  418. [mDict setObject:@"-1" forKey:@"watch_number"]; //观看人数
  419. [mDict setObject:[NSString stringWithFormat:@"%ld",(long)_voteNumber] forKey:@"vote_number"]; //主播当前印票
  420. if ([_liveItem liveType] == FW_LIVE_TYPE_HOST)
  421. {
  422. [mDict setObject:[_liveController getLiveQuality] forKey:@"live_quality"];
  423. }
  424. FWWeakify(self)
  425. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  426. FWStrongify(self)
  427. if ([responseJson toInt:@"status"] == 1)
  428. {
  429. if ([responseJson objectForKey:@"live"])
  430. {
  431. if (self.liveUIViewController.livePay.hostLeftPView.threeLabel)
  432. {
  433. [self.liveUIViewController.livePay.hostLeftPView addThreeLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[[responseJson objectForKey:@"live"] toInt:@"live_viewer"]]];
  434. }else
  435. {
  436. if (self.liveUIViewController.livePay.hostLeftPView.secondLabel)
  437. {
  438. [self.liveUIViewController.livePay.hostLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[[responseJson objectForKey:@"live"] toInt:@"live_viewer"]]];
  439. }
  440. }
  441. [self.liveUIViewController.liveView.topView refreshTicketCount:[NSString stringWithFormat:@"%d",[[responseJson objectForKey:@"live"] toInt:@"ticket"]]];
  442. self.liveUIViewController.liveView.topView.timeView.liveAudience.text = [NSString stringWithFormat:@"%d",[[responseJson objectForKey:@"live"] toInt:@"watch_number"]];
  443. if ([[responseJson objectForKey:@"live"] toInt:@"allow_mention"] == 1 || [[responseJson objectForKey:@"live"] toInt:@"allow_live_pay"] == 1)
  444. {
  445. [self.liveUIViewController createPayLiveView:responseJson];
  446. }
  447. }
  448. }
  449. } FailureBlock:^(NSError *error) {
  450. }];
  451. }
  452. #pragma mark 主播进入房间状态回调
  453. - (void)getVideoState:(NSMutableDictionary *)parmMDict
  454. {
  455. [self.httpsManager POSTWithParameters:parmMDict SuccessBlock:^(NSDictionary *responseJson){
  456. } FailureBlock:^(NSError *error) {
  457. }];
  458. }
  459. -(void)protocolGetVideoWithRoomID:(NSString *)roomID{
  460. if (self.isHost) {
  461. return;
  462. }
  463. if (self.delegate && [self.delegate respondsToSelector:@selector(protocolGetVideoWithRoomID:)]) {
  464. [self.delegate protocolGetVideoWithRoomID:roomID];
  465. }
  466. }
  467. #pragma mark 进入直播室成功后的相关业务:获得视频信息
  468. - (void)getVideo:(FWLiveGetVideoCompletion)succ roomID:(NSString *)roomID failed:(FWErrorBlock)failed
  469. {
  470. if ([BGUtils isBlankString:roomID]) {
  471. roomID = [NSString stringWithFormat:@"%@",_roomIDStr];
  472. }
  473. _roomIDStr = roomID;
  474. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  475. [mDict setObject:@"video" forKey:@"ctl"];
  476. [mDict setObject:@"get_video2" forKey:@"act"];
  477. if(self.isVoice)
  478. {
  479. [mDict setObject:@"voice" forKey:@"ctl"];
  480. [mDict setObject:@"get_voice" forKey:@"act"];
  481. }
  482. else
  483. {
  484. [mDict setObject:@"video" forKey:@"ctl"];
  485. [mDict setObject:@"get_video2" forKey:@"act"];
  486. }
  487. NSString *MD5String = [NSString stringWithFormat:@"%@%@%@",TXYSdkAppId,[[IMAPlatform sharedInstance].host imUserId],_roomIDStr];
  488. if (![BGUtils isBlankString:MD5String])
  489. {
  490. [mDict setObject:[NSString stringWithFormat:@"%@",[BGMD5UTils getmd5WithString:MD5String]] forKey:@"sign"];
  491. }
  492. [mDict setObject:@"0" forKey:@"is_vod"]; // 0:观看直播;1:点播
  493. if (!_privateKeyString.length)
  494. {
  495. if ([UIPasteboard generalPasteboard].string.length)
  496. {
  497. if ([[[UIPasteboard generalPasteboard].string componentsSeparatedByString:[GTMBase64 decodeBase64:@"8J+UkQ=="]] count] > 1)
  498. {
  499. _privateKeyString = [[[UIPasteboard generalPasteboard].string componentsSeparatedByString:[GTMBase64 decodeBase64:@"8J+UkQ=="]] objectAtIndex:1];
  500. }
  501. }
  502. }
  503. if (_privateKeyString.length)
  504. {
  505. [mDict setObject:_privateKeyString forKey:@"private_key"];
  506. [UIPasteboard generalPasteboard].string = @"";
  507. }
  508. if (![BGUtils isBlankString:_roomIDStr])
  509. {
  510. [mDict setObject:_roomIDStr forKey:@"room_id"];
  511. FWWeakify(self)
  512. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  513. FWStrongify(self)
  514. // status: status=1表示抗议正常进入直播间,status=0表示不能正常进入直播间,status=2表示关闭直播间
  515. if ([responseJson toInt:@"status"] == 1)
  516. {
  517. self.currentLiveInfo = [CurrentLiveInfo mj_objectWithKeyValues:responseJson];
  518. [self getGuardianInfo];
  519. NSString *is_guartian = responseJson[@"is_guardian"];
  520. [GlobalVariables sharedInstance].is_guartian = [NSString stringWithFormat:@"%@",is_guartian];
  521. NSString *isShop = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"is_shop"]];
  522. // self.liveUIViewController.liveView.bottomView.shopBtn.hidden = ![isShop isEqualToString:@"1"];
  523. ;
  524. [GlobalVariables sharedInstance].isShop = [[GlobalVariables sharedInstance].userModel.shop_status isEqualToString:@"1"] ? YES : NO;
  525. // [isShop isEqualToString:@"1"];
  526. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  527. [dict setValue:@"guardians" forKey:@"ctl"];
  528. [dict setValue:@"get_guardians_privilege" forKey:@"act"];
  529. [dict setValue:self.currentLiveInfo.user_id forKey:@"host_id"];
  530. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  531. if ([responseJson toInt:@"status"] == 1) {
  532. BogoGuardianModel *model = [BogoGuardianModel modelWithDictionary:[responseJson valueForKey:@"list"]];
  533. [GlobalVariables sharedInstance].guardianModel = model;
  534. //10.09
  535. if (StrValid(self.currentLiveInfo.shop_goods.title)) {
  536. self.liveUIViewController.shopExplainView.model = self.currentLiveInfo.shop_goods;
  537. [self.liveUIViewController.shopExplainView show:self.liveUIViewController.view offsetY:kScreenH - MG_BOTTOM_MARGIN - kRealValue(184) - kRealValue(50 + 20)];
  538. [_liveUIViewController.liveView bringSubviewToFront:_liveUIViewController.liveView.giftView];
  539. }
  540. NSString *pkId = @"pkId";
  541. if (pkId.integerValue > 0) {
  542. }
  543. if (succ)
  544. {
  545. succ(self.currentLiveInfo);
  546. }
  547. }else{
  548. NSLog(ASLocalizedString(@"守护类型接口请求失败responseJson:%@"),responseJson);
  549. }
  550. } FailureBlock:^(NSError *error) {
  551. NSLog(ASLocalizedString(@"守护类型接口请求失败error:%@"),error);
  552. }];
  553. [self getVideoSuccess:responseJson];
  554. }
  555. else if ([responseJson toInt:@"status"] == 2)
  556. {
  557. NSString *audienceTotalStr = [responseJson toString:@"show_num"];
  558. if (_isHost)
  559. {
  560. [self showHostFinishView:audienceTotalStr andVote:@"" andHasDel:NO];
  561. }
  562. else
  563. {
  564. CustomMessageModel *cmm = [[CustomMessageModel alloc] init];
  565. cmm.showNum = [audienceTotalStr intValue];
  566. [self showAudienceFinishView:cmm];
  567. }
  568. if (failed)
  569. {
  570. failed(FWCode_Biz_Error, @"");
  571. }
  572. }
  573. else if ([responseJson toInt:@"status"] == 0)
  574. {
  575. if ([responseJson toInt:@"is_live_pay"] == 1)
  576. {
  577. if (succ)
  578. {
  579. [self.liveUIViewController beginEnterPayLive:responseJson closeBtn:self.closeBtn];
  580. self.currentLiveInfo = [CurrentLiveInfo mj_objectWithKeyValues:responseJson];
  581. succ(self.currentLiveInfo);
  582. }
  583. }
  584. else if([self.BuguLive.appModel.open_vip intValue] == 1)
  585. {
  586. if ([responseJson toInt:@"is_vip"] == 1)
  587. {
  588. if (succ)
  589. {
  590. [self.liveUIViewController beginEnterPayLive:responseJson closeBtn:self.closeBtn];
  591. self.currentLiveInfo = [CurrentLiveInfo mj_objectWithKeyValues:responseJson];
  592. succ(self.currentLiveInfo);
  593. }
  594. }
  595. else
  596. {
  597. if (failed)
  598. {
  599. failed(FWCode_Vip_Cancel, [responseJson toString:@"error"]);
  600. }
  601. }
  602. }
  603. else
  604. {
  605. if (failed)
  606. {
  607. failed(FWCode_Biz_Error, [responseJson toString:@"error"]);
  608. }
  609. }
  610. }
  611. //设置座驾
  612. [IMAPlatform sharedInstance].host.has_car = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"has_car"]];
  613. [IMAPlatform sharedInstance].host.car_name = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"car_name"]];
  614. [IMAPlatform sharedInstance].host.car_svga = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"noble_car_url"]];
  615. [IMAPlatform sharedInstance].host.is_vip = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"is_vip"]];
  616. } FailureBlock:^(NSError *error) {
  617. if (failed)
  618. {
  619. failed(FWCode_Net_Error, ASLocalizedString(@"网络加载失败"));
  620. }
  621. }];
  622. }
  623. }
  624. //获取守护权限
  625. -(void)getGuardianInfo{
  626. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  627. [dict setValue:@"guardians" forKey:@"ctl"];
  628. [dict setValue:@"get_guardians_privilege" forKey:@"act"];
  629. [dict setValue:self.currentLiveInfo.user_id forKey:@"host_id"];
  630. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  631. if ([responseJson toInt:@"status"] == 1) {
  632. BogoGuardianModel *model = [BogoGuardianModel modelWithDictionary:[responseJson valueForKey:@"list"]];
  633. [GlobalVariables sharedInstance].guardianModel = model;
  634. }else{
  635. NSLog(ASLocalizedString(@"守护类型接口请求失败responseJson:%@"),responseJson);
  636. }
  637. } FailureBlock:^(NSError *error) {
  638. NSLog(ASLocalizedString(@"守护类型接口请求失败error:%@"),error);
  639. }];
  640. }
  641. #pragma mark 请求get_video2接口成功处理
  642. - (void)getVideoSuccess:(NSDictionary *)responseJson
  643. {
  644. // 获取观众列表
  645. [self.liveUIViewController.liveView.topView refreshAudienceList:responseJson];
  646. //[_liveUIViewController showWishView];
  647. // 用来判断是否在直播间内
  648. LiveState *liveState = [[LiveState alloc] init];
  649. liveState.roomId = StringFromInt([_liveItem liveAVRoomId]);
  650. liveState.liveHostId = [[_liveItem liveHost] imUserId];
  651. if ([[[IMAPlatform sharedInstance].host imUserId] isEqualToString:[[_liveItem liveHost] imUserId]])
  652. {
  653. liveState.isLiveHost = YES;
  654. }
  655. else
  656. {
  657. liveState.isLiveHost = NO;
  658. }
  659. self.BuguLive.liveState = liveState;
  660. // 直播间整体刷新
  661. TCShowLiveListItem *liveRoom = (TCShowLiveListItem *)_liveItem;
  662. if (self.currentLiveInfo.podcast.user)
  663. {
  664. TCShowUser *showUser = [[TCShowUser alloc]init];
  665. showUser.uid = self.currentLiveInfo.podcast.user.user_id;
  666. showUser.username = self.currentLiveInfo.podcast.user.nick_name;
  667. showUser.avatar = self.currentLiveInfo.podcast.user.head_image;
  668. liveRoom.host = showUser;
  669. _liveItem = liveRoom;
  670. }
  671. if (self.delegate && [self.delegate respondsToSelector:@selector(refreshCurrentLiveItem:liveInfo:)])
  672. {
  673. [self.delegate refreshCurrentLiveItem:_liveItem liveInfo:self.currentLiveInfo];
  674. }
  675. // 该观众在当前直播间的排序权重
  676. [IMAPlatform sharedInstance].host.sort_num = [responseJson toString:@"sort_num"];
  677. if (!_isHost)
  678. {
  679. if ([responseJson toInt:@"open_daily_task"] == 1)//观众打开
  680. {
  681. self.liveUIViewController.liveView.closeLiveBtn.hidden = NO;
  682. }
  683. if (_currentLiveInfo.online_status == 1)
  684. {
  685. _anchorLeaveTipLabel.hidden = YES;
  686. }
  687. else if (([_liveItem liveType] == FW_LIVE_TYPE_HOST ||
  688. [_liveItem liveType] == FW_LIVE_TYPE_RECORD ||
  689. [_liveItem liveType] == FW_LIVE_TYPE_AUDIENCE) && _currentLiveInfo.online_status == 0)
  690. {
  691. _anchorLeaveTipLabel.hidden = NO;
  692. }
  693. }
  694. [self.liveUIViewController beginEnterPayLive:responseJson closeBtn:self.closeBtn];
  695. _voteNumber = [_currentLiveInfo.podcast.user.ticket integerValue];
  696. [self changePayView:self.liveUIViewController.liveView];
  697. if (!_isHost && _currentLiveInfo.podcast.has_focus == 0 && ![[[IMAPlatform sharedInstance].host imUserId] isEqualToString:[[_liveItem liveHost] imUserId]])
  698. {
  699. _isFollowAnchor = NO;
  700. }
  701. else
  702. {
  703. _isFollowAnchor = YES;
  704. }
  705. _privateShareString = [responseJson toString:@"private_share"];
  706. // 开启直播时如果有开启分享直播就在此处延时调用
  707. [self performSelector:@selector(hostShareLive) withObject:nil afterDelay:2];
  708. //判断是否是pk
  709. NSString *pk_id = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"pk_id"]];
  710. if([pk_id intValue]!=0)
  711. {
  712. [_liveUIViewController pkViewWith:pk_id];
  713. }
  714. }
  715. #pragma mark 主播退出直播间
  716. - (void)hostExitLive:(FWVoidBlock)succ failed:(FWErrorBlock)failed
  717. {
  718. if (![BGUtils isBlankString:_roomIDStr])
  719. {
  720. if(_liveUIViewController.pkView != nil)
  721. {
  722. [_liveUIViewController pkVivewHidden];
  723. }
  724. //直播结束
  725. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  726. [mDict setObject:@"video" forKey:@"ctl"];
  727. [mDict setObject:@"end_video" forKey:@"act"];
  728. [mDict setObject:_roomIDStr forKey:@"room_id"];
  729. FWWeakify(self)
  730. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  731. FWStrongify(self)
  732. if ([responseJson toInt:@"status"] == 1)
  733. {
  734. [self.liveUIViewController.liveView hideInputView];
  735. NSString *watch_number = [responseJson toString:@"watch_number"];
  736. if ([BGUtils isBlankString:watch_number])
  737. {
  738. watch_number = @"0";
  739. }
  740. NSString *vote_number = [responseJson toString:@"vote_number"];
  741. if ([BGUtils isBlankString:vote_number])
  742. {
  743. vote_number = @"0";
  744. }
  745. [self showHostFinishView:watch_number andVote:vote_number andHasDel:[responseJson toInt:@"has_delvideo"]];
  746. if(self.isVoice)
  747. {
  748. [self clickedFinishLiveViewBackHomeBtn];
  749. }
  750. else{
  751. [self showHostFinishView:watch_number andVote:vote_number andHasDel:[responseJson toInt:@"has_delvideo"]];
  752. }
  753. self.finishLiveView.liveTimeL.text = [BGUtils getMMSSFromSS:[responseJson valueForKey:@"time_len"]] ;
  754. if (succ)
  755. {
  756. succ();
  757. }
  758. }
  759. else
  760. {
  761. [self showHostFinishView:@"" andVote:@"" andHasDel:[responseJson toInt:@"has_delvideo"]];
  762. if (succ)
  763. {
  764. succ();
  765. }
  766. }
  767. } FailureBlock:^(NSError *error) {
  768. if (failed)
  769. {
  770. failed(FWCode_Net_Error, ASLocalizedString(@"网络加载失败"));
  771. }
  772. }];
  773. }
  774. else
  775. {
  776. if (failed)
  777. {
  778. failed(FWCode_Normal_Error, @"");
  779. }
  780. }
  781. }
  782. #pragma mark 业务上的"关闭"统一都调用这个,统一一个出口,防止出错
  783. - (void)closeCurrentLive:(BOOL)isDirectCloseLive isHostShowAlert:(BOOL)isHostShowAlert
  784. {
  785. if(_delegate && [_delegate respondsToSelector:@selector(clickCloseLive:isHostShowAlert:)])
  786. {
  787. [_delegate clickCloseLive:isDirectCloseLive isHostShowAlert:isHostShowAlert];
  788. }
  789. }
  790. -(void)clickCloseBtn:(TCShowLiveView *)showLiveView{
  791. [self onClickClose:nil];
  792. }
  793. #pragma mark 关闭操作
  794. - (void)onClickClose:(id)sender
  795. {
  796. BOOL isDirectCloseLive;
  797. BOOL showAlert;
  798. if (_isHost)
  799. {
  800. isDirectCloseLive = NO;
  801. showAlert = YES;
  802. }
  803. else
  804. {
  805. isDirectCloseLive = YES;
  806. showAlert = NO;
  807. }
  808. [_liveUIViewController ChatVCBgViewTap];
  809. DebugLog(@"=================:真正的点击了关闭按钮");
  810. showAlert = NO;
  811. [self closeCurrentLive:isDirectCloseLive isHostShowAlert:showAlert];
  812. }
  813. #pragma mark 有竞拍时点击关闭按钮
  814. - (void)closeRoom
  815. {
  816. BOOL isDirectCloseLive;
  817. if (_isHost)
  818. {
  819. isDirectCloseLive = NO;
  820. }
  821. else
  822. {
  823. isDirectCloseLive = YES;
  824. }
  825. DebugLog(@"=================:竞拍时真正的点击了关闭按钮");
  826. [self closeCurrentLive:isDirectCloseLive isHostShowAlert:YES];
  827. }
  828. #pragma mark 收到MSG_END_VIDEO 处理,该消息一般是观众会收到
  829. - (void)receiveEndMsg:(CustomMessageModel *)customMessageModel
  830. {
  831. if (!_isHost)
  832. {
  833. if (self.clickCloseBlock) {
  834. self.clickCloseBlock(YES);
  835. }
  836. DebugLog(@"=================:收到MSG_END_VIDEO 处理,该消息一般是观众会收到");
  837. if(self.isVoice)
  838. {
  839. if(self.delegate && [self.delegate respondsToSelector:@selector(closeVoiceRoom)])
  840. {
  841. [self.delegate closeVoiceRoom];
  842. }
  843. }
  844. else
  845. {
  846. [self closeCurrentLive:NO isHostShowAlert:NO];
  847. }
  848. [self showAudienceFinishView:customMessageModel];
  849. [self releaseAll];
  850. }
  851. }
  852. -(void)viewWillDisappear:(BOOL)animated
  853. {
  854. [[NSNotificationCenter defaultCenter] removeObserver:self];
  855. [super viewWillDisappear:animated];
  856. }
  857. #pragma mark 收到MSG_SYSTEM_CLOSE_LIVE 处理,该消息一般是主播会收到
  858. - (void)receiveSystemCloseMsg:(CustomMessageModel *)customMessageModel
  859. {
  860. BOOL isDirectCloseLive;
  861. if (_isHost)
  862. {
  863. isDirectCloseLive = NO;
  864. }
  865. else
  866. {
  867. isDirectCloseLive = YES;
  868. }
  869. DebugLog(@"=================:收到MSG_SYSTEM_CLOSE_LIVE 处理,该消息一般是主播会收到");
  870. BOOL showAlert = NO;
  871. if (customMessageModel.type == 17) {
  872. showAlert = YES;
  873. }
  874. [self closeCurrentLive:isDirectCloseLive isHostShowAlert:showAlert];
  875. }
  876. #pragma mark - ----------------------- IM消息处理 -----------------------
  877. #pragma mark 收到自定义C2C消息
  878. - (void)onIMHandler:(BGIMMsgHandler *)receiver recvCustomC2C:(id<AVIMMsgAble>)msg
  879. {
  880. if (![msg isKindOfClass:[CustomMessageModel class]])
  881. {
  882. return;
  883. }
  884. if (_delegate && [_delegate respondsToSelector:@selector(recvCustomC2C:)])
  885. {
  886. [_delegate recvCustomC2C:msg];
  887. }
  888. CustomMessageModel *customMessageModel = (CustomMessageModel *)msg;
  889. switch (customMessageModel.type) {
  890. case MSG_SYSTEM_CLOSE_LIVE: // 17 违规直播,立即关闭直播;私密直播被主播踢出直播间
  891. {
  892. [self receiveSystemCloseMsg:customMessageModel];
  893. }
  894. break;
  895. case MSG_BACKGROUND_MONITORING://41:后台会员监控
  896. {
  897. [FanweMessage alert:customMessageModel.desc];
  898. }
  899. break;
  900. case MSG_ACCEPT_PK:
  901. {
  902. //接收到pk
  903. NSString *pid = [NSString stringWithFormat:@"%@",[customMessageModel.dicData valueForKey:@"pk_id"]];
  904. [_liveUIViewController pkViewWith:pid ];
  905. }
  906. break;
  907. case MSG_END_PK:
  908. {
  909. // 关闭键盘
  910. [BGUtils closeKeyboard];
  911. }
  912. break;
  913. case MSG_CANCEL_PK: // 取消pk
  914. {
  915. // [MMAlertView hideAll];
  916. [_pkAcceptAlert hide];
  917. _pkAcceptAlert = nil;
  918. [self.liveUIViewController receiveCanclePk];
  919. }
  920. break;
  921. case MSG_REQEUST_PK:
  922. {
  923. // [MMAlertView hideAll];
  924. [self.liveUIViewController hiddenPKlist];
  925. [self PKAlertWith:customMessageModel];
  926. }
  927. break;
  928. case MSG_START_PK:
  929. {
  930. [self StartPK:customMessageModel];
  931. }
  932. break;
  933. case MSG_REJECT_PK:
  934. {
  935. [self.liveUIViewController hiddenPKlist];
  936. NSLog(ASLocalizedString(@"收到拒绝PK消息"));
  937. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  938. if(![GlobalVariables sharedInstance].openAgora)
  939. {
  940. [dict setObject:@"pk_tencent" forKey:@"ctl"];
  941. }
  942. else
  943. {
  944. [dict setObject:@"pk_agora" forKey:@"ctl"];
  945. }
  946. [dict setValue:@"request_Refused_pk" forKey:@"act"];
  947. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  948. if ([responseJson toInt:@"status"] == 1) {
  949. NSLog(ASLocalizedString(@"结束PK请求成功responseJson:%@"),responseJson);
  950. }else{
  951. NSLog(ASLocalizedString(@"结束PK请求失败responseJson:%@"),responseJson);
  952. }
  953. } FailureBlock:^(NSError *error) {
  954. NSLog(ASLocalizedString(@"结束PK请求失败error:%@"),error);
  955. }];
  956. [_liveUIViewController receiveRejectPkWithMsg:customMessageModel.msg];
  957. }
  958. break;
  959. default:
  960. break;
  961. }
  962. }
  963. - (void) StartPK:(CustomMessageModel *)msg{
  964. }
  965. -(void)PKAlertWith:(CustomMessageModel *)msg
  966. {
  967. [_pkAcceptAlert hide];
  968. _pkAcceptAlert = nil;
  969. _pkAcceptAlert = [FanweMessage alert:ASLocalizedString(@"pk消息")message:[NSString stringWithFormat:ASLocalizedString(@"%@请求与您pk"), msg.sender.nick_name] destructiveTitle:ASLocalizedString(@"同意")destructiveAction:^{
  970. UserModel *user = [[UserModel alloc] init];
  971. user.user_id = msg.sender.user_id;
  972. user.nick_name = msg.sender.nick_name;
  973. user.pk_id = msg.pkid;
  974. [self pkController:1 WidthData:user];
  975. } cancelTitle:ASLocalizedString(@"拒绝")cancelAction:^{
  976. UserModel *user = [[UserModel alloc] init];
  977. user.user_id = msg.sender.user_id;
  978. user.nick_name = msg.sender.nick_name;
  979. user.pk_id = msg.pkid;
  980. [self pkController:2 WidthData:user];
  981. }];
  982. // [_pkAcceptAlert show];
  983. }
  984. - (void)userlistRefresh
  985. {
  986. if([self.delegate respondsToSelector:@selector(refreshUserListVoice)])
  987. {
  988. [self.delegate refreshUserListVoice];
  989. }
  990. }
  991. #pragma mark 收到自定义的Group消息
  992. - (void)onIMHandler:(BGIMMsgHandler *)receiver recvCustomGroup:(id<AVIMMsgAble>)msg
  993. {
  994. NSLog(ASLocalizedString(@"消息类型type:%ld"),(long)[msg msgType]);
  995. if (![msg isKindOfClass:[CustomMessageModel class]])
  996. {
  997. return;
  998. }
  999. CustomMessageModel *customMessageModel = (CustomMessageModel *)msg;
  1000. if(customMessageModel.type == MSG_SHOP_SAY_TYPE)
  1001. {
  1002. customMessageModel.shopModel.isHost = _isHost;
  1003. [self.cartPopView hide];
  1004. self.cartPopView.lid = self.currentLiveInfo.room_id;
  1005. // if (!_isHost) {
  1006. // customMessageModel.shopModel.isHost = YES;
  1007. self.liveUIViewController.shopExplainView.model = customMessageModel.shopModel;
  1008. // if (!_isHost) {
  1009. // self.liveUIViewController.shopExplainView.buyBtn.hidden = YES;
  1010. // self.liveUIViewController.shopExplainView.priceLabel.textal
  1011. // }
  1012. // self.liveUIViewController.shopExplainView.hidden = NO;
  1013. [self.liveUIViewController.shopExplainView show:self.liveUIViewController.view offsetY:kScreenH - MG_BOTTOM_MARGIN - kRealValue(184) - kRealValue(80 + 20)];
  1014. // self.liveUIViewController.shopExplainView.
  1015. [_liveUIViewController.liveView bringSubviewToFront:_liveUIViewController.liveView.giftView];
  1016. return;
  1017. }
  1018. if(customMessageModel.type == MSG_SHOP_SAY_CANCLE_TYPE){//取消讲解
  1019. // self.liveUIViewController.shopExplainView.hidden = YES;
  1020. [self.liveUIViewController.shopExplainView hide];
  1021. self.cartPopView.lid = self.currentLiveInfo.room_id;
  1022. }
  1023. if(customMessageModel.type == MSG_END_PK)
  1024. {
  1025. //暂时不消失,等待惩罚时间2分钟结束以后再结束pk
  1026. //如果status == 启动倒计时
  1027. //否则是直接中断pk
  1028. if (customMessageModel.status == 1) {
  1029. //do nothing
  1030. }else if (customMessageModel.status == 3){
  1031. return;
  1032. if (!_isHost) {
  1033. //非主播接收消息
  1034. //pk结束
  1035. NSString *win_user_id = [NSString stringWithFormat:@"%@",customMessageModel.win_user_id];
  1036. NSString *time = [NSString stringWithFormat:@"%@",customMessageModel.time];
  1037. if([win_user_id isEqualToString:[IMAPlatform sharedInstance].host.userId])
  1038. {
  1039. // [FanweMessage alert:ASLocalizedString(@"恭贺您pk取得胜利")];
  1040. }
  1041. //2020-1-4 pk结束
  1042. //[self->_liveUIViewController pkVivewEnd:win_user_id anddic:[NSDictionary dictionary]];
  1043. dispatch_async(dispatch_get_main_queue(), ^{
  1044. [self->_liveUIViewController switchToPunish:time.intValue];
  1045. });
  1046. }
  1047. }else{
  1048. dispatch_async(dispatch_get_main_queue(), ^{
  1049. [self->_liveUIViewController pkVivewHidden];
  1050. });
  1051. }
  1052. }
  1053. if(customMessageModel.type == UPDATE_PK_TICKET)
  1054. {
  1055. [_liveUIViewController pkViewUpdateData:customMessageModel.dicData];
  1056. return;
  1057. }
  1058. //
  1059. if(customMessageModel.type == MSG_REFRESH_VOICE_MSG)
  1060. {
  1061. if([self.delegate respondsToSelector:@selector(refreshVoice:liveInfo:)])
  1062. {
  1063. [self.delegate refreshVoice:_liveItem liveInfo:customMessageModel];
  1064. }
  1065. return;
  1066. }
  1067. if(customMessageModel.type == MSG_START_PK)
  1068. {
  1069. if (_pkAcceptAlert) {
  1070. [_pkAcceptAlert hide];
  1071. }
  1072. NSString *pid = [NSString stringWithFormat:@"%@",[customMessageModel.dicData valueForKey:@"pk_id"]];
  1073. [_liveUIViewController pkViewWith:pid];
  1074. }
  1075. if (![customMessageModel.chatGroupID isEqualToString:[_liveItem liveIMChatRoomId]])
  1076. {
  1077. if (customMessageModel.type == MSG_REFRESH_AUDIENCE_LIST)
  1078. {
  1079. [[V2TIMManager sharedInstance] quitGroup:customMessageModel.chatGroupID succ:^{
  1080. } fail:^(int code, NSString *msg) {
  1081. }];
  1082. // [[TIMGroupManager sharedInstance] quitGroup:customMessageModel.chatGroupID succ:^{
  1083. // NSLog(ASLocalizedString(@"退出群:%@ 成功"),customMessageModel.chatGroupID);
  1084. // } fail:^(int code, NSString *msg) {
  1085. // NSLog(ASLocalizedString(@"退出群:%@ 失败,错误码:%d,错误原因:%@"),customMessageModel.chatGroupID,code,msg);
  1086. // }];
  1087. }
  1088. return;
  1089. }
  1090. if (customMessageModel.type == MSG_OPEN_GUARD_SUCCESS) {
  1091. //如果收到开通守护成功的消息,刷新数据
  1092. [_liveUIViewController.liveView.topView requestWardData];
  1093. [self receiveGlobalMsgModel:customMessageModel];
  1094. return;
  1095. }
  1096. if (customMessageModel.type == MSG_WIN_PRIZE) {
  1097. [self confirmPlayWinNotificationAnimation:customMessageModel];
  1098. if ([customMessageModel.sender.user_id isEqualToString:[IMAPlatform sharedInstance].host.userId]) {
  1099. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:ASLocalizedString(@"恭喜您中奖%@倍"),customMessageModel.user_multiple]];
  1100. }
  1101. return;
  1102. }
  1103. if (_delegate && [_delegate respondsToSelector:@selector(recvCustomGroup:)])
  1104. {
  1105. [_delegate recvCustomGroup:customMessageModel];
  1106. }
  1107. switch (customMessageModel.type)
  1108. {
  1109. case MSG_NONE: //-1:无操作
  1110. break;
  1111. case MSG_TEXT: //0:正常文字聊天消息
  1112. break;
  1113. case MSG_SEND_GIFT_SUCCESS: //1:收到发送礼物成功消息
  1114. {
  1115. if (customMessageModel.total_ticket>_voteNumber)
  1116. {
  1117. _voteNumber = customMessageModel.total_ticket; //印票总数
  1118. }
  1119. // if (customMessageModel.total_num>_voteNumber)
  1120. // {
  1121. // _voteNumber = customMessageModel.total_ticket; //印票总数
  1122. // }
  1123. [_liveUIViewController.liveView.topView refreshTicketCount:[NSString stringWithFormat:@"%ld",(long)_voteNumber]];
  1124. [_liveUIViewController.liveView.topView refreshHostNumCount:customMessageModel.total_num];
  1125. // refreshTicketCount:[NSString stringWithFormat:@"%ld",(long)_voteNumber]];
  1126. //0:普通动画 1:gif动画 2:真实动画
  1127. if (customMessageModel.is_animated == 0)
  1128. {
  1129. [self performSelector:@selector(addGiftMessage:) onThread:_addGiftRunLoopRef.thread withObject:customMessageModel waitUntilDone:NO];
  1130. }
  1131. else if (customMessageModel.is_animated == 1)
  1132. {
  1133. [_gifAnimateArray addObject:customMessageModel];
  1134. }
  1135. else if (customMessageModel.is_animated == 2)
  1136. {
  1137. [_gifAnimateArray addObject:customMessageModel];
  1138. }
  1139. //4-18 收到礼物需要更新心愿列表
  1140. [self.liveUIViewController.liveView.livewWishView requestModel:_roomIDStr];
  1141. }
  1142. break;
  1143. case MSG_POP_MSG://2:收到弹幕消息
  1144. {
  1145. if (customMessageModel.total_ticket>_voteNumber)
  1146. {
  1147. _voteNumber = customMessageModel.total_ticket; //印票总数
  1148. }
  1149. [_liveUIViewController.liveView.topView refreshTicketCount:[NSString stringWithFormat:@"%ld",(long)_voteNumber]];
  1150. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1151. [self addBarrageMessage:customMessageModel];
  1152. }
  1153. break;
  1154. case MSG_CREATER_EXIT_ROOM://3:主播退出直播间,暂未用到
  1155. {
  1156. }
  1157. break;
  1158. case MSG_FORBID_SEND_MSG://4:禁言消息
  1159. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1160. break;
  1161. case MSG_VIEWER_JOIN: //5:观众进入直播间消息
  1162. {
  1163. UserModel *userModel = [[UserModel alloc]init];
  1164. userModel.user_id = customMessageModel.sender.user_id;
  1165. userModel.nick_name = customMessageModel.sender.nick_name;
  1166. userModel.head_image = customMessageModel.sender.head_image;
  1167. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)customMessageModel.sender.user_level];
  1168. userModel.sort_num = customMessageModel.sender.sort_num;
  1169. userModel.noble_stealth = customMessageModel.sender.noble_stealth;
  1170. userModel.noble_icon = customMessageModel.sender.noble_icon;
  1171. userModel.noble_avatar = customMessageModel.sender.noble_avatar;
  1172. userModel.noble_is_avatar = customMessageModel.sender.noble_is_avatar;
  1173. userModel.noble_vip_type = customMessageModel.sender.noble_vip_type;
  1174. userModel.noble_car_name = customMessageModel.sender.noble_car_name;
  1175. userModel.car_svga = customMessageModel.sender.car_svga;
  1176. userModel.has_car = customMessageModel.sender.has_car;
  1177. userModel.isvip = customMessageModel.sender.is_vip;
  1178. userModel.is_vip = customMessageModel.sender.is_vip;
  1179. userModel.noble_car_url = customMessageModel.sender.noble_car_url;
  1180. userModel.is_guardian = customMessageModel.sender.is_guardian;
  1181. userModel.is_noble_mysterious = customMessageModel.sender.is_noble_mysterious;
  1182. userModel.guardianModel = customMessageModel.guardianModel;
  1183. userModel.guardian_icon = customMessageModel.sender.guardian_icon;
  1184. userModel.guardian_gift = customMessageModel.sender.guardian_gift;
  1185. userModel.guardian_skin = customMessageModel.sender.guardian_skin;
  1186. userModel.guardian_img = customMessageModel.sender.guardian_img;
  1187. userModel.guardian_broadcast = customMessageModel.sender.guardian_broadcast;
  1188. // userModel.is_guardian = customMessageModel.sender.is_guardian;
  1189. [_liveUIViewController.liveView.topView onImUsersEnterLive:userModel];
  1190. [self audienceEnterAnimate:userModel];
  1191. [self CarAnimate:userModel];
  1192. }
  1193. break;
  1194. case MSG_VIEWER_QUIT: //6:观众退出直播间消息
  1195. {
  1196. UserModel *userModel = [[UserModel alloc]init];
  1197. userModel.user_id = customMessageModel.sender.user_id;
  1198. userModel.nick_name = customMessageModel.sender.nick_name;
  1199. userModel.head_image = customMessageModel.sender.head_image;
  1200. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)customMessageModel.sender.user_level];
  1201. userModel.sort_num = customMessageModel.sender.sort_num;
  1202. [_liveUIViewController.liveView.topView onImUsersExitLive:userModel];
  1203. }
  1204. break;
  1205. case MSG_END_VIDEO: //7:直播结束消息
  1206. {
  1207. [self receiveEndMsg:customMessageModel];
  1208. }
  1209. break;
  1210. case MSG_RED_PACKET: //8:红包
  1211. {
  1212. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1213. customMessageModel.delegate = self;
  1214. [self addRedBagView:customMessageModel];
  1215. }
  1216. break;
  1217. case MSG_LIVING_MESSAGE: //9:直播消息
  1218. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1219. break;
  1220. case MSG_ANCHOR_LEAVE: //10:主播离开
  1221. {
  1222. _anchorLeaveTipLabel.hidden = NO;
  1223. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1224. }
  1225. break;
  1226. case MSG_ANCHOR_BACK: //11:主播回来
  1227. {
  1228. _anchorLeaveTipLabel.hidden = YES;
  1229. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1230. }
  1231. break;
  1232. case MSG_LIGHT: //12:点亮
  1233. {
  1234. if (customMessageModel.showMsg == 1)
  1235. {
  1236. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1237. }
  1238. [_liveUIViewController.liveView onRecvLight:customMessageModel.imageName];
  1239. }
  1240. break;
  1241. case MSG_PAY_SUCCESS : //29:支付成功
  1242. {
  1243. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1244. // [self.auctionTool paySuccessWithCustomModel:customMessageModel];
  1245. }
  1246. break;
  1247. case MSG_STARGOODS_SUCCESS: //31:主播发起商品推送成功
  1248. {
  1249. if ([_liveUIViewController.liveView.liveInputView isInputViewActive])
  1250. {
  1251. [_liveUIViewController.liveView.liveInputView resignFirstResponder];
  1252. }
  1253. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1254. }
  1255. break;
  1256. case MSG_PAYMONEY_SUCCESS: //32:主播发起付费直播成功(按时间)
  1257. {
  1258. if (!_isHost)
  1259. {
  1260. [BGUtils closeKeyboard];
  1261. [self.liveUIViewController getVedioViewWithType:1 closeBtn:_closeBtn];
  1262. }
  1263. }
  1264. break;
  1265. case MSG_GAME_OVER: //34,//游戏结束推送
  1266. {
  1267. [_liveUIViewController.liveView gameOverWithCustomMessageModel:customMessageModel];
  1268. _game_log_id = 0;
  1269. }
  1270. break;
  1271. case MSG_BUYGOODS_SUCCESS : //37.购买商品成功推送
  1272. {
  1273. [_liveUIViewController.liveView.msgView insertMsg:msg];
  1274. // [self.auctionTool buyGoodsSuccessWithCustomModel:customMessageModel];
  1275. }
  1276. break;
  1277. case MSG_GAME_ALL: //39.游戏总的推送
  1278. {
  1279. [_liveUIViewController.liveView gameAllMessageWithCustomMessageModel:customMessageModel];
  1280. }
  1281. break;
  1282. case MSG_PAYMONEYSEASON_SUCCESS : //40.主播发起付费直播成功(按场次)
  1283. {
  1284. if (!_isHost)
  1285. {
  1286. [BGUtils closeKeyboard];
  1287. [self.liveUIViewController getVedioViewWithType:40 closeBtn:_closeBtn];
  1288. }
  1289. }
  1290. break;
  1291. case MSG_REFRESH_AUDIENCE_LIST: // 42 刷新观众列表
  1292. {
  1293. [_liveUIViewController.liveView.topView refreshLiveAudienceList:customMessageModel];
  1294. }
  1295. break;
  1296. case MSG_GAME_BANKER: // 43 游戏上庄相关推送
  1297. {
  1298. [_liveUIViewController.liveView gameBankerMessageWithCustomMessageModel:customMessageModel];
  1299. }
  1300. break;
  1301. case MSG_BIG_GIFT_NOTICE_ALL: // 50 直播间飞屏模式(送大型礼物-全服飞屏通告)
  1302. {
  1303. if (!_isHost)
  1304. {
  1305. [_otherRoomBitGiftArray addObject:customMessageModel];
  1306. }
  1307. }
  1308. break;
  1309. case MSG_WISH_UPDATE: // 71 更新直播间心愿列表.
  1310. {
  1311. [self.liveUIViewController.liveView.livewWishView requestModel:_roomIDStr];
  1312. // showWishView];
  1313. }
  1314. break;
  1315. case MSG_RECEIVE_BROADCAST:
  1316. {
  1317. [self receiveGlobalMsgModel:customMessageModel];
  1318. }
  1319. break;
  1320. case MSG_OPEN_VIP_TYPE: // 91 贵族开通消息
  1321. {
  1322. [self receiveGlobalMsgModel:customMessageModel];
  1323. }
  1324. break;
  1325. default:
  1326. break;
  1327. }
  1328. }
  1329. -(void)receiveGlobalMsgModel:(CustomMessageModel *)customMessageModel{
  1330. if (!self.globalView) {
  1331. self.globalView = [[MGGlobalVipView alloc]initWithFrame:CGRectMake(kScreenW, kTopHeight + 120, kRealValue(230 + 40), 40)];
  1332. }
  1333. self.globalView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
  1334. dispatch_async(dispatch_get_main_queue(), ^{
  1335. // 判断是否有悬浮窗
  1336. UIView *tmpView = [AppDelegate sharedAppDelegate].sus_window.rootViewController ? [AppDelegate sharedAppDelegate].sus_window : [AppDelegate sharedAppDelegate].window;
  1337. UIView *inView = [AppDelegate sharedAppDelegate].sus_window.isSmallSusWindow ? [AppDelegate sharedAppDelegate].window : tmpView;
  1338. self.globalView.model = customMessageModel;
  1339. [inView addSubview:self.globalView];
  1340. [inView bringSubviewToFront:self.globalView];
  1341. FWWeakify(self)
  1342. [UIView animateWithDuration:10.0f animations:^{
  1343. FWStrongify(self)
  1344. self.globalView.left = -kScreenW;
  1345. } completion:^(BOOL finished) {
  1346. FWStrongify(self)
  1347. self.globalView.left = kScreenW;
  1348. }];
  1349. });
  1350. }
  1351. #pragma mark - ----------------------- 礼物处理 -----------------------
  1352. #pragma mark 开始循环小礼物队列
  1353. - (void)biginGiftLoop
  1354. {
  1355. _giftLoopTimer = [NSTimer scheduledTimerWithTimeInterval:kLiveMessageRefreshTime target:self selector:@selector(looperWork) userInfo:nil repeats:YES];
  1356. }
  1357. #pragma mark 添加一条新的礼物信息
  1358. - (void)addGiftMessage:(CustomMessageModel *)newMsg
  1359. {
  1360. @synchronized (_giftMessageMArray)
  1361. {
  1362. if (newMsg)
  1363. {
  1364. NSMutableDictionary *msgKey = [BGLiveServiceViewModel getGiftMsgKey:newMsg];
  1365. CustomMessageModel *oldMsg = [_giftMessageMDict objectForKey:msgKey];
  1366. int showNum = 1;
  1367. if (oldMsg && newMsg.is_plus == 1)
  1368. {
  1369. showNum = oldMsg.showNum + oldMsg.num;
  1370. if (oldMsg.isTaked)
  1371. {
  1372. [_giftMessageMArray removeObject:oldMsg];
  1373. }
  1374. }
  1375. newMsg.showNum = showNum;
  1376. [_giftMessageMArray addObject:newMsg];
  1377. [_giftMessageMDict setObject:newMsg forKey:msgKey];
  1378. }
  1379. }
  1380. }
  1381. #pragma mark 刷新IM消息
  1382. - (void)onUIRefreshIMMsg:(AVIMCache *)cache
  1383. {
  1384. [_liveUIViewController.liveView.msgView insertCachedMsg:cache];
  1385. }
  1386. #pragma mark 刷新点赞消息
  1387. - (void)onUIRefreshPraise:(AVIMCache *)cache
  1388. {
  1389. [_liveUIViewController.liveView onRecvPraise:cache];
  1390. }
  1391. - (void)refreshIMMsgTableView
  1392. {
  1393. NSDictionary *dic = [_iMMsgHandler getMsgCache];
  1394. AVIMCache *msgcache = dic[kRoomTableViewMsgKey];
  1395. [self onUIRefreshIMMsg:msgcache];
  1396. AVIMCache *praisecache = dic[@(MSG_LIGHT)];
  1397. [self onUIRefreshPraise:praisecache];
  1398. }
  1399. #pragma mark 循环礼物队列
  1400. - (void)looperWork
  1401. {
  1402. [_iMMsgHandler onHandleMyNewMessage:50];
  1403. __weak typeof(self) ws = self;
  1404. if (_refreshIMMsgCount % 2 == 0)
  1405. {
  1406. //在主线程播放送文字缩小动画
  1407. dispatch_async(dispatch_get_main_queue(), ^{
  1408. [ws refreshIMMsgTableView];
  1409. });
  1410. }
  1411. dispatch_async(dispatch_get_main_queue(), ^{
  1412. if (_currentBigGiftState == 0 && [_gifAnimateArray count])
  1413. {
  1414. _currentBigGiftState = 1;
  1415. [self playNextGiftAnimation];
  1416. }
  1417. if (_currentOtherRoomBigGiftState == 0 && [_otherRoomBitGiftArray count])
  1418. {
  1419. _currentOtherRoomBigGiftState = 1;
  1420. [self playNextOhterRoomBigGiftAnimation];
  1421. }
  1422. });
  1423. _refreshIMMsgCount ++;
  1424. @synchronized (_giftMessageMArray)
  1425. {
  1426. for (SendGiftAnimateView *view in _giftMessageViewMArray)
  1427. {
  1428. if (!view.isPlaying || (view.isPlaying && view.isPlayingDeplay))
  1429. {
  1430. for (CustomMessageModel* giftElem in _giftMessageMArray)
  1431. {
  1432. if (!giftElem.isTaked)
  1433. {
  1434. //如果本条msg还没有被播放过,遍历view列表,寻找是否已经有包含本条msg的view
  1435. SendGiftAnimateView *currentGiftMsgView;
  1436. for (SendGiftAnimateView *otherView in _giftMessageViewMArray)
  1437. {
  1438. if ([giftElem isEquals:otherView.customMessageModel])
  1439. {
  1440. currentGiftMsgView = otherView;
  1441. break;
  1442. }
  1443. }
  1444. _sendGiftAnimateView1.frame = CGRectMake(kDefaultMargin, [self obtainGiftAnimateViewY:SmallGiftAnimateIndex_1], SEND_GIFT_ANIMATE_VIEW_WIDTH, SEND_GIFT_ANIMATE_VIEW_HEIGHT);
  1445. _sendGiftAnimateView2.frame = CGRectMake(kDefaultMargin, [self obtainGiftAnimateViewY:SmallGiftAnimateIndex_2], SEND_GIFT_ANIMATE_VIEW_WIDTH, SEND_GIFT_ANIMATE_VIEW_HEIGHT);
  1446. if (currentGiftMsgView)
  1447. {
  1448. //如果找到包含本条msg的view
  1449. if (view != currentGiftMsgView)
  1450. {
  1451. //这个view不是自己,跳过此条信息
  1452. continue;
  1453. }
  1454. else
  1455. {
  1456. //如果这个view是自己
  1457. if (view.isPlaying && view.isPlayingDeplay)
  1458. {
  1459. //在主线程播放送文字缩小动画
  1460. dispatch_async(dispatch_get_main_queue(), ^{
  1461. if (view == _sendGiftAnimateView1)
  1462. {
  1463. [_sendGiftAnimateView1 setContent:giftElem];
  1464. BOOL canTxtFontChanging = [_sendGiftAnimateView1 txtFontAgain];
  1465. if (canTxtFontChanging) {
  1466. giftElem.isTaked = YES;
  1467. }
  1468. }
  1469. else
  1470. {
  1471. [_sendGiftAnimateView2 setContent:giftElem];
  1472. BOOL canTxtFontChanging = [_sendGiftAnimateView2 txtFontAgain];
  1473. if (canTxtFontChanging)
  1474. {
  1475. giftElem.isTaked = YES;
  1476. }
  1477. }
  1478. });
  1479. break;
  1480. }
  1481. else
  1482. {
  1483. //在主线程播放送礼物动画
  1484. dispatch_async(dispatch_get_main_queue(), ^{
  1485. if (view == _sendGiftAnimateView1)
  1486. {
  1487. [_sendGiftAnimateView1 setContent:giftElem];
  1488. BOOL canshowGiftAnimate = [_sendGiftAnimateView1 showGiftAnimate];
  1489. if (canshowGiftAnimate)
  1490. {
  1491. giftElem.isTaked = YES;
  1492. }
  1493. }
  1494. else
  1495. {
  1496. [_sendGiftAnimateView2 setContent:giftElem];
  1497. BOOL canshowGiftAnimate = [_sendGiftAnimateView2 showGiftAnimate];
  1498. if (canshowGiftAnimate)
  1499. {
  1500. giftElem.isTaked = YES;
  1501. }
  1502. }
  1503. });
  1504. break;
  1505. }
  1506. }
  1507. }
  1508. else
  1509. {
  1510. //如果没找到包含本条msg的view
  1511. if (!view.isPlaying)
  1512. {
  1513. giftElem.isTaked = YES;
  1514. //在主线程播放送礼物动画
  1515. dispatch_async(dispatch_get_main_queue(), ^{
  1516. if (view == _sendGiftAnimateView1)
  1517. {
  1518. [_sendGiftAnimateView1 setContent:giftElem];
  1519. [_sendGiftAnimateView1 showGiftAnimate];
  1520. }
  1521. else
  1522. {
  1523. [_sendGiftAnimateView2 setContent:giftElem];
  1524. [_sendGiftAnimateView2 showGiftAnimate];
  1525. }
  1526. });
  1527. break;
  1528. }
  1529. }
  1530. }
  1531. else
  1532. {
  1533. continue;
  1534. }
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. #pragma mark - ----------------------- 小礼物 -----------------------
  1541. #pragma mark 获取小礼物视图的Y值
  1542. - (CGFloat)obtainGiftAnimateViewY:(SmallGiftAnimateIndex)smallGiftAnimateindex
  1543. {
  1544. if (smallGiftAnimateindex == SmallGiftAnimateIndex_1)
  1545. {
  1546. if (_liveUIViewController.liveView.goldFlowerView && _liveUIViewController.liveView.goldViewCanNotSee == NO)
  1547. {
  1548. return SEND_GIFT_ANIMATE_VIEW_Y_1-_liveUIViewController.liveView.goldFlowerViewHeiht+20;
  1549. }
  1550. else if (_liveUIViewController.liveView.guessSizeView && _liveUIViewController.liveView.guessSizeViewCanNotSee == NO)
  1551. {
  1552. return SEND_GIFT_ANIMATE_VIEW_Y_1-kGuessSizeViewHeight+20;
  1553. }
  1554. else
  1555. {
  1556. return SEND_GIFT_ANIMATE_VIEW_Y_1;
  1557. }
  1558. }
  1559. else
  1560. {
  1561. if (_liveUIViewController.liveView.goldFlowerView && _liveUIViewController.liveView.goldViewCanNotSee == NO)
  1562. {
  1563. return SEND_GIFT_ANIMATE_VIEW_Y_2-_liveUIViewController.liveView.goldFlowerViewHeiht+20;
  1564. }
  1565. else if (_liveUIViewController.liveView.guessSizeView && _liveUIViewController.liveView.guessSizeViewCanNotSee == NO)
  1566. {
  1567. return SEND_GIFT_ANIMATE_VIEW_Y_2-kGuessSizeViewHeight+20;
  1568. }
  1569. else
  1570. {
  1571. return SEND_GIFT_ANIMATE_VIEW_Y_2;
  1572. }
  1573. }
  1574. }
  1575. #pragma mark 创建礼物视图及礼物动画视图
  1576. - (void)loadGiftView:(NSArray *)list
  1577. {
  1578. _sendGiftAnimateView1 = [[SendGiftAnimateView alloc]initWithFrame:CGRectMake(kDefaultMargin, [self obtainGiftAnimateViewY:SmallGiftAnimateIndex_1], SEND_GIFT_ANIMATE_VIEW_WIDTH, SEND_GIFT_ANIMATE_VIEW_HEIGHT)];
  1579. [_liveUIViewController.liveView addSubview:_sendGiftAnimateView1];
  1580. __weak typeof(self) ws = self;
  1581. [_sendGiftAnimateView1.headImgView setClickAction:^(id<MenuAbleItem> menu) {
  1582. CustomMessageModel *customMessageModel = ws.sendGiftAnimateView1.customMessageModel;
  1583. UserModel *userModel = [[UserModel alloc]init];
  1584. if(customMessageModel.type==1)
  1585. {
  1586. userModel.user_id = customMessageModel.sender.user_id;
  1587. userModel.nick_name = customMessageModel.sender.nick_name;
  1588. userModel.head_image = customMessageModel.sender.head_image;
  1589. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)customMessageModel.sender.user_level];
  1590. }
  1591. else if (customMessageModel.type==28)
  1592. {
  1593. userModel.user_id = customMessageModel.user.user_id;
  1594. userModel.nick_name = customMessageModel.user.nick_name;
  1595. userModel.head_image = customMessageModel.user.head_image;
  1596. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)customMessageModel.user.user_level];
  1597. }
  1598. [ws getUserInfo:userModel];
  1599. }];
  1600. _sendGiftAnimateView2 = [[SendGiftAnimateView2 alloc]initWithFrame:CGRectMake(kDefaultMargin, [self obtainGiftAnimateViewY:SmallGiftAnimateIndex_2], SEND_GIFT_ANIMATE_VIEW_WIDTH, SEND_GIFT_ANIMATE_VIEW_HEIGHT)];
  1601. [_liveUIViewController.liveView addSubview:_sendGiftAnimateView2];
  1602. [_sendGiftAnimateView2.headImgView setClickAction:^(id<MenuAbleItem> menu) {
  1603. CustomMessageModel *customMessageModel = ws.sendGiftAnimateView2.customMessageModel;
  1604. UserModel *userModel = [[UserModel alloc]init];
  1605. if(customMessageModel.type==1)
  1606. {
  1607. userModel.user_id = customMessageModel.sender.user_id;
  1608. userModel.nick_name = customMessageModel.sender.nick_name;
  1609. userModel.head_image = customMessageModel.sender.head_image;
  1610. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)customMessageModel.sender.user_level];
  1611. }
  1612. else if (customMessageModel.type==28)
  1613. {
  1614. userModel.user_id = customMessageModel.user.user_id;
  1615. userModel.nick_name = customMessageModel.user.nick_name;
  1616. userModel.head_image = customMessageModel.user.head_image;
  1617. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)customMessageModel.user.user_level];
  1618. }
  1619. [ws getUserInfo:userModel];
  1620. }];
  1621. [_giftMessageViewMArray addObject:_sendGiftAnimateView1];
  1622. [_giftMessageViewMArray addObject:_sendGiftAnimateView2];
  1623. }
  1624. -(void)closeRechargeWithRechargeView:(RechargeView *)rechargeView{
  1625. [UIView animateWithDuration:0.5 animations:^{
  1626. rechargeView.transform = CGAffineTransformIdentity;
  1627. } completion:^(BOOL finished) {
  1628. rechargeView.hidden = YES;
  1629. }];
  1630. // self.giftView.hidden = NO;
  1631. }
  1632. #pragma mark - ----------------------- 大型礼物动画、GIF动画 -----------------------
  1633. #pragma mark - svga动画
  1634. - (void)beginSVGAAnimate:(CustomMessageModel *)customMessageModel andSenderName:(NSString *)senderName
  1635. {
  1636. if (customMessageModel)
  1637. {
  1638. SVGAAnimate *svgaAnmate = [[SVGAAnimate alloc] initWithModel:customMessageModel inView:_liveUIViewController.liveView andSenderName:senderName];
  1639. svgaAnmate.delegate = self;
  1640. }
  1641. else
  1642. {
  1643. _currentBigGiftState = 0;
  1644. }
  1645. }
  1646. #pragma mark - svga关闭动画
  1647. -(void)SVGAViewFinish:(CustomMessageModel *)animateConfigModel andSenderName:(NSString *)senderName
  1648. {
  1649. if ([_gifAnimateArray count])
  1650. {
  1651. CustomMessageModel *customMessageModel = [_gifAnimateArray firstObject];
  1652. NSArray *firstArray = customMessageModel.anim_cfg;
  1653. NSInteger index = [firstArray count];
  1654. // for (int i=0; i<[firstArray count]; i++)
  1655. // {
  1656. // AnimateConfigModel *model = [firstArray objectAtIndex:i];
  1657. // if (model.Id == animateConfigModel.Id)
  1658. // {
  1659. // model.isFinishAnimate = YES;
  1660. // }
  1661. // if (model.isFinishAnimate)
  1662. // {
  1663. // index--;
  1664. // }
  1665. // }
  1666. // if (index == 0)
  1667. // {
  1668. [_gifAnimateArray removeObjectAtIndex:0];
  1669. _currentBigGiftState = 0;
  1670. // }
  1671. }
  1672. }
  1673. #pragma mark 开始gif动画
  1674. - (void)beginGifAnimate:(CustomMessageModel *)customMessageModel andSenderName:(NSString *)senderName
  1675. {
  1676. if (customMessageModel.anim_cfg)
  1677. {
  1678. if ([customMessageModel.anim_cfg count])
  1679. {
  1680. NSArray *gifArray = customMessageModel.anim_cfg;
  1681. for (AnimateConfigModel *animateConfigModel in gifArray)
  1682. {
  1683. GifImageView *gifImageView = [[GifImageView alloc]initWithModel:animateConfigModel inView:_liveUIViewController.liveView andSenderName:senderName];
  1684. gifImageView.delegate = self;
  1685. }
  1686. }
  1687. else
  1688. {
  1689. [_gifAnimateArray removeObjectAtIndex:0];
  1690. _currentBigGiftState = 0;
  1691. }
  1692. }
  1693. else
  1694. {
  1695. _currentBigGiftState = 0;
  1696. }
  1697. }
  1698. #pragma mark GifImageView代理(GifImageViewDelegate)
  1699. - (void)gifImageViewFinish:(AnimateConfigModel *)animateConfigModel andSenderName:(NSString *)senderName
  1700. {
  1701. if ([_gifAnimateArray count])
  1702. {
  1703. CustomMessageModel *customMessageModel = [_gifAnimateArray firstObject];
  1704. NSArray *firstArray = customMessageModel.anim_cfg;
  1705. NSInteger index = [firstArray count];
  1706. for (int i=0; i<[firstArray count]; i++)
  1707. {
  1708. AnimateConfigModel *model = [firstArray objectAtIndex:i];
  1709. if (model.Id == animateConfigModel.Id)
  1710. {
  1711. model.isFinishAnimate = YES;
  1712. }
  1713. if (model.isFinishAnimate)
  1714. {
  1715. index--;
  1716. }
  1717. }
  1718. if (index == 0)
  1719. {
  1720. [_gifAnimateArray removeObjectAtIndex:0];
  1721. _currentBigGiftState = 0;
  1722. }
  1723. }
  1724. }
  1725. #pragma mark Plane1Controller代理(Plane1ControllerDelegate)
  1726. - (void)plane1AnimationFinished
  1727. {
  1728. [self removePlayAnimate:kPlane1Tag];
  1729. }
  1730. #pragma mark Plane2Controller代理(Plane2ControllerDelegate)
  1731. - (void)plane2AnimationFinished
  1732. {
  1733. [self removePlayAnimate:kPlane2Tag];
  1734. }
  1735. #pragma mark FerrariController代理(FerrariControllerDelegate)
  1736. - (void)ferrariAnimationFinished
  1737. {
  1738. [self removePlayAnimate:kFerrariTag];
  1739. }
  1740. #pragma mark LambohiniViewController代理(LambohiniViewControllerDelegate)
  1741. - (void)lambohiniAnimationFinished
  1742. {
  1743. [self removePlayAnimate:kLambohiniTag];
  1744. }
  1745. #pragma mark RocketViewController代理(RocketViewControllerDelegate)
  1746. - (void)rocketAnimationFinished
  1747. {
  1748. [self removePlayAnimate:kRocket1Tag];
  1749. }
  1750. #pragma mark 移除当前播放动画视图,如果有下一条视图则对应继续播放
  1751. - (void)removePlayAnimate:(NSInteger)viewTag
  1752. {
  1753. [_gifAnimateArray removeObjectAtIndex:0];
  1754. _currentBigGiftState = 0;
  1755. }
  1756. #pragma mark 播放礼物下一个gif、真实动画
  1757. - (void)playNextGiftAnimation
  1758. {
  1759. CustomMessageModel *customMessageModel = [_gifAnimateArray firstObject];
  1760. //1:gif动画 2:真实动画
  1761. if (customMessageModel.is_animated == 1)
  1762. {
  1763. [self beginGifAnimate:[_gifAnimateArray firstObject] andSenderName:customMessageModel.top_title];
  1764. }
  1765. else if (customMessageModel.is_animated == 2)
  1766. {
  1767. if ([BGUtils isBlankString:customMessageModel.animated_url]) {
  1768. // [self playAnimationWithTagStr:customMessageModel superView:_liveUIViewController.liveView];
  1769. }else{
  1770. [self beginSVGAAnimate:customMessageModel andSenderName:customMessageModel.sender.nick_name];
  1771. }
  1772. }
  1773. }
  1774. #pragma mark 播放对应标签的动画
  1775. - (void)playAnimationWithTagStr:(CustomMessageModel *)customMessageModel superView:(UIView *)superView
  1776. {
  1777. if ([customMessageModel.anim_type isEqualToString:kPlane1TypeStr])
  1778. {
  1779. Plane1Controller *tmpController = [[Plane1Controller alloc]init];
  1780. tmpController.senderNameStr = customMessageModel.top_title;
  1781. tmpController.delegate = self;
  1782. [superView addSubview:tmpController.view];
  1783. tmpController.view.tag = kPlane1Tag;
  1784. tmpController.view.frame = self.view.bounds;
  1785. [superView sendSubviewToBack:tmpController.view];
  1786. }
  1787. else if ([customMessageModel.anim_type isEqualToString:kPlane2TypeStr])
  1788. {
  1789. Plane2Controller *tmpController = [[Plane2Controller alloc]init];
  1790. tmpController.senderNameStr = customMessageModel.top_title;
  1791. tmpController.delegate = self;
  1792. [superView addSubview:tmpController.view];
  1793. tmpController.view.tag = kPlane2Tag;
  1794. tmpController.view.frame = self.view.bounds;
  1795. [superView sendSubviewToBack:tmpController.view];
  1796. }
  1797. else if ([customMessageModel.anim_type isEqualToString:kFerrariTypeStr])
  1798. {
  1799. FerrariController *tmpController = [[FerrariController alloc]init];
  1800. tmpController.senderNameStr1 = customMessageModel.top_title;
  1801. tmpController.senderNameStr2 = customMessageModel.top_title;
  1802. tmpController.delegate = self;
  1803. [superView addSubview:tmpController.view];
  1804. tmpController.view.tag = kFerrariTag;
  1805. tmpController.view.frame = self.view.bounds;
  1806. [superView sendSubviewToBack:tmpController.view];
  1807. }
  1808. else if ([customMessageModel.anim_type isEqualToString:kLambohiniTypeStr])
  1809. {
  1810. LambohiniViewController *tmpController = [[LambohiniViewController alloc]init];
  1811. tmpController.senderNameStr = customMessageModel.top_title;
  1812. tmpController.delegate = self;
  1813. [superView addSubview:tmpController.view];
  1814. tmpController.view.tag = kLambohiniTag;
  1815. tmpController.view.frame = self.view.bounds;
  1816. [superView sendSubviewToBack:tmpController.view];
  1817. }
  1818. else if ([customMessageModel.anim_type isEqualToString:kRocket1TypeStr])
  1819. {
  1820. RocketViewController *tmpController = [[RocketViewController alloc]init];
  1821. tmpController.senderNameStr = customMessageModel.top_title;
  1822. tmpController.delegate = self;
  1823. [superView addSubview:tmpController.view];
  1824. tmpController.view.tag = kRocket1Tag;
  1825. tmpController.view.frame = self.view.bounds;
  1826. [superView sendSubviewToBack:tmpController.view];
  1827. }
  1828. }
  1829. #pragma mark - ----------------------- 飞屏模式 -----------------------
  1830. #pragma mark 播放下一个其他房间的大型礼物(飞屏模式)
  1831. - (void)playNextOhterRoomBigGiftAnimation
  1832. {
  1833. _ohterRoomBitGiftModel = [_otherRoomBitGiftArray firstObject];
  1834. [self.otherRoomBitGiftArray removeObjectAtIndex:0];
  1835. if (![BGUtils isBlankString:_ohterRoomBitGiftModel.desc])
  1836. {
  1837. FWWeakify(self)
  1838. [self.otherRoomBitGiftView judgeGiftViewWith:_ohterRoomBitGiftModel.desc finishBlock:^{
  1839. FWStrongify(self)
  1840. self.otherRoomBitGiftView.hidden = NO;
  1841. self.currentOtherRoomBigGiftState = 0;
  1842. }];
  1843. _otherRoomBitGiftView.hidden = NO;
  1844. }
  1845. }
  1846. - (OtherRoomBitGiftView *)otherRoomBitGiftView
  1847. {
  1848. if (!_otherRoomBitGiftView)
  1849. {
  1850. _otherRoomBitGiftView = [[OtherRoomBitGiftView alloc] initWithFrame:CGRectMake(0, 100, kScreenW, 55)];
  1851. [_liveUIViewController.liveView addSubview:_otherRoomBitGiftView];
  1852. _otherRoomBitGiftView.userInteractionEnabled = YES;
  1853. UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goOtherLiveRoom)];
  1854. tapRecognizer.numberOfTapsRequired = 1;
  1855. tapRecognizer.numberOfTouchesRequired = 1;
  1856. [_otherRoomBitGiftView addGestureRecognizer:tapRecognizer];
  1857. }
  1858. return _otherRoomBitGiftView;
  1859. }
  1860. - (void)goOtherLiveRoom
  1861. {
  1862. if (!_isHost)
  1863. {
  1864. [FanweMessage alert:nil message:ASLocalizedString(@"您确定需要前往该直播间吗?")destructiveAction:^{
  1865. SUS_WINDOW.switchedRoomId = _ohterRoomBitGiftModel.room_id;
  1866. [self closeCurrentLive:YES isHostShowAlert:NO];
  1867. [self releaseAll];
  1868. } cancelAction:^{
  1869. }];
  1870. /**
  1871. _roomIDStr = _ohterRoomBitGiftModel.room_id;
  1872. if (_delegate && [_delegate respondsToSelector:@selector(switchLiveRoom)])
  1873. {
  1874. [_delegate switchLiveRoom];
  1875. }
  1876. */
  1877. }
  1878. }
  1879. #pragma mark - ----------------------- 弹幕消息 -----------------------
  1880. - (void)addBarrageMessage:(CustomMessageModel *)customMessageModel
  1881. {
  1882. if(customMessageModel.desc.length == 0)
  1883. {
  1884. return;
  1885. }
  1886. MessageView* messageView = [[MessageView alloc] initWithView:_liveUIViewController.liveView customMessageModel:customMessageModel];
  1887. messageView.delegate = self;
  1888. if ([_barrageViewArray count])
  1889. { //弹幕消息视图队列中有正在等待展示的弹幕信息
  1890. [_barrageViewArray addObject:messageView];
  1891. }
  1892. else
  1893. {
  1894. if (_barrageViewShowing1 && !_barrageViewShowing2)
  1895. { //正在展示底下的弹幕,上面的弹幕空闲状态
  1896. messageView.frame = CGRectMake(messageView.frame.origin.x, [self showBarrageViewWithOriginY:BARRAGE_VIEW_Y_2], messageView.frame.size.width, messageView.frame.size.height);
  1897. [self barrageViewAnimating2:messageView];
  1898. }
  1899. else if ((!_barrageViewShowing1 && _barrageViewShowing2) || (!_barrageViewShowing1 && !_barrageViewShowing2))
  1900. { //正在展示上面的弹幕,底下的弹幕空闲状态 或者 两个弹幕都不在展示状态
  1901. messageView.frame = CGRectMake(messageView.frame.origin.x, [self showBarrageViewWithOriginY:BARRAGE_VIEW_Y_1], messageView.frame.size.width, messageView.frame.size.height);
  1902. [self barrageViewAnimating1:messageView];
  1903. }
  1904. else if (_barrageViewShowing1 && _barrageViewShowing2)
  1905. { //两个弹幕都正在展示状态
  1906. [_barrageViewArray addObject:messageView];
  1907. }
  1908. }
  1909. }
  1910. - (CGFloat)showBarrageViewWithOriginY:(CGFloat)originY
  1911. {
  1912. if (_liveUIViewController.liveView.goldFlowerView && _liveUIViewController.liveView.goldViewCanNotSee == NO)
  1913. {
  1914. return originY-_liveUIViewController.liveView.goldFlowerViewHeiht;
  1915. }
  1916. else if (_liveUIViewController.liveView.guessSizeView && _liveUIViewController.liveView.guessSizeViewCanNotSee == NO)
  1917. {
  1918. return originY-kGuessSizeViewHeight;
  1919. }
  1920. else
  1921. {
  1922. return originY;
  1923. }
  1924. }
  1925. #pragma mark 获取弹幕视图队列中的弹幕视图
  1926. - (void)getBarrageViewFromArray:(int)tag
  1927. {
  1928. MessageView* messageView;
  1929. if ([_barrageViewArray count])
  1930. { //获取弹幕消息视图队列中的第一个弹幕信息
  1931. messageView = [_barrageViewArray firstObject];
  1932. [_barrageViewArray removeObjectAtIndex:0];
  1933. if (tag == 1)
  1934. {
  1935. messageView.frame = CGRectMake(messageView.frame.origin.x, [self showBarrageViewWithOriginY:BARRAGE_VIEW_Y_1], messageView.frame.size.width, messageView.frame.size.height);
  1936. [self barrageViewAnimating1:messageView];
  1937. }
  1938. else
  1939. {
  1940. messageView.frame = CGRectMake(messageView.frame.origin.x, [self showBarrageViewWithOriginY:BARRAGE_VIEW_Y_2], messageView.frame.size.width, messageView.frame.size.height);
  1941. [self barrageViewAnimating2:messageView];
  1942. }
  1943. }
  1944. }
  1945. - (void)barrageViewAnimating1:(MessageView *)messageView
  1946. {
  1947. double needTime = 0;
  1948. if (messageView.frame.size.width<kScreenW)
  1949. {
  1950. needTime = BARRAGE_VIEW_ANIMATE_TIME;
  1951. }
  1952. else
  1953. {
  1954. needTime = BARRAGE_VIEW_ANIMATE_TIME+(messageView.frame.size.width-kScreenW)/kScreenW*BARRAGE_VIEW_ANIMATE_TIME;
  1955. }
  1956. _barrageViewShowing1 = YES;
  1957. __weak MessageView *mv = messageView;
  1958. FWWeakify(self)
  1959. [UIView animateWithDuration:needTime animations:^{
  1960. FWStrongify(self)
  1961. mv.frame = CGRectMake(-mv.frame.size.width, [self showBarrageViewWithOriginY:BARRAGE_VIEW_Y_1], mv.frame.size.width, mv.frame.size.height);
  1962. } completion:^(BOOL finished) {
  1963. FWStrongify(self)
  1964. self.barrageViewShowing1 = NO;
  1965. [mv removeFromSuperview];
  1966. if ([self.barrageViewArray count])
  1967. {
  1968. [self getBarrageViewFromArray:1];
  1969. }
  1970. }];
  1971. }
  1972. - (void)barrageViewAnimating2:(MessageView *)messageView
  1973. {
  1974. double needTime = 0;
  1975. if (messageView.frame.size.width<kScreenW)
  1976. {
  1977. needTime = BARRAGE_VIEW_ANIMATE_TIME;
  1978. }
  1979. else
  1980. {
  1981. needTime = BARRAGE_VIEW_ANIMATE_TIME+(messageView.frame.size.width-kScreenW)/kScreenW*BARRAGE_VIEW_ANIMATE_TIME;
  1982. }
  1983. _barrageViewShowing2 = YES;
  1984. __weak MessageView *mv = messageView;
  1985. FWWeakify(self)
  1986. [UIView animateWithDuration:needTime animations:^{
  1987. FWStrongify(self)
  1988. mv.frame = CGRectMake(-mv.frame.size.width, [self showBarrageViewWithOriginY:BARRAGE_VIEW_Y_2], mv.frame.size.width, mv.frame.size.height);
  1989. } completion:^(BOOL finished) {
  1990. FWStrongify(self)
  1991. self.barrageViewShowing2 = NO;
  1992. [mv removeFromSuperview];
  1993. if ([self.barrageViewArray count])
  1994. {
  1995. [self getBarrageViewFromArray:2];
  1996. }
  1997. }];
  1998. }
  1999. #pragma mark 点击弹幕头像
  2000. - (void)tapLogo:(MessageView *)messageView customMessageModel:(CustomMessageModel *)customMessageModel
  2001. {
  2002. }
  2003. //#pragma mark 关闭每日任务
  2004. //- (void)closeEverydayTask
  2005. //{
  2006. // self.liveUIViewController.liveView.closeLiveBtn.hidden = YES;
  2007. //}
  2008. #pragma mark - ----------------------- 高级别用户进入动画 -----------------------
  2009. #pragma mark 查看客户是否高级用户,如果是的显示对应的高级用户进入动画
  2010. - (void)showCurrUserJoinAnimate
  2011. {
  2012. if (!_isHost)
  2013. {
  2014. UserModel *userModel = [[UserModel alloc]init];
  2015. userModel.user_id = [IMAPlatform sharedInstance].host.imUserId;
  2016. userModel.nick_name = [IMAPlatform sharedInstance].host.imUserName;
  2017. userModel.head_image = [IMAPlatform sharedInstance].host.imUserIconUrl;
  2018. userModel.user_level = [NSString stringWithFormat:@"%ld",[[IMAPlatform sharedInstance].host getUserRank]];
  2019. [self audienceEnterAnimate:userModel];
  2020. }
  2021. }
  2022. #pragma mark 判断是否播放高级别用户进入动画
  2023. - (void)audienceEnterAnimate:(UserModel *)userModel
  2024. {
  2025. if (userModel.is_guardian == 1) {
  2026. //是守护,展示守护样式
  2027. [_aETViewArray addObject:userModel];
  2028. if ([_aETViewArray count] == 1 && !_aETViewShowing)
  2029. {
  2030. _aETView.type = AudienceEnteringTipViewTypeGuard;
  2031. [self playAETViewAnimate:userModel];
  2032. }
  2033. }else if ([userModel.user_level integerValue] >= self.BuguLive.appModel.jr_user_level){
  2034. //高级别观众进入,展示高级别动画
  2035. [_aETViewArray addObject:userModel];
  2036. if ([_aETViewArray count] == 1 && !_aETViewShowing)
  2037. {
  2038. _aETView.type = AudienceEnteringTipViewTypeHighLevel;
  2039. [self playAETViewAnimate:userModel];
  2040. }
  2041. }else{
  2042. //不是守护也不是高级别
  2043. }
  2044. }
  2045. #pragma mark 播放高级别观众进入的动画
  2046. - (void)playAETViewAnimate:(UserModel *) userModel
  2047. {
  2048. _aETView = [[AudienceEnteringTipView alloc]initWithMyFrame:CGRectMake(-kScreenW, _liveUIViewController.liveView.msgView.top - 35, kRealValue(250), kRealValue(30))];
  2049. [_liveUIViewController.liveView addSubview:_aETView];
  2050. [_liveUIViewController.liveView bringSubviewToFront:_liveUIViewController.liveView.giftView];
  2051. _aETViewShowing = YES;
  2052. [_aETView setContent:userModel];
  2053. FWWeakify(self)
  2054. [UIView animateWithDuration:1.2 animations:^{
  2055. FWStrongify(self)
  2056. self.aETView.hidden = NO;
  2057. self.aETView.frame = CGRectMake(0, _liveUIViewController.liveView.msgView.top - 35, kScreenW, 35);
  2058. } completion:^(BOOL finished) {
  2059. FWStrongify(self)
  2060. [self performSelector:@selector(finishAETViewAnimate) withObject:nil afterDelay:2];
  2061. }];
  2062. }
  2063. #pragma mark 结束高级用户进入动画
  2064. - (void)finishAETViewAnimate
  2065. {
  2066. _aETView.hidden = YES;
  2067. _aETViewShowing = NO;
  2068. [_aETViewArray removeObjectAtIndex:0];
  2069. _aETView.frame = CGRectMake(-kScreenW, _aETView.frame.origin.y, CGRectGetWidth(_aETView.frame), CGRectGetHeight(_aETView.frame));
  2070. [_aETView removeAllSubViews];
  2071. _aETView = nil;
  2072. if ([_aETViewArray count])
  2073. {
  2074. UserModel *userModel = [_aETViewArray firstObject];
  2075. [self playAETViewAnimate:userModel];
  2076. }
  2077. }
  2078. #pragma mark - ======= 中奖全站播放通知动画 ======
  2079. - (void)confirmPlayWinNotificationAnimation:(CustomMessageModel *)model{
  2080. [_winTipViewArray addObject:model];
  2081. if ([_winTipViewArray count] == 1 && !_winTipViewShowing)
  2082. {
  2083. [self playWinNotificationAnimation:model];
  2084. }
  2085. }
  2086. - (void)playWinNotificationAnimation:(CustomMessageModel *)model{
  2087. _winTipViewShowing = YES;
  2088. [_winTipView setModel:model];
  2089. self.winTipView.hidden = NO;
  2090. [UIView animateWithDuration:8 animations:^{
  2091. self.winTipView.frame = CGRectMake(-kScreenW, kOpenTipViewHeight, kScreenW - 20, 44);
  2092. } completion:^(BOOL finished) {
  2093. [self performSelector:@selector(finishWinNotificationAnimation) withObject:nil afterDelay:0];
  2094. }];
  2095. }
  2096. - (void)finishWinNotificationAnimation{
  2097. _winTipViewShowing = NO;
  2098. [_winTipViewArray removeObjectAtIndex:0];
  2099. self.winTipView.hidden = YES;
  2100. self.winTipView.frame = CGRectMake(kScreenW, kOpenTipViewHeight, kScreenW - 20, 44);
  2101. if ([_winTipViewArray count])
  2102. {
  2103. CustomMessageModel *model = [_winTipViewArray firstObject];
  2104. [self playWinNotificationAnimation:model];
  2105. }
  2106. }
  2107. #pragma mark - ----------------------- 红包 -----------------------
  2108. #pragma mark 展示红包
  2109. - (void)addRedBagView:(CustomMessageModel *) customMessageModel
  2110. {
  2111. BGRedPackModel *user = [BGRedPackModel new];
  2112. user.head_image = customMessageModel.dicData[@"head_image"];
  2113. user.nick_name = customMessageModel.dicData[@"nick_name"];
  2114. user.id = customMessageModel.dicData[@"surprise_id"];
  2115. BGOpenRedPackView *readView = [[BGOpenRedPackView alloc] init];
  2116. // readView.video_id = self.video_id;
  2117. readView.userModel = user;
  2118. readView.frame = CGRectMake(40, 0, kScreenW-40*2, kScreenH-140*2);
  2119. readView.userModel = user;
  2120. // readView.backgroundColor = kRedColor;
  2121. [readView show:[TCUtil currentViewController].view type:FDPopTypeCenter];
  2122. return;
  2123. [customMessageModel startRedPackageTimer];
  2124. SLiveRedBagView *redBagView = [[[NSBundle mainBundle]loadNibNamed:@"SLiveRedBagView" owner:self options:nil] objectAtIndex:0];
  2125. redBagView.frame = CGRectMake(0,0,kScreenW,kScreenH);
  2126. redBagView.rebBagDelegate = self;
  2127. redBagView.video_id = self.currentLiveInfo.room_id;
  2128. [redBagView creatRedWithModel:customMessageModel];
  2129. [_liveUIViewController.liveView addSubview:redBagView];
  2130. }
  2131. #pragma mark RedBagViewDelegate
  2132. #pragma mark 点击打开红包
  2133. - (void)openRedbag:(SLiveRedBagView *)redBagView
  2134. {
  2135. [redBagView.customMessageModel stopRedPackageTimer];
  2136. _liveUIViewController.liveView.currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  2137. [_liveUIViewController.liveView.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",[[IMAPlatform sharedInstance].host getDiamonds]]];
  2138. }
  2139. #pragma mark CustomMessageModelDelegate
  2140. #pragma mark 红包消失
  2141. - (void)redPackageDisappear:(CustomMessageModel *)customMessageModel
  2142. {
  2143. for (UIView *subView in _liveUIViewController.liveView.subviews)
  2144. {
  2145. if ([subView isKindOfClass:[SLiveRedBagView class]])
  2146. {
  2147. SLiveRedBagView *redBagView = (SLiveRedBagView *)subView;
  2148. if ([redBagView.customMessageModel isEqual:customMessageModel])
  2149. {
  2150. [redBagView removeFromSuperview];
  2151. }
  2152. }
  2153. }
  2154. }
  2155. #pragma mark - ----------------------- 结束界面 -----------------------
  2156. #pragma mark 结束界面
  2157. - (void)setupFinishView:(CurrentLiveInfo *)liveInfo
  2158. {
  2159. if (!_finishLiveView)
  2160. {
  2161. _finishLiveView = [[BGFinishLiveView alloc] init];
  2162. }
  2163. [BGUtils downloadImage:liveInfo.podcast.user.head_image place:kDefaultPreloadHeadImg imageView:_finishLiveView.userHeadImgView];
  2164. // [BGUtils downloadImage:liveInfo.podcast.user.head_image place:kDefaultPreloadHeadImg imageView:_finishLiveView.bgImgView];
  2165. _finishLiveView.userNameLabel.text = liveInfo.podcast.user.nick_name;
  2166. if (_isHost)
  2167. {
  2168. _finishLiveView.shareFollowBtn.hidden = YES;
  2169. _finishLiveView.screenshotShareBtn.hidden = YES;
  2170. _finishLiveView.audienTicketContrainerView.hidden = YES;
  2171. _finishLiveView.hostCostView.hidden = YES;
  2172. _finishLiveView.hostTicketView.hidden = YES;
  2173. //2021.05修改
  2174. _finishLiveView.shareFollowBtn.hidden = YES;
  2175. _finishLiveView.backHomeBtn.hidden = NO;
  2176. _finishLiveView.backTopConstraint.constant = 60;
  2177. _finishLiveView.userIDLabel.text =ASLocalizedString( @"直播已结束");
  2178. }
  2179. else
  2180. {
  2181. // _finishLiveView.screenshotShareBtn.hidden = YES;
  2182. // _finishLiveView.hostContrainerView.hidden = YES;
  2183. _finishLiveView.shareFollowBtn.hidden = NO;
  2184. _finishLiveView.delLiveVideoBtn.hidden = YES;
  2185. _finishLiveView.backTopConstraint.constant = 120;
  2186. _finishLiveView.userIDLabel.text = [NSString stringWithFormat:@"ID %@",liveInfo.podcast.user.user_id];
  2187. }
  2188. FWWeakify(self)
  2189. _finishLiveView.shareFollowBlock = ^(){
  2190. FWStrongify(self)
  2191. // 主播此时是“分享”按钮,观众此时是“关注”按钮
  2192. if (self.isHost)
  2193. {
  2194. FWStrongify(self)
  2195. [self clickedFinishLiveViewBackHomeBtn];
  2196. //分享
  2197. // [self shareWithModel:self.currentLiveInfo.share];
  2198. }
  2199. else
  2200. {
  2201. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2202. [mDict setObject:@"user" forKey:@"ctl"];
  2203. [mDict setObject:@"follow" forKey:@"act"];
  2204. if (![BGUtils isBlankString:self.currentLiveInfo.user_id])
  2205. {
  2206. [mDict setObject:self.currentLiveInfo.user_id forKey:@"to_user_id"];
  2207. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  2208. if ([responseJson toInt:@"status"] == 1)
  2209. {
  2210. if ([responseJson toInt:@"has_focus"] == 1)
  2211. {
  2212. [self.finishLiveView.shareFollowBtn setTitle:ASLocalizedString(@"已关注")forState:UIControlStateNormal];
  2213. }
  2214. else
  2215. {
  2216. [self.finishLiveView.shareFollowBtn setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  2217. }
  2218. }
  2219. } FailureBlock:^(NSError *error) {
  2220. }];
  2221. }
  2222. }
  2223. };
  2224. _finishLiveView.backHomeBlock = ^(){
  2225. FWStrongify(self)
  2226. [self clickedFinishLiveViewBackHomeBtn];
  2227. };
  2228. _finishLiveView.screenshotShareBlock = ^{
  2229. FWStrongify(self)
  2230. [self shareWithModel:self.currentLiveInfo.share];
  2231. };
  2232. /*
  2233. _finishLiveView.delLiveBlock = ^(){
  2234. FWStrongify(self)
  2235. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2236. [mDict setObject:@"video" forKey:@"ctl"];
  2237. [mDict setObject:@"del_video" forKey:@"act"];
  2238. [mDict setObject:self.roomIDStr forKey:@"room_id"];
  2239. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  2240. FWStrongify(self)
  2241. [self clickedFinishLiveViewBackHomeBtn];
  2242. } FailureBlock:^(NSError *error) {
  2243. FWStrongify(self)
  2244. [self clickedFinishLiveViewBackHomeBtn];
  2245. }];
  2246. };
  2247. */
  2248. }
  2249. - (void)clickedFinishLiveViewBackHomeBtn
  2250. {
  2251. if (self.delegate && [self.delegate respondsToSelector:@selector(finishViewClose:)])
  2252. {
  2253. [self.delegate finishViewClose:self];
  2254. }
  2255. }
  2256. #pragma mark 显示主播结束界面
  2257. - (void)showHostFinishView:(NSString *)audience andVote:(NSString *)vote andHasDel:(BOOL)hasDel
  2258. {
  2259. if (_isHost)
  2260. {
  2261. [BGUtils closeKeyboard];
  2262. _finishLiveView.delLiveVideoBtn.hidden = !hasDel;
  2263. [self.view addSubview:_finishLiveView];
  2264. [self.view bringSubviewToFront:_finishLiveView];
  2265. if ([BGUtils isBlankString:audience] && [BGUtils isBlankString:vote])
  2266. {
  2267. [_finishLiveView.acIndicator startAnimating];
  2268. }
  2269. else
  2270. {
  2271. [_finishLiveView.acIndicator stopAnimating];
  2272. _finishLiveView.acIndicator.hidden = YES;
  2273. _finishLiveView.audienceNumLabel.text = audience;
  2274. _finishLiveView.hostLight.text = vote;
  2275. }
  2276. }
  2277. }
  2278. #pragma mark 显示观众结束界面
  2279. - (void)showAudienceFinishView:(CustomMessageModel *)customMessageModel
  2280. {
  2281. if (!_isHost)
  2282. {
  2283. [BGUtils closeKeyboard];
  2284. NSString *audienceTotalStr = customMessageModel.show_num;
  2285. if ([BGUtils isBlankString:audienceTotalStr])
  2286. {
  2287. [_finishLiveView.acIndicator startAnimating];
  2288. }
  2289. else
  2290. {
  2291. [_finishLiveView.acIndicator stopAnimating];
  2292. _finishLiveView.acIndicator.hidden = YES;
  2293. _finishLiveView.audienceNumLabel.text = audienceTotalStr;
  2294. }
  2295. //现在观众端无法记录
  2296. self.finishLiveView.liveTimeL.hidden = YES;
  2297. self.finishLiveView.liveTimeStrLabel.hidden = YES;
  2298. self.finishLiveView.viewToTopConstraint.constant = 119 / 2;
  2299. self.finishLiveView.consumStrLabel.text =ASLocalizedString( @"消费数");
  2300. self.finishLiveView.audienceBGView.hidden = NO;
  2301. self.finishLiveView.hostContrainerView.backgroundColor = kClearColor;
  2302. //_isFollowAnchor 是否已关注主播
  2303. if (_isFollowAnchor)
  2304. {
  2305. self.finishLiveView.shareFollowBtn.hidden = YES;
  2306. self.finishLiveView.backTopConstraint.constant = 119;
  2307. }
  2308. else
  2309. {
  2310. self.finishLiveView.backTopConstraint.constant = 119;
  2311. [self.finishLiveView.shareFollowBtn setTitle:ASLocalizedString(@"关注主播")forState:UIControlStateNormal];
  2312. }
  2313. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2314. [mDict setObject:@"video" forKey:@"ctl"];
  2315. [mDict setObject:@"user_consumption_sum" forKey:@"act"];
  2316. [mDict setObject:_roomIDStr forKey:@"room_id"];
  2317. NSLog(@"%@",_roomIDStr);
  2318. FWWeakify(self)
  2319. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  2320. NSLog(@"%@",responseJson);
  2321. _finishLiveView.hostLight.text = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"total_diamonds"]];
  2322. } FailureBlock:^(NSError *error) {
  2323. }];
  2324. [self.view addSubview:_finishLiveView];
  2325. [self.view bringSubviewToFront:_finishLiveView];
  2326. }
  2327. }
  2328. #pragma mark - ----------------------- 其他代理方法 -----------------------
  2329. #pragma mark ========== FWLiveUIViewControllerServeiceDelegate ==========
  2330. - (void)showRechargeView:(BGLiveUIViewController *)liveUIViewController
  2331. {
  2332. [self rechargeView:_liveUIViewController.liveView];
  2333. }
  2334. #pragma mark ========== TCShowLiveViewServiceDelegate ==========
  2335. #pragma mark 显示充值
  2336. - (void)rechargeView:(TCShowLiveView *)showLiveView
  2337. {
  2338. [self.rechargePopView show:self.view type:FDPopTypeBottom];
  2339. // if (!self.mgRechargeView) {
  2340. // self.mgRechargeView = [[MGLiveRechargeView alloc]initWithFrame:CGRectMake(0, kScreenH - kRealValue(485), kScreenW, kRealValue(485))];
  2341. // }
  2342. // [self.mgRechargeView show:self.view];
  2343. // self.rechargeView.hidden = NO;
  2344. // SUS_WINDOW.window_Tap_Ges.enabled = NO;
  2345. // SUS_WINDOW.window_Pan_Ges.enabled = NO;
  2346. // [self.rechargeView loadRechargeData];
  2347. //
  2348. // FWWeakify(self)
  2349. // [UIView animateWithDuration:0.5 animations:^{
  2350. //
  2351. // FWStrongify(self)
  2352. // self.rechargeView.transform = CGAffineTransformMakeTranslation(0, (kScreenH-kRechargeViewHeight)/2-kScreenH);
  2353. //
  2354. // } completion:^(BOOL finished) {
  2355. //
  2356. // }];
  2357. }
  2358. #pragma mark 连麦、关闭连麦
  2359. - (void)clickMikeBtn:(TCShowLiveView *)showLiveView
  2360. {
  2361. [self canMike];
  2362. }
  2363. - (void)canMike
  2364. {
  2365. if ([GlobalVariables sharedInstance].isBeingPK) {
  2366. [FanweMessage alertHUD:ASLocalizedString(@"pk中不可以连麦")];
  2367. return;
  2368. }
  2369. if (_delegate && [_delegate respondsToSelector:@selector(openOrCloseMike:)])
  2370. {
  2371. [_delegate openOrCloseMike:self];
  2372. }
  2373. }
  2374. #pragma mark IM私聊
  2375. - (void)clickIM:(TCShowLiveView *)showLiveView
  2376. {
  2377. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  2378. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  2379. // 加载半VC;
  2380. [_liveUIViewController addTwoSubVC];
  2381. }
  2382. - (void)clickFace:(TCShowLiveView *)showLiveView
  2383. {
  2384. [_liveUIViewController showFace];
  2385. }
  2386. -(void)clickMusic:(TCShowLiveView *)showLiveView
  2387. {
  2388. BOOL isInMike = NO;
  2389. for(int i = 0;i < self.currentLiveInfo.wheat_type_list.count; i++)
  2390. {
  2391. Wheat_Type_List *model = self.currentLiveInfo.wheat_type_list[i];
  2392. if(model.even_wheat.user_id == [IMAPlatform sharedInstance].host.userId.intValue)
  2393. {
  2394. isInMike = YES;
  2395. break;
  2396. }
  2397. }
  2398. if(isInMike)
  2399. {
  2400. [_liveUIViewController showMusic];
  2401. }
  2402. else
  2403. {
  2404. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"上麦后才能播放音乐")];
  2405. }
  2406. }
  2407. #pragma mark 点击liveView的空白
  2408. - (void)clickBlank:(TCShowLiveView *)showLiveView
  2409. {
  2410. [_liveUIViewController hiddenPKlist];
  2411. // 后期通知要废掉
  2412. self.liveUIViewController.panGestureRec.enabled = YES;
  2413. for (UIViewController *one_VC in self.liveUIViewController.childViewControllers)
  2414. {
  2415. [[NSNotificationCenter defaultCenter] postNotificationName:@"imRemoveNeedUpdate" object:nil];
  2416. FWWeakify(self)
  2417. // chatVC存在
  2418. if ([one_VC isKindOfClass:[BGConversationSegmentController class]])
  2419. {
  2420. BGConversationSegmentController *imChat_VC = (BGConversationSegmentController *)one_VC;
  2421. __weak BGConversationSegmentController *imchat = imChat_VC;
  2422. [UIView animateWithDuration:kHalfVCViewanimation animations:^{
  2423. imchat.view.y = kScreenH;
  2424. } completion:^(BOOL finished) {
  2425. FWStrongify(self)
  2426. if(finished)
  2427. {
  2428. [imChat_VC.view removeFromSuperview];
  2429. [self.liveUIViewController removeChild:imChat_VC];
  2430. self.liveUIViewController.isHaveHalfIMChatVC = NO;
  2431. self.liveUIViewController.isKeyboardTypeNum = 0;
  2432. }
  2433. }];
  2434. }
  2435. // 聊天退出
  2436. if ([one_VC isKindOfClass:[BGConversationServiceController class]])
  2437. {
  2438. BGConversationSegmentController *imMsgChat_VC = (BGConversationSegmentController *)one_VC;
  2439. __weak BGConversationSegmentController *imchat = imMsgChat_VC;
  2440. [UIView animateWithDuration:kHalfVCViewanimation animations:^{
  2441. imchat.view.y = kScreenH;
  2442. } completion:^(BOOL finished) {
  2443. FWStrongify(self)
  2444. [imMsgChat_VC.view removeFromSuperview];
  2445. [self.liveUIViewController removeChild:imMsgChat_VC];
  2446. self.liveUIViewController.isHaveHalfIMMsgVC = NO;
  2447. self.liveUIViewController.isKeyboardTypeNum = 0;
  2448. }];
  2449. }
  2450. }
  2451. }
  2452. #pragma mark ========== TCShowLiveMessageViewDelegate ==========
  2453. - (void)getUserInfo:(UserModel *)userModel
  2454. {
  2455. // 关闭键盘
  2456. [BGUtils closeKeyboard];
  2457. if (!_informationView)
  2458. {
  2459. _informationView = [[[NSBundle mainBundle]loadNibNamed:@"SLiveHeadInfoView" owner:self options:nil] objectAtIndex:0];
  2460. _informationView.infoDelegate = self;
  2461. _informationView.frame = CGRectMake(0,kScreenH,kScreenW, kScreenH);
  2462. [_informationView updateUIWithModel:userModel withRoom:_liveItem];
  2463. [_liveUIViewController.view addSubview:_informationView];
  2464. [UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
  2465. CGRect rect = _informationView.frame;
  2466. rect.origin.y = 0;
  2467. _informationView.frame = rect;
  2468. } completion:^(BOOL finished) {
  2469. }];
  2470. [self setUpLocalizationStringForView:_informationView];
  2471. // _informationView loc
  2472. }else
  2473. {
  2474. [self removeInformationView];
  2475. }
  2476. }
  2477. #pragma mark 点击消息列表中的用户名称
  2478. - (void)clickNameRange:(CustomMessageModel *) customMessageModel
  2479. {
  2480. UserModel *userModel = [[UserModel alloc]init];
  2481. userModel.user_id = customMessageModel.sender.user_id;
  2482. userModel.nick_name = customMessageModel.sender.nick_name;
  2483. userModel.head_image = customMessageModel.sender.head_image;
  2484. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)customMessageModel.sender.user_level];
  2485. [self getUserInfo:userModel];
  2486. }
  2487. - (void)clickUserInfo:(cuserModel *)cuser
  2488. {
  2489. UserModel *userModel = [[UserModel alloc]init];
  2490. userModel.user_id = cuser.user_id;
  2491. userModel.nick_name = cuser.nick_name;
  2492. userModel.head_image = cuser.head_image;
  2493. userModel.user_level = [NSString stringWithFormat:@"%ld",(long)cuser.user_level];
  2494. [self getUserInfo:userModel];
  2495. }
  2496. #pragma mark 点击消息列表中的具体消息内容(目前会响应点击事件的是:红包)
  2497. - (void)clickMessageRange:(CustomMessageModel *) customMessageModel
  2498. {
  2499. BGRedPackModel *user = [BGRedPackModel new];
  2500. user.head_image = customMessageModel.dicData[@"head_image"];
  2501. user.nick_name = customMessageModel.dicData[@"nick_name"];
  2502. user.id = customMessageModel.dicData[@"surprise_id"];
  2503. BGOpenRedPackView *readView = [[BGOpenRedPackView alloc] init];
  2504. // readView.video_id = self.video_id;
  2505. readView.userModel = user;
  2506. readView.frame = CGRectMake(40, 0, kScreenW-40*2, kScreenH-140*2);
  2507. readView.userModel = user;
  2508. // readView.backgroundColor = kRedColor;
  2509. [readView show:[AppDelegate sharedAppDelegate].topViewController.view type:FDPopTypeCenter];
  2510. return;
  2511. //防止当前页面中正在展示该红包
  2512. for (UIView *view in _liveUIViewController.liveView.subviews)
  2513. {
  2514. if ([view isKindOfClass:[SLiveRedBagView class]])
  2515. {
  2516. SLiveRedBagView *redBagView = (SLiveRedBagView *)view;
  2517. if ([redBagView.customMessageModel isEquals:customMessageModel])
  2518. {
  2519. return;
  2520. }
  2521. }
  2522. }
  2523. [self clickNameRange:customMessageModel];
  2524. if (customMessageModel.type == MSG_RED_PACKET)
  2525. {
  2526. SLiveRedBagView *redBagView = [[[NSBundle mainBundle]loadNibNamed:@"SLiveRedBagView" owner:self options:nil] objectAtIndex:0];
  2527. redBagView.frame = CGRectMake(0,0,kScreenW,kScreenH);
  2528. redBagView.video_id = self.currentLiveInfo.room_id;
  2529. redBagView.rebBagDelegate = self;
  2530. [redBagView creatRedWithModel:customMessageModel];
  2531. if (customMessageModel.isRedPackageTaked)
  2532. {
  2533. [redBagView changeRedPackageView];
  2534. }
  2535. [_liveUIViewController.liveView addSubview:redBagView];
  2536. }
  2537. }
  2538. #pragma mark 点击消息列表中的商品推送信息
  2539. - (void)clickGoodsMessage:(CustomMessageModel *) customMessageModel
  2540. {
  2541. if (customMessageModel.goods.url.length>0 && customMessageModel.goods.type == 1)
  2542. {
  2543. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:customMessageModel.goods.url isShowIndicator:YES isShowNavBar:!kSupportH5Shopping isShowBackBtn:YES isShowCloseBtn:YES];
  2544. [tmpController initRightBarBtnItemWithType:RightBarBtnItemBackLiveVC titleStr:ASLocalizedString(@"直播")];
  2545. // if (kSupportH5Shopping || self.BuguLive.appModel.open_podcast_goods == 1)
  2546. // {
  2547. // tmpController.isSmallScreen = NO;
  2548. // }
  2549. // else
  2550. // {
  2551. // tmpController.isSmallScreen = YES;
  2552. // }
  2553. tmpController.isSmallScreen = NO;
  2554. tmpController.httpMethodStr = @"GET";
  2555. [self toGoH5With:tmpController andShowSmallWindow:tmpController.isSmallScreen];
  2556. }
  2557. else
  2558. {
  2559. GoodsModel * model = [[GoodsModel alloc] init];
  2560. model = customMessageModel.goods;
  2561. NSString * hostId = [[_liveItem liveHost] imUserId];
  2562. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2563. [mDict setObject:@"pai_user" forKey:@"ctl"];
  2564. [mDict setObject:@"open_goods_detail" forKey:@"act"];
  2565. [mDict setObject:hostId forKey:@"podcast_id"];
  2566. [mDict setObject:@"shop" forKey:@"itype"];
  2567. if(model.goods_id>0)
  2568. {
  2569. [mDict setObject:model.goods_id forKey:@"goods_id"];
  2570. }
  2571. FWWeakify(self)
  2572. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  2573. FWStrongify(self)
  2574. if ([responseJson toInt:@"status"] == 1)
  2575. {
  2576. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:[responseJson toString:@"url"] isShowIndicator:YES isShowNavBar:!kSupportH5Shopping isShowBackBtn:YES isShowCloseBtn:YES];
  2577. [tmpController initRightBarBtnItemWithType:RightBarBtnItemBackLiveVC titleStr:ASLocalizedString(@"直播")];
  2578. // if (kSupportH5Shopping || self.BuguLive.appModel.open_podcast_goods == 1)
  2579. // {
  2580. // tmpController.isSmallScreen = NO;
  2581. // }
  2582. // else
  2583. // {
  2584. // tmpController.isSmallScreen = YES;
  2585. // }
  2586. tmpController.isSmallScreen = NO;
  2587. tmpController.httpMethodStr = @"GET";
  2588. [self toGoH5With:tmpController andShowSmallWindow:tmpController.isSmallScreen];
  2589. }
  2590. } FailureBlock:^(NSError *error) {
  2591. }];
  2592. }
  2593. if ([_liveUIViewController.liveView.liveInputView isInputViewActive])
  2594. {
  2595. [_liveUIViewController.liveView.liveInputView resignFirstResponder];
  2596. }
  2597. }
  2598. #pragma mark ========== SLiveHeadInfoViewDelegate ==========
  2599. - (void)operationHeadView:(SLiveHeadInfoView *)headView andUserId:(NSString *)userId andNameStr:(NSString *)nameStr andUserImgUrl:(NSString *)userImgUrl andIs_robot:(BOOL)is_robot andViewType:(int)viewType
  2600. {
  2601. [self removeInformationView];
  2602. switch (viewType)
  2603. {
  2604. case 1: //删除_informationView
  2605. {
  2606. //[self removeInformationView];
  2607. }
  2608. break;
  2609. case 2: //进入用户主页
  2610. {
  2611. // NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2612. // [mDict setObject:@"pk_tencent" forKey:@"ctl"];
  2613. // [mDict setObject:@"get_pk_lists" forKey:@"act"];
  2614. // [mDict setObject:@"1" forKey:@"page"];
  2615. // [mDict setObject:@"164741" forKey:@"user_id"];
  2616. //
  2617. //
  2618. //
  2619. // [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  2620. //
  2621. // } FailureBlock:^(NSError *error) {
  2622. //
  2623. // }];
  2624. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  2625. tmpController.user_id = userId;
  2626. tmpController.type = 0;
  2627. WeakSelf
  2628. tmpController.clickHomePageBlock = ^(BOOL isFocus) {
  2629. if ([userId isEqualToString:[[_liveItem liveHost] imUserId]]) {
  2630. if (isFocus) {
  2631. self.liveUIViewController.liveView.topView.isShowFollowBtn = NO;
  2632. self.isFollowAnchor = YES;
  2633. [self.liveUIViewController.liveView.topView relayoutFrameOfSubViews];
  2634. }else{
  2635. self.liveUIViewController.liveView.topView.isShowFollowBtn = YES;
  2636. self.isFollowAnchor = NO;
  2637. [self.liveUIViewController.liveView.topView relayoutFrameOfSubViews];
  2638. }
  2639. }
  2640. };
  2641. BGNavigationController *nav = [[BGNavigationController alloc] initWithRootViewController:tmpController];
  2642. [self presentViewController:nav animated:YES completion:nil];
  2643. }
  2644. break;
  2645. case 3: //进入管理员列表
  2646. {
  2647. ManagerViewController *tmpController = [[ManagerViewController alloc]init];
  2648. // [[AppDelegate sharedAppDelegate]pushViewController:tmpController];
  2649. [self.navigationController pushViewController:tmpController animated:YES];
  2650. }
  2651. break;
  2652. case 4: //@某个用户
  2653. {
  2654. if (_liveUIViewController.liveView.giftView.hidden == NO)
  2655. {
  2656. [_liveUIViewController.liveView hiddenGiftView];
  2657. }
  2658. [_liveUIViewController.liveView.liveInputView.textField becomeFirstResponder];
  2659. _liveUIViewController.liveView.liveInputView.hidden = NO;
  2660. _liveUIViewController.liveView.bottomView.hidden = YES;
  2661. _liveUIViewController.liveView.liveInputView.textField.text = [NSString stringWithFormat:@"%@%@ ",@"@",nameStr];
  2662. }
  2663. break;
  2664. case 5: //举报
  2665. {
  2666. _tipoffUserId = userId;
  2667. _liveReportV = [[SLiveReportView alloc]initWithFrame:CGRectMake(0,0,kScreenW,kScreenH)];
  2668. _liveReportV.reportDelegate = self;
  2669. [_liveUIViewController.liveView addSubview:_liveReportV];
  2670. }
  2671. break;
  2672. case 6: //进入IM消息
  2673. {
  2674. SFriendObj* chattag = [[SFriendObj alloc]initWithUserId:[userId intValue]];
  2675. chattag.mNick_name = nameStr;
  2676. chattag.mHead_image = userImgUrl;
  2677. chattag.is_robot = is_robot;
  2678. BGConversationServiceController* chatvc = [BGConversationServiceController makeChatVCWith:chattag];
  2679. chatvc.mtoptitle.text = nameStr;
  2680. BGNavigationController *nav = [[BGNavigationController alloc] initWithRootViewController:chatvc];
  2681. nav.navigationBarHidden = YES;
  2682. [self presentViewController:nav animated:YES completion:nil];
  2683. }
  2684. break;
  2685. default:
  2686. break;
  2687. }
  2688. }
  2689. -(void)clickHeadViewRefresh{
  2690. [_liveUIViewController.liveView.topView refreshTicketCount:[NSString stringWithFormat:@"%ld",(long)_voteNumber]];
  2691. }
  2692. - (void)removeInformationView
  2693. {
  2694. [_informationView removeFromSuperview];
  2695. _informationView = nil;
  2696. }
  2697. //- (void)IMchatMsg:(int)userid userimgurl:(NSString*)userimgurl username:(NSString*)username is_robot:(BOOL)is_robot
  2698. //{
  2699. // SFriendObj* chattag = [[SFriendObj alloc]initWithUserId:userid];
  2700. //
  2701. // chattag.mNick_name = username;
  2702. // chattag.mHead_image = userimgurl;
  2703. // chattag.is_robot = is_robot;
  2704. //
  2705. // BGConversationServiceController* chatvc = [BGConversationServiceController makeChatVCWith:chattag];
  2706. // chatvc.mtoptitle.text = username;
  2707. // BGNavigationController *nav = [[BGNavigationController alloc] initWithRootViewController:chatvc];
  2708. // nav.navigationBarHidden = YES;
  2709. // [self presentViewController:nav animated:YES completion:nil];
  2710. //}
  2711. #pragma mark ========== ReportViewDelegate ==========
  2712. - (void)clickWithReportId:(NSString *)reportId andBtnIndex:(int)btnIndex andView:(SLiveReportView *)reportView
  2713. {
  2714. if (btnIndex == 1)
  2715. {
  2716. if (reportId.length < 1)
  2717. {
  2718. [FanweMessage alert:ASLocalizedString(@"请选择举报类型")];
  2719. return;
  2720. }
  2721. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2722. [mDict setObject:@"user" forKey:@"ctl"];
  2723. [mDict setObject:@"tipoff" forKey:@"act"];
  2724. if (_tipoffUserId) {
  2725. [mDict setObject:_tipoffUserId forKey:@"to_user_id"];
  2726. }
  2727. [mDict setObject:_roomIDStr forKey:@"room_id"];
  2728. [mDict setObject:reportId forKey:@"type"];
  2729. FWWeakify(self)
  2730. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  2731. FWStrongify(self)
  2732. [self.liveReportV removeFromSuperview];
  2733. self.liveReportV = nil;
  2734. if ([responseJson toInt:@"status"] == 1)
  2735. {
  2736. [FanweMessage alertHUD:ASLocalizedString(@"已收到举报消息,我们将尽快落实处理")];
  2737. }
  2738. } FailureBlock:^(NSError *error) {
  2739. }];
  2740. }
  2741. else
  2742. {
  2743. [_liveReportV removeFromSuperview];
  2744. _liveReportV = nil;
  2745. }
  2746. }
  2747. #pragma mark ========== TCShowLiveTopViewDelegate ==========
  2748. #pragma mark 点击用户头像
  2749. - (void)onTopView:(TCShowLiveTopView *)topView userModel:(UserModel *)userModel
  2750. {
  2751. [self getUserInfo:userModel];
  2752. }
  2753. #pragma mark 点击关注按钮
  2754. - (void)followAchor:(TCShowLiveTopView *)topView
  2755. {
  2756. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2757. [mDict setObject:@"user" forKey:@"ctl"];
  2758. [mDict setObject:@"follow" forKey:@"act"];
  2759. [mDict setObject:_roomIDStr forKey:@"room_id"];
  2760. if ([[_liveItem liveHost] imUserId])
  2761. {
  2762. [mDict setObject:[[_liveItem liveHost] imUserId] forKey:@"to_user_id"];
  2763. FWWeakify(self)
  2764. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  2765. FWStrongify(self)
  2766. if ([responseJson toInt:@"status"] == 1)
  2767. {
  2768. if ([responseJson toInt:@"has_focus"] == 1)
  2769. {
  2770. self.liveUIViewController.liveView.topView.isShowFollowBtn = NO;
  2771. self.isFollowAnchor = YES;
  2772. [self.liveUIViewController.liveView.topView relayoutFrameOfSubViews];
  2773. NSString *follow_msg = [responseJson toString:@"follow_msg"];
  2774. if (![BGUtils isBlankString:[[IMAPlatform sharedInstance].host imUserName]] && ![BGUtils isBlankString:follow_msg])
  2775. {
  2776. [self sentMessageWithStr:follow_msg];
  2777. }
  2778. }
  2779. else
  2780. {
  2781. self.isFollowAnchor = NO;
  2782. }
  2783. }
  2784. } FailureBlock:^(NSError *error) {
  2785. }];
  2786. }
  2787. }
  2788. #pragma mark 点击关注按钮发送IM通知
  2789. - (void)sentMessageWithStr:(NSString *)msgStr
  2790. {
  2791. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  2792. sendCustomMsgModel.msgType = MSG_LIVING_MESSAGE;
  2793. sendCustomMsgModel.msg = msgStr;
  2794. sendCustomMsgModel.chatGroupID = [_liveItem liveIMChatRoomId];
  2795. [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  2796. }
  2797. #pragma mark 进入印票排行榜
  2798. - (void)goToContributionList:(TCShowLiveTopView *)topView
  2799. {
  2800. ContributionListViewController *VC = [[ContributionListViewController alloc]init];
  2801. VC.user_id = [[_liveItem liveHost] imUserId];
  2802. VC.liveHost_id = [[_liveItem liveHost] imUserId];
  2803. VC.type = @"1";
  2804. // VC.fromType = @"1";
  2805. VC.liveAVRoomId = _roomIDStr;
  2806. [VC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
  2807. [self.navigationController pushViewController:VC animated:YES];
  2808. }
  2809. #pragma mark - 进入守护排行榜
  2810. - (void)goToWardPopView:(TCShowLiveTopView *)topView{
  2811. [self.liveUIViewController.liveView hiddenGiftView];
  2812. _wardPopView = [[WardPopView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kRealValue(416)) UserId:self.currentLiveInfo.user_id ResponseJson:topView.wardJson];
  2813. [_wardPopView show:self.view];
  2814. __weak typeof(self) weakSelf = self;
  2815. [_wardPopView setClickOpenBtnBlock:^{
  2816. __strong typeof(weakSelf) strongSelf = weakSelf;
  2817. //点击了开通守护
  2818. NSLog(ASLocalizedString(@"点击了开通守护功能"));
  2819. BogoWardOpenView *openView = [[BogoWardOpenView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kRealValue(569)) UserId:self.currentLiveInfo.user_id];
  2820. [openView setClickOpenViewBtnBlock:^(NSString *currentId){
  2821. //开通守护
  2822. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  2823. [dict setValue:@"guardians" forKey:@"ctl"];
  2824. [dict setValue:@"guardian_buy" forKey:@"act"];
  2825. [dict setValue:self.currentLiveInfo.user_id forKey:@"host_id"];
  2826. [dict setValue:currentId forKey:@"id"];
  2827. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  2828. if ([responseJson toInt:@"status"] == 1) {
  2829. NSLog(ASLocalizedString(@"开通守护成功"));
  2830. if ([[GlobalVariables sharedInstance].is_guartian isEqualToString:@"1"]) {
  2831. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"守护续费成功")];
  2832. }else{
  2833. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"开通守护成功")];
  2834. }
  2835. [_liveUIViewController.liveView.topView requestWardData];
  2836. [_wardPopView show:[UIApplication sharedApplication].keyWindow];
  2837. self.currentLiveInfo.is_guardian = 1;
  2838. [GlobalVariables sharedInstance].is_guartian = @"1";
  2839. [self getGuardianInfo];
  2840. // //发送群组消息
  2841. // SendCustomMsgModel *scmm = [[SendCustomMsgModel alloc] init];
  2842. // scmm.msgType = MSG_OPEN_GUARD_SUCCESS;
  2843. // scmm.chatGroupID = [_liveItem liveIMChatRoomId];
  2844. // [[BGIMMsgHandler sharedInstance] sendCustomGroupMsg:scmm succ:^{
  2845. // NSLog(ASLocalizedString(@"开通守护之后发送群组消息成功"));
  2846. // } fail:^(int code, NSString *msg) {
  2847. // NSLog(ASLocalizedString(@"开通守护之后发送群组消息失败:code:%d msg:%@"),code,msg);
  2848. // }];
  2849. }else{
  2850. NSLog(ASLocalizedString(@"开通守护失败responseJson:%@"),responseJson);
  2851. }
  2852. } FailureBlock:^(NSError *error) {
  2853. NSLog(ASLocalizedString(@"开通守护失败error:%@"),error);
  2854. }];
  2855. }];
  2856. __block BGLiveServiceController *blockSelf = weakSelf;
  2857. [openView setClickWardListBtnBlock:^{
  2858. [blockSelf->_wardPopView show:[UIApplication sharedApplication].keyWindow];
  2859. }];
  2860. [openView setClickFAQBtnBlock:^{
  2861. //去到网页
  2862. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.h5_url.guartian_details isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  2863. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  2864. }];
  2865. __weak typeof(openView) weakOpenView = openView;
  2866. [openView setClickPrivilegeBtnBlock:^(NSString *htmlString, WardPrivilegeButton *button, BOOL isLast) {
  2867. __strong typeof(weakOpenView) strongOpenView = weakOpenView;
  2868. if ([strongOpenView.subviews containsObject:strongSelf.tipView]) {
  2869. [strongSelf.tipView removeFromSuperview];
  2870. }
  2871. strongSelf.tipView = [[WardTipView alloc]initWithFrame:CGRectMake(80, kScreenH, kScreenW - 160, kScreenH / 2)];
  2872. [strongSelf.tipView setURL:htmlString];
  2873. [strongSelf.tipView show:[UIApplication sharedApplication].keyWindow];
  2874. [strongSelf.tipView setTipWebViewDidFinishLoadBlock:^{
  2875. }];
  2876. }];
  2877. [openView show:[UIApplication sharedApplication].keyWindow];
  2878. }];
  2879. [_wardPopView setClickWardPopViewCellBlock:^(WardPopViewModel * _Nonnull model) {
  2880. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  2881. tmpController.user_id = model.uid;
  2882. tmpController.type = 0;
  2883. [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  2884. }];
  2885. }
  2886. #pragma mark 移除添加好友的View
  2887. - (void)removeAddFriendView
  2888. {
  2889. [_addFView removeFromSuperview];
  2890. _addFView = nil;
  2891. }
  2892. #pragma mark PasteViewDelegate 微信qq添加好友跳转
  2893. - (void)sentPasteWithIndex:(int)index withShareIndex:(int)shareIndex
  2894. {
  2895. UIPasteboard *pasteboard=[UIPasteboard generalPasteboard];
  2896. pasteboard.string = _privateShareString;
  2897. if (index == 0 || index == 1)
  2898. {
  2899. [_PView removeFromSuperview];
  2900. _PView = nil;
  2901. }
  2902. else
  2903. {
  2904. if (shareIndex == 0)
  2905. {
  2906. NSString *str =@"weixin://qr/JnXv90fE6hqVrQOU9yA0";
  2907. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
  2908. [_PView removeFromSuperview];
  2909. _PView = nil;
  2910. }
  2911. else
  2912. {
  2913. NSString *str =@"mqq://";
  2914. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
  2915. [_PView removeFromSuperview];
  2916. _PView = nil;
  2917. }
  2918. }
  2919. }
  2920. #pragma mark PasteViewDelegate
  2921. - (void)deletePasteView
  2922. {
  2923. if (_PView)
  2924. {
  2925. [_PView removeFromSuperview];
  2926. _PView = nil;
  2927. }
  2928. }
  2929. #pragma mark 添加好友跳转
  2930. - (void)addFriendWithIndex:(int)index
  2931. {
  2932. if (index == 0 || index == 1)
  2933. {
  2934. [self removeAddFriendView];
  2935. if (!_PView)
  2936. {
  2937. _PView = [[[NSBundle mainBundle]loadNibNamed:@"PasteView" owner:self options:nil] lastObject];
  2938. _PView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  2939. _PView.shareIndex = index;
  2940. _PView.delegate = self;
  2941. [self.view addSubview:_PView];
  2942. }
  2943. }
  2944. else // 添加好友
  2945. {
  2946. [_addFView removeFromSuperview];
  2947. _addFView = nil;
  2948. SManageFriendVC *manageVC = [[SManageFriendVC alloc]init];
  2949. manageVC.liveAVRoomId = _roomIDStr;
  2950. manageVC.type = 1;
  2951. [self presentViewController:manageVC animated:YES completion:nil];
  2952. }
  2953. }
  2954. #pragma mark 最新点击+ -跳转
  2955. - (void)onTopView:(TCShowLiveTopView *)topView andCount:(int)count
  2956. {
  2957. if (count == 0)
  2958. {
  2959. if (!_addFView)
  2960. {
  2961. _addFView = [[[NSBundle mainBundle]loadNibNamed:@"AddFriendView" owner:self options:nil] lastObject];
  2962. _addFView.delegate = self;
  2963. _addFView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  2964. [self.view addSubview:_addFView];
  2965. }
  2966. else
  2967. {
  2968. [self removeAddFriendView];
  2969. }
  2970. }
  2971. else if (count == 1)
  2972. {
  2973. if (_addFView)
  2974. {
  2975. [self removeAddFriendView];
  2976. }
  2977. else
  2978. {
  2979. SManageFriendVC *manageVC = [[SManageFriendVC alloc]init];
  2980. manageVC.liveAVRoomId = _roomIDStr;
  2981. manageVC.chatAVRoomId = [_liveItem liveIMChatRoomId];
  2982. manageVC.type = 0;
  2983. [self presentViewController:manageVC animated:YES completion:nil];
  2984. }
  2985. }
  2986. }
  2987. #pragma mark - 通知接受到结束惩罚
  2988. - (void)endPunish{
  2989. [_liveUIViewController pkVivewHidden];
  2990. }
  2991. #pragma mark - 点击好友pk
  2992. -(void)clickPkList:(TCShowLiveView *)showLiveView
  2993. {
  2994. [_liveUIViewController showPKlist];
  2995. }
  2996. -(void)clickShowShopView:(TCShowLiveView *)showLiveView{
  2997. // _shopView = [[MGShopView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kRealValue(416)) UserId:self.currentLiveInfo.user_id ResponseJson:nil];
  2998. // [_shopView show:self.view];
  2999. BogoLiveStartGoodListCellType type = BogoLiveStartGoodListCellTypeList;
  3000. if (!_isHost) {
  3001. type = BogoLiveStartGoodListCellTypeForUser;
  3002. }
  3003. self.cartPopView.type = type;
  3004. self.cartPopView.lid = self.currentLiveInfo.room_id;
  3005. [self.cartPopView show:self.liveUIViewController.view type:FDPopTypeBottom];
  3006. NSLog(@"");
  3007. [_liveUIViewController.liveView bringSubviewToFront:_liveUIViewController.liveView.giftView];
  3008. }
  3009. -(void)clickWishView:(TCShowLiveView *)showLiveView{
  3010. _liveUIViewController.wishView = nil;
  3011. [_liveUIViewController showWishView];
  3012. }
  3013. - (void)clickRoomManage:(TCShowLiveView *)showLiveView
  3014. {
  3015. if([self.delegate respondsToSelector:@selector(clickRoomManage)])
  3016. {
  3017. [self.delegate clickRoomManage];
  3018. }
  3019. }
  3020. #pragma mark 添加好友点击空白的地方
  3021. - (void)deleteFriendView
  3022. {
  3023. [self removeAddFriendView];
  3024. }
  3025. #pragma mark 控制半VC退出
  3026. - (void)clickTopViewUserHeaderMustQuitAllHalfVC:(TCShowLiveTopView*)topView
  3027. {
  3028. if (_liveUIViewController.liveView)
  3029. {
  3030. [self clickBlank:_liveUIViewController.liveView];
  3031. }
  3032. }
  3033. #pragma mark - ----------------------- 分享 -----------------------
  3034. #pragma mark 主播开始直播时点击的分享
  3035. - (void)hostShareLive
  3036. {
  3037. if (![BGUtils isBlankString:_liveUIViewController.liveView.share_type] && _isHost)
  3038. {
  3039. [BGLiveServiceViewModel hostShareCurrentLive:_currentLiveInfo.share shareType:_liveUIViewController.liveView.share_type vc:self block:nil];
  3040. }
  3041. }
  3042. #pragma mark 观众在直播间点击分享按钮
  3043. - (void)clickShareBtn:(TCShowLiveView *)showLiveView
  3044. {
  3045. [self shareWithModel:_currentLiveInfo.share];
  3046. }
  3047. #pragma mark 分享
  3048. - (void)shareWithModel:(ShareModel *)model
  3049. {
  3050. NSString *share_content;
  3051. if (![model.share_content isEqualToString:@""])
  3052. {
  3053. share_content = model.share_content;
  3054. }
  3055. else
  3056. {
  3057. share_content = model.share_title;
  3058. }
  3059. model.isNotifiService = YES;
  3060. model.roomIDStr = _roomIDStr;
  3061. model.imChatIDStr = [_liveItem liveIMChatRoomId];
  3062. [[BGUMengShareManager sharedInstance] showShareViewInControllr:self shareModel:model succ:nil failed:nil];
  3063. }
  3064. #pragma mark 是否显示关注通知的实现
  3065. - (void)isShowFollow:(NSNotification *)notification
  3066. {
  3067. NSDictionary *interuptionDict = notification.object;
  3068. if ([interuptionDict toString:@"userId"])
  3069. {
  3070. if ([[interuptionDict toString:@"userId"] isEqualToString:[[_liveItem liveHost] imUserId]])
  3071. {
  3072. if ([[interuptionDict objectForKey:@"isShowFollow"] intValue] == 0)
  3073. {
  3074. _liveUIViewController.liveView.topView.isShowFollowBtn = NO;
  3075. if ([interuptionDict objectForKey:@"follow_msg"])
  3076. {
  3077. // [self sentMessageWithStr:[interuptionDict objectForKey:@"follow_msg"]];
  3078. }
  3079. }
  3080. else
  3081. {
  3082. _liveUIViewController.liveView.topView.isShowFollowBtn = YES;
  3083. }
  3084. [_liveUIViewController.liveView.topView relayoutFrameOfSubViews];
  3085. }
  3086. }
  3087. }
  3088. #pragma mark - ----------------------- 插件中心 -----------------------
  3089. #pragma mark 创建插件中心
  3090. - (void)creatPluginCenter
  3091. {
  3092. if (!_pluginCenterView)
  3093. {
  3094. _pluginCenterBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  3095. _pluginCenterBgView.backgroundColor = [UIColor clearColor];
  3096. _pluginCenterBgView.hidden = YES;
  3097. [_liveUIViewController.liveView addSubview:_pluginCenterBgView];
  3098. UITapGestureRecognizer *pluginBgTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pluginBgViewClick)];
  3099. [_pluginCenterBgView addGestureRecognizer:pluginBgTap];
  3100. _pluginCenterView = [[PluginCenterView alloc]initWithFrame:CGRectMake(0, kScreenH , kScreenW, kPluginCenterHeight)];
  3101. _pluginCenterView.delegate = self;
  3102. _pluginCenterView.layer.masksToBounds = YES;
  3103. _pluginCenterView.backgroundColor = [UIColor colorWithHexString:@"#221336"];
  3104. [_liveUIViewController.liveView addSubview:_pluginCenterView];
  3105. }
  3106. }
  3107. #pragma mark 收起插件中心
  3108. - (void)closeGameList
  3109. {
  3110. [self closeGameListView];
  3111. }
  3112. #pragma mark 点击空白关闭插件中心
  3113. - (void)closeGamesView:(TCShowLiveView *)showLiveView
  3114. {
  3115. [self closeGameListView];
  3116. }
  3117. - (void)pluginBgViewClick
  3118. {
  3119. [self closeGameListView];
  3120. }
  3121. - (void)closeGameListView
  3122. {
  3123. FWWeakify(self)
  3124. [UIView animateWithDuration:0.3 animations:^{
  3125. FWStrongify(self)
  3126. self.pluginCenterBgView.hidden = YES;
  3127. self.pluginCenterView.frame = CGRectMake(0, kScreenH, kScreenW, kPluginCenterHeight);
  3128. } completion:^(BOOL finished) {
  3129. }];
  3130. }
  3131. #pragma mark 点击插件中心列表
  3132. - (void)loadGoldFlowerView:(GameModel *)model withGameID:(NSString *)gameID
  3133. {
  3134. if (_isHost)
  3135. {
  3136. if ([model.class_name isEqualToString:@"live_pay"]) // 按时付费
  3137. {
  3138. [self.liveUIViewController clickPluginPayItem:model closeBtn:_closeBtn];
  3139. }
  3140. else if ([model.class_name isEqualToString:@"live_pay_scene"]) // 按场付费
  3141. {
  3142. [self.liveUIViewController clickPluginPayItem:model closeBtn:_closeBtn];
  3143. }
  3144. else if ([model.class_name isEqualToString:@"pai"])
  3145. {
  3146. if ([model.is_active intValue] == 0)
  3147. {
  3148. // [self.auctionTool addView]; // 点击竞拍按钮后出现实物竞拍和虚拟竞拍
  3149. }
  3150. else
  3151. {
  3152. [FanweMessage alert:ASLocalizedString(@"直播间已处于竞拍中")];
  3153. }
  3154. }
  3155. else if ([model.class_name isEqualToString:@"shop"])
  3156. {
  3157. if ([model.is_active intValue] == 0)
  3158. {
  3159. // [self.auctionTool clickStarShopWithIsOTOShop:NO]; // 主播点击星店后
  3160. }
  3161. }
  3162. else if ([model.class_name isEqualToString:@"podcast_goods"])
  3163. {
  3164. if ([model.is_active intValue] == 0)
  3165. {
  3166. // [self.auctionTool clickStarShopWithIsOTOShop:YES]; // 主播点击星店后
  3167. }
  3168. }
  3169. else
  3170. {
  3171. if (self.pluginCenterView.game_id)
  3172. {
  3173. _liveUIViewController.liveView.gameId = [self.pluginCenterView.game_id integerValue];
  3174. [_liveUIViewController.liveView beginGame];
  3175. }
  3176. [_liveUIViewController.liveView addGameView];
  3177. }
  3178. }
  3179. }
  3180. #pragma mark 获取功能插件个数
  3181. - (void)getCount:(NSMutableArray *)array
  3182. {
  3183. self.gameOrFeatures = array.count;
  3184. }
  3185. - (void)clickGameBtn:(TCShowLiveView *)showLiveView
  3186. {
  3187. // 进一步控制悬浮手势
  3188. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  3189. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  3190. self.pluginCenterView.hidden = NO;
  3191. [_liveUIViewController.liveView bringSubviewToFront:self.pluginCenterView];
  3192. [self.pluginCenterView initGamesForNetWorking];
  3193. FWWeakify(self)
  3194. [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:5 options: UIViewAnimationOptionCurveLinear animations:^{
  3195. FWStrongify(self)
  3196. self.pluginCenterBgView.hidden = NO;
  3197. if (self.gameOrFeatures != 0)
  3198. {
  3199. self.pluginCenterView.frame = CGRectMake(0, kPluginCenterY , kScreenW, kPluginCenterHeight);
  3200. }
  3201. else
  3202. {
  3203. self.pluginCenterView.frame = CGRectMake(0, kScreenH - 250, kScreenW, 250);
  3204. }
  3205. } completion:^(BOOL finished) {
  3206. }];
  3207. }
  3208. - (void)toGoH5With:(UIViewController *)tmpController andShowSmallWindow:(BOOL)smallWindow
  3209. {
  3210. if (smallWindow == YES)
  3211. {
  3212. [[LiveCenterManager sharedInstance] showChangeAuctionLiveScreenSOfIsSmallScreen:YES nextViewController:tmpController delegateWindowRCNameStr:nil complete:^(BOOL finished) {
  3213. }];
  3214. }
  3215. else
  3216. {
  3217. [self.navigationController pushViewController:tmpController animated:YES];
  3218. }
  3219. }
  3220. - (void)changePayView:(TCShowLiveView *)showLiveView
  3221. {
  3222. // [self.liveUIViewController.livePay changeLeftViewFrameWithIsHost:_isHost andAuctionView:showLiveView.topView.priceView];
  3223. [self.liveUIViewController.livePay changeLeftViewFrameWithIsHost:_isHost andAuctionView:showLiveView.topView.priceView andBankerView:showLiveView.gameBankerView];
  3224. }
  3225. #pragma mark - ----------------------- 游戏相关 -----------------------
  3226. #pragma mark 重新开始直播时判断之前是否有游戏视图
  3227. - (void)reloadGameData
  3228. {
  3229. if (_liveUIViewController.liveView.goldFlowerView || _liveUIViewController.liveView.guessSizeView)
  3230. {
  3231. if (_liveUIViewController.liveView.goldFlowerView)
  3232. {
  3233. [_liveUIViewController.liveView disAboutClick];
  3234. [_liveUIViewController.liveView.goldFlowerView removeFromSuperview];
  3235. _liveUIViewController.liveView.goldFlowerView = nil;
  3236. }
  3237. else if(_liveUIViewController.liveView.guessSizeView)
  3238. {
  3239. [_liveUIViewController.liveView.guessSizeView disClockTime];
  3240. [_liveUIViewController.liveView.guessSizeView removeFromSuperview];
  3241. _liveUIViewController.liveView.guessSizeView = nil;
  3242. }
  3243. [_liveUIViewController.liveView relayoutFrameOfSubViews];
  3244. _liveUIViewController.liveView.bottomView.hidden = YES;
  3245. [_liveUIViewController.liveView.gameArray removeAllObjects];
  3246. [_liveUIViewController.liveView.gameDataArray removeAllObjects];
  3247. [_liveUIViewController.liveView.bankerDataArr removeAllObjects];
  3248. [_liveUIViewController.liveView.bankerListArr removeAllObjects];
  3249. // 如果是主播调用该方法获取到本局游戏的状态
  3250. if (_isHost || [_liveItem liveType] == FW_LIVE_TYPE_HOST)
  3251. {
  3252. [_liveUIViewController.liveView loadGameData];
  3253. }
  3254. }
  3255. else
  3256. {
  3257. // 如果前后台切换时直播间不存在游戏
  3258. _liveUIViewController.liveView.shouldReloadGame = NO;
  3259. }
  3260. // 如果是观众
  3261. if (!_isHost)
  3262. {
  3263. [self getVideo:^(CurrentLiveInfo *liveInfo) {
  3264. } roomID:_roomIDStr failed:^(int errId, NSString *errMsg) {
  3265. }];
  3266. }
  3267. }
  3268. - (void)exchangeCoin:(NSString *)diamond
  3269. {
  3270. ConverDiamondsViewController *ConverDiamondsVC =[[ConverDiamondsViewController alloc]init];
  3271. ConverDiamondsVC.whetherGame = YES;
  3272. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  3273. {
  3274. ConverDiamondsVC.modalPresentationStyle=UIModalPresentationOverCurrentContext;
  3275. }
  3276. else
  3277. {
  3278. self.modalPresentationStyle=UIModalPresentationCurrentContext;
  3279. }
  3280. [self presentViewController:ConverDiamondsVC animated:YES completion:nil];
  3281. }
  3282. #pragma mark - ----------------------- 充值兑换界面相关 -----------------------
  3283. - (RechargeView *)rechargeView
  3284. {
  3285. if (_rechargeView == nil)
  3286. {
  3287. _rechargeView = [[RechargeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, kRechargeViewHeight) andUIViewController:self];
  3288. _rechargeView.hidden = YES;
  3289. _rechargeView.delegate = self;
  3290. [self.view addSubview:_rechargeView];
  3291. }
  3292. return _rechargeView;
  3293. }
  3294. - (OtherChangeView *)otherChangeView
  3295. {
  3296. if (_otherChangeView == nil)
  3297. {
  3298. _otherChangeView = [[OtherChangeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, 300) andUIViewController:self];
  3299. _otherChangeView.hidden = YES;
  3300. _otherChangeView.delegate = self;
  3301. [self.view addSubview:_otherChangeView];
  3302. }
  3303. return _otherChangeView;
  3304. }
  3305. - (ExchangeView *)exchangeView
  3306. {
  3307. if (_exchangeView == nil)
  3308. {
  3309. _exchangeView = [[ExchangeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, 260)];
  3310. _exchangeView.hidden = YES;
  3311. _exchangeView.delegate = self;
  3312. [self.view addSubview:_exchangeView];
  3313. }
  3314. return _exchangeView;
  3315. }
  3316. - (void)choseRecharge:(BOOL)recharge orExchange:(BOOL)exchange
  3317. {
  3318. [self.liveUIViewController.liveView closeGitfView];
  3319. FWWeakify(self)
  3320. if (recharge)
  3321. {
  3322. self.rechargeView.hidden = NO;
  3323. [UIView animateWithDuration:0.5 animations:^{
  3324. FWStrongify(self)
  3325. self.rechargeView.transform = CGAffineTransformMakeTranslation(0, (kScreenH-kRechargeViewHeight)/2-kScreenH);
  3326. // self.rechargeView.frame = CGRectMake(10, (kScreenH-kRechargeViewHeight)/2, kScreenW-20, kRechargeViewHeight);
  3327. } completion:^(BOOL finished) {
  3328. }];
  3329. }
  3330. else if(exchange)
  3331. {
  3332. self.exchangeView.hidden = NO;
  3333. self.exchangeView.model = self.rechargeView.model;
  3334. [UIView animateWithDuration:0.5 animations:^{
  3335. FWStrongify(self)
  3336. //self.exchangeView.frame = CGRectMake(10, kScreenH-230-kNumberBoardHeight, kScreenW-20, 230);
  3337. self.exchangeView.transform = CGAffineTransformMakeTranslation(0, -260-kNumberBoardHeight);
  3338. } completion:^(BOOL finished) {
  3339. }];
  3340. }
  3341. }
  3342. - (void)choseOtherRechargeWithRechargeView:(RechargeView *)rechargeView
  3343. {
  3344. self.otherChangeView.hidden = NO;
  3345. self.otherChangeView.selectIndex = rechargeView.indexPayWay;
  3346. self.otherChangeView.model = rechargeView.model;
  3347. self.otherChangeView.otherPayArr = rechargeView.model.pay_list;
  3348. [self.liveUIViewController.liveView closeGitfView];
  3349. FWWeakify(self)
  3350. [UIView animateWithDuration:0.5 animations:^{
  3351. FWStrongify(self)
  3352. //self.otherChangeView.frame = CGRectMake(10, kScreenH-260-kNumberBoardHeight, kScreenW-20, 260);
  3353. self.otherChangeView.transform = CGAffineTransformMakeTranslation(0, -300-kNumberBoardHeight);
  3354. } completion:^(BOOL finished) {
  3355. }];
  3356. }
  3357. #pragma mark 点击其它支付的确定按钮
  3358. - (void)clickOtherRechergeWithView:(OtherChangeView *)otherView
  3359. {
  3360. PayMoneyModel * model = [[PayMoneyModel alloc] init];
  3361. model.hasOtherPay = YES;
  3362. self.rechargeView.money = otherView.textField.text;
  3363. [self.rechargeView payRequestWithModel:model withPayWayIndex:otherView.selectIndex];
  3364. }
  3365. #pragma mark 点击其它支付的兑换按钮
  3366. - (void)clickExchangeWithView:(OtherChangeView *)otherView
  3367. {
  3368. [self choseRecharge:NO orExchange:YES];
  3369. }
  3370. #pragma mark 充值成功后调用
  3371. - (void)rechargeSuccessWithRechargeView:(RechargeView *)rechargeView
  3372. {
  3373. if (self.liveUIViewController.livePay)//通过这个判断充钱后是否可以看看付费直播的视频
  3374. {
  3375. if (self.liveUIViewController.livePay.isEnterPayLive == 1)
  3376. {
  3377. [self.liveUIViewController.livePay enterMoneyMode];
  3378. }
  3379. }
  3380. FWWeakify(self)
  3381. [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  3382. FWStrongify(self)
  3383. self.liveUIViewController.liveView.currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  3384. // 更新游戏余额
  3385. if (self.liveUIViewController.liveView.goldFlowerView)
  3386. {
  3387. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  3388. {
  3389. self.liveUIViewController.liveView.goldFlowerView.coinView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",[[IMAPlatform sharedInstance].host getDiamonds]];
  3390. self.liveUIViewController.liveView.guessSizeView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",[[IMAPlatform sharedInstance].host getDiamonds]];
  3391. }
  3392. else
  3393. {
  3394. self.liveUIViewController.liveView.goldFlowerView.coinView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",[[IMAPlatform sharedInstance].host getUserCoin]];
  3395. self.liveUIViewController.liveView.guessSizeView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",[[IMAPlatform sharedInstance].host getUserCoin]];
  3396. }
  3397. }
  3398. [self.liveUIViewController.liveView.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",[[IMAPlatform sharedInstance].host getDiamonds]]];
  3399. self.rechargeView.model.diamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  3400. if (self.otherChangeView.hidden == NO)
  3401. {
  3402. [self.otherChangeView disChangeText];
  3403. }
  3404. }];
  3405. }
  3406. - (void)closeRechargeView:(TCShowLiveView *)showLiveView
  3407. {
  3408. [self.view endEditing:YES];
  3409. if (self.rechargeView.hidden == NO)
  3410. {
  3411. FWWeakify(self)
  3412. [UIView animateWithDuration:0.5 animations:^{
  3413. FWStrongify(self)
  3414. //self.rechargeView.frame = CGRectMake(10, kScreenH, kScreenW-20, kRechargeViewHeight);
  3415. self.rechargeView.transform = CGAffineTransformIdentity;
  3416. } completion:^(BOOL finished) {
  3417. FWStrongify(self)
  3418. self.exchangeView.hidden = YES;
  3419. }];
  3420. }
  3421. if (self.exchangeView.hidden == NO)
  3422. {
  3423. [self.exchangeView cancleExchange];
  3424. }
  3425. if (self.otherChangeView.hidden == NO)
  3426. {
  3427. [self.otherChangeView disChangeText];
  3428. }
  3429. }
  3430. #pragma mark - ----------------------- CY座驾进入动画 -----------------------
  3431. #pragma mark 判断是否播放高级别用户进入动画
  3432. - (void)CarAnimate:(UserModel *)userModel
  3433. {
  3434. //if (userModel.has_car > 0)
  3435. if (userModel.noble_car_url.length > 0 && ![BGUtils isBlankString:userModel.noble_car_url])
  3436. {
  3437. [_aCYCarViewwArray addObject:userModel];
  3438. if ([_aCYCarViewwArray count] == 1 && !_aCYCarViewwShowing)
  3439. {
  3440. [self playCarViewAnimate:userModel];
  3441. }
  3442. }
  3443. }
  3444. -(void)CarAnimationHiddenPlayerDelegate
  3445. {
  3446. [self finishCarViewAnimate];
  3447. }
  3448. #pragma mark 播放高级别观众进入的动画
  3449. - (void)playCarViewAnimate:(UserModel *) userModel
  3450. {
  3451. _aCYCarViewwShowing = YES;
  3452. [_aCYCarView setContent:userModel];
  3453. // _aCYCarView.backgroundColor = randomColor;
  3454. _aCYCarView.hidden = NO;
  3455. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  3456. // [self performSelector:@selector(finishCarViewAnimate) withObject:nil afterDelay:3.5];
  3457. // });
  3458. // [UIView animateWithDuration:1.2 animations:^{
  3459. // _aETView.frame = CGRectMake(0,kCYCarViewY, kCYCarViewWidth, kCYCarViewHeight);
  3460. // } completion:^(BOOL finished) {
  3461. // }];
  3462. }
  3463. #pragma mark 结束高级用户进入动画
  3464. - (void)finishCarViewAnimate
  3465. {
  3466. _aCYCarView.hidden = YES;
  3467. _aCYCarViewwShowing = NO;
  3468. [_aCYCarViewwArray removeObjectAtIndex:0];
  3469. if ([_aCYCarViewwArray count])
  3470. {
  3471. UserModel *userModel = [_aCYCarViewwArray firstObject];
  3472. [self playCarViewAnimate:userModel];
  3473. }
  3474. }
  3475. - (WardTipView *)tipView{
  3476. if (!_tipView) {
  3477. _tipView = [[WardTipView alloc]initWithFrame:CGRectMake(0, 0, kScreenW / 2, 1)];
  3478. }
  3479. return _tipView;
  3480. }
  3481. - (void)hideTipView{
  3482. [self.tipView hide];
  3483. }
  3484. - (void)didReceiveMemoryWarning{
  3485. [super didReceiveMemoryWarning];
  3486. }
  3487. - (void)protocolDidScrollView:(BGTLiveScrollView *)scrollView isRefreshLive:(BOOL)isRefresh{
  3488. if (self.delegate && [self.delegate respondsToSelector:@selector(protocolDidScrollView:isRefreshLive:)]) {
  3489. [self.delegate protocolDidScrollView:scrollView isRefreshLive:isRefresh];
  3490. }
  3491. }
  3492. #pragma mark - BogoLiveCartPopViewDelegate
  3493. - (void)popView:(BogoLiveCartPopView *)popView didClickGood:(BogoCommodityDetailModel *)model{
  3494. // BogoCartModel *model = self.dataArray[indexPath.section];
  3495. if (model.model_id.integerValue == 1) {
  3496. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.link_url]];
  3497. }else{
  3498. BogoGoodDetailViewController *detailVC = [[BogoGoodDetailViewController alloc]init];
  3499. detailVC.gid = model.gid;
  3500. detailVC.distribution_id = model.distribution_uid;
  3501. // detailVC.uid = model.share_uid;
  3502. detailVC.source = BogoShopBuySourceLive;
  3503. [self.navigationController pushViewController:detailVC animated:YES];
  3504. }
  3505. }
  3506. - (void)popView:(BogoLiveCartPopView *)popView didClickAddBtn:(UIButton *)sender{
  3507. BogoLiveGoodAddViewController *addVC = [[BogoLiveGoodAddViewController alloc]init];
  3508. addVC.lid = self.currentLiveInfo.room_id;
  3509. BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:addVC];
  3510. [self presentViewController:nav animated:YES completion:nil];
  3511. popView.bottom = 0;
  3512. }
  3513. -(void)popView:(BogoLiveCartPopView *)popView didRemoveGood:(BogoCommodityDetailModel *)model{
  3514. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  3515. sendCustomMsgModel.msgType = MSG_SHOP_SAY_CANCLE_TYPE;
  3516. sendCustomMsgModel.msg = @"";
  3517. sendCustomMsgModel.chatGroupID = [_liveItem liveIMChatRoomId];
  3518. sendCustomMsgModel.shopModel = model;
  3519. [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  3520. }
  3521. - (void)popView:(BogoLiveCartPopView *)popView didClickSayBtn:(BogoCommodityDetailModel *)model{
  3522. if (!model.is_live) {
  3523. //取消讲解
  3524. [[BogoNetwork shareInstance] GET:@"api/inExplanation" param:@{@"token":[BogoNetwork shareInstance].token,@"lid":self.currentLiveInfo.room_id,@"gid":model.gid} success:^(BogoNetworkResponseModel * _Nonnull result) {
  3525. if (result.status.integerValue == 200) {
  3526. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  3527. sendCustomMsgModel.msgType = MSG_SHOP_SAY_TYPE;
  3528. sendCustomMsgModel.msg = @"";
  3529. sendCustomMsgModel.chatGroupID = [_liveItem liveIMChatRoomId];
  3530. sendCustomMsgModel.shopModel = model;
  3531. [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  3532. // [self.cartPopView hide];
  3533. }
  3534. } failure:^(NSString * _Nonnull error) {
  3535. [[FDHUDManager defaultManager] show:error ToView:[UIApplication sharedApplication].keyWindow];
  3536. }];
  3537. }else{
  3538. [[BogoNetwork shareInstance] GET:@"api/endExplanation" param:@{@"token":[BogoNetwork shareInstance].token,@"lid":self.currentLiveInfo.room_id,@"gid":model.gid} success:^(BogoNetworkResponseModel * _Nonnull result) {
  3539. if (result.status.integerValue == 200) {
  3540. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  3541. sendCustomMsgModel.msgType = MSG_SHOP_SAY_CANCLE_TYPE;
  3542. sendCustomMsgModel.msg = @"";
  3543. sendCustomMsgModel.chatGroupID = [_liveItem liveIMChatRoomId];
  3544. sendCustomMsgModel.shopModel = model;
  3545. [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  3546. }
  3547. } failure:^(NSString * _Nonnull error) {
  3548. [[FDHUDManager defaultManager] show:error ToView:[UIApplication sharedApplication].keyWindow];
  3549. }];
  3550. }
  3551. }
  3552. - (BogoLiveCartPopView *)cartPopView{
  3553. if (!_cartPopView) {
  3554. _cartPopView = [kShopKitBundle loadNibNamed:@"BogoLiveCartPopView" owner:nil options:nil].lastObject;
  3555. _cartPopView.delegate = self;
  3556. }
  3557. return _cartPopView;
  3558. }
  3559. - (BogoRechargePopView *)rechargePopView{
  3560. if (!_rechargePopView) {
  3561. _rechargePopView = [[BogoRechargePopView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH - kRealValue(180))];
  3562. }
  3563. return _rechargePopView;
  3564. }
  3565. //发送表情
  3566. -(void)protocolDidClickEmoji:(NSString *)emoji
  3567. {
  3568. //判断我在没在麦位
  3569. BOOL isInMike = NO;
  3570. for(int i = 0;i < self.currentLiveInfo.wheat_type_list.count; i++)
  3571. {
  3572. Wheat_Type_List *model = self.currentLiveInfo.wheat_type_list[i];
  3573. if(model.even_wheat.user_id == [IMAPlatform sharedInstance].host.userId.intValue)
  3574. {
  3575. isInMike = YES;
  3576. break;
  3577. }
  3578. }
  3579. if(isInMike)
  3580. {
  3581. NSLog(@"发送表情 %@",emoji);
  3582. SendCustomMsgModel *scmm = [[SendCustomMsgModel alloc] init];
  3583. scmm.msgType = MSG_SEND_EMOTION;
  3584. scmm.faceUrl = emoji;
  3585. scmm.chatGroupID = [_liveItem liveIMChatRoomId];
  3586. [[BGIMMsgHandler sharedInstance] sendCustomGroupMsg:scmm succ:nil fail:nil];
  3587. }
  3588. else
  3589. {
  3590. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"上麦后才能发送表情")];
  3591. }
  3592. }
  3593. @end