12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062 |
- //
- // ViewController.m
- // VideoTest
- //
- // Created by APPLE on 2019/5/29.
- // Copyright © 2019 APPLE. All rights reserved.
- //
- #import "PlayerViewController.h"
- #import "PlayerViewController+TouchPointXD.h"
- #import "PlayerViewController+AdjustBtnFrame.h"
- #import "AFNetworkReachabilityManager.h"
- #import <AVFoundation/AVFoundation.h>
- #import <ifaddrs.h>
- #import <arpa/inet.h>
- #import <SystemConfiguration/CaptiveNetwork.h>
- #import <SDWebImage.h>
- #import "FLAnimatedImage.h"
- #import "VclCrash.h"
- #import "HWBuryPointModel.h"
- #import "BuryPoint.h"
- #import<objc/runtime.h>
- #import "CloudPhoneModel.h"
- #import "BGTool.h"
- #import "AppDelegate.h"
- #import <RCCloudPhoneSDK/RCAudioPlayer.h>
- #import <RCCloudPhoneSDK/RCRecordManager.h>
- //#import <RCCloudPhoneSDK/RCCommandChannel.h>
- #import <RCCloudPhoneSDK/RCLiveSteamManager.h>
- #import "ShortcutManager.h"
- #import "PhoneP2PModel.h"
- #import "PlayerViewController+RBD.h"
- #import "P2PDataManager.h"
- #import "UseAccountManage.h"
- #import "RCCommandHelp.h"
- #import "UIView+View.h"
- #import "SafeForKey.h"
- #import "CloudPhoneAPI.h"
- #import "P2PDataManager.h"
- #import "MySetViewController.h"
- typedef enum : NSUInteger {
- BITRATE_EXTREME_SPEED = 2,//极速
- // BITRATE_HIGH_SPEED = 843000,//高速
- BITRATE_AUTO = 6,//自动
- // BITRATE_STANDARD_CLEARING = 2,//wwan标清
- // BITRATE_HD = 3,//wwan高清
- BITRATE_WIFI_STANDARD_CLEARING = 3, //wifi标清
- BITRATE_WIFI_HD = 4, //wifi高清
- } BITRATE_TYPE;
- //当手机采用wifi时不做码率调整,当手机采用流量时,高清采用2052000,标清采用1652000调整(默认)
- ///*测试*/
- //#include "socket.h"
- PlayerViewController * _Nullable mySelf;
- BOOL isLan;
- //PlayerViewController *mySelf;
- int portConnect;
- NSString *ipConnect;
- @interface PlayerViewController ()
- <PlayerViewDelegate,
- RecoderManagerDelegate,
- AudioRecoderMamagerDelegate,
- RCLiveSteamManagerDelegate,
- UITextFieldDelegate>
- {
- // __block int _ihandle;
-
- int rate;/*0:极速 1:高速 2:高清 3:标清 4:d自动*/
- NSUInteger rateForAuto;
-
-
- BOOL showWattingViewImageView;
-
- RCPCMPlayer *pcmPlayer;
-
- NSInteger gpsOnOff;
-
- BOOL canRate;
-
- CIContext *videoContext;
-
- NSInteger reConnectAccount;/*记录重连次数*/
-
- BOOL isInPan;/*标记是否有手指在活动*/
-
- int socketFortest;
-
- UIView *loadingWithTipsView;
-
- NSInteger netWorkStates;/*0很差 1较差 2流畅*/
-
-
- BOOL outputVolumeKVO;/*标记声音监听通知*/
-
- NSDate *rootSetTime;
-
- UITextField *hidenTextField;
- NSString *hidenTextFieldOldStr;
- }
- @property (nonatomic, strong, nullable) RCVideoRecoderManager *recoderManager;
- @property (nonatomic, strong, nullable) RCAudioRecoderMamager *audioRecoderMamager;
- @property (nonatomic, strong) RCLiveSteamManager *liveStreamManager;
- //@property (nonatomic, strong) RCCommandChannelManager *commandChannelManager;//指令通道
- //@property (nonatomic, strong) RCCommandChannelManager *businessCommandChannelManager;//业务通道
- //需不需要显示音量条
- @property (nonatomic, assign) BOOL isNeedShowVoiceBar;
- //切换云手机 保存切换过的云手机数组, 返回的时刷新对应的云机websorket封面
- @property (nonatomic, strong) NSMutableArray *switchCloudPhoneArray;
- @property (nonatomic, copy) NSString *screenShotFileName;
- @property (nonatomic, copy) NSTimer *timer; // 定时器-控制按钮
- /**30s后 渲染时间戳无更新 自动断开链接*/
- @property (nonatomic, assign) NSInteger concentTime; // 拉流数据 渲染更新时间戳
- /**定时器计数*/
- @property (nonatomic, assign) NSInteger currentTime;
- /**是否是收入进入云手机*/
- @property (nonatomic, assign) BOOL isFirstEnterPhone;
- @end
- @implementation PlayerViewController
- @synthesize internetVideoPort;
- @synthesize ip;
- @synthesize canControl;
- @synthesize phoneIndex;
- @synthesize deviceId;
- @synthesize vpnStatus;
- @synthesize internetHttp;
- @synthesize deviceModel;
- @synthesize chaofenDeviceModel;
- @synthesize rbdNotification;
- - (void)viewDidLoad {
-
- [super viewDidLoad];
- if (@available(iOS 11.0, *)) { // 兼容低版本ios
- [self setNeedsUpdateOfHomeIndicatorAutoHidden];
- }
- /*请求设备列表*/
- [[UseAccountManage shareInstance] CommonGetWithCallBackCode:LoadDeviceAPI Parameters:[NSMutableDictionary new] success:^(id _Nonnull responseObject) {
- CloduPhoneListDataModel *model = [[CloduPhoneListDataModel alloc] initWithDictionary:responseObject error:nil];
- KyoLog(@"\n----modelstatus-%@---",model.status);
- if (model.status.integerValue == 0)
- {
- [UseAccountManage shareInstance].cloudPhoneListModel = model.data;
- if ([UseAccountManage shareInstance].cloudPhoneListModel.diskInfo.count > 0){
- /*提取第一个设备*/
- self->deviceModel = [UseAccountManage shareInstance].cloudPhoneListModel.diskInfo.firstObject;
- /*先判断本地有无缓存,无缓存时进行超分,有缓存直接进行链接*/
- PhoneP2PModel *p2pModel = [[P2PDataManager shareInstance] findRecoderWithPhoneID:self->deviceModel.phoneId];
- if (p2pModel) {
- if (p2pModel.ctime + 24*3600 > [[NSDate date] timeIntervalSince1970]) {/*在有效时间内*/
- /*替换相关参数并且进入云手机*/
- self->deviceModel.sn = p2pModel.sn;
- self->deviceModel.internetVideoPort = p2pModel.internetVideoPort;
- self->deviceModel.internetBusinessPort = p2pModel.internetBusinessPort;
- self->deviceModel.internetIp = p2pModel.internetIp;
- self->deviceModel.roomInternetIp = p2pModel.roomInternetIp;
- self->deviceModel.vpnStatus = p2pModel.vpnStatus;
- self->deviceModel.videoCode = p2pModel.videoCode;
- self->deviceModel.deviceBoard = p2pModel.deviceBoard;
- self->deviceModel.internetHttps = p2pModel.internetHttps;
- self->deviceModel.internetHttp = p2pModel.internetHttp;
- self->deviceModel.localIp = p2pModel.localIp;
- self->deviceModel.cardToken = p2pModel.cardToken;
- self->deviceModel.pushFlowCode = p2pModel.pushFlowCode;
- self->deviceModel.resolvingPower = p2pModel.resolvingPower;
- self->deviceModel.width = p2pModel.width;
- self->deviceModel.high = p2pModel.high;
- self->deviceModel.dpi = p2pModel.dpi;
- self->deviceModel.vpnMode = p2pModel.vpnMode;
-
- self.phoneIndex = 0;
- /*传入IP与port*/
- self.ip = self->deviceModel.internetIp;
- self.internetVideoPort = self->deviceModel.internetVideoPort;
- self.deviceId = [NSString stringWithFormat:@"%ld",(long)self->deviceModel.phoneId];
-
- self.canControl = YES;
- self.buyVipType = self->deviceModel.buyVipType;
- self.internetHttp = self->deviceModel.internetHttp;
-
- HLog(@"__________连接000000__________deviceModel.cardToken = %@ 旧",self->deviceModel.cardToken);
- if (self->deviceModel){
- if (self.isNeedRecyclResource) {
- self.liveStreamManager = [[RCLiveSteamManager alloc] init];
- self.liveStreamManager.delegate = self;
-
- [self opencommandChannelManagerrc_openURL];
- [self openbusinessCommandChannelManagerrc_openURL];
- portConnect = [self->internetVideoPort intValue];
- ipConnect = self->ip;
-
- isLan = NO;
-
- globalBlock(^{
- // 初始化成功后连接
- @synchronized (self) {
- if ([self initVideoServer])
- {
- [self connectVideoServer];
- }
- }
- });
- [self addNSNotification];
- }
-
- self.isNeedRecyclResource = YES;
- }
- }
- }else{
- /*主动超分*/
- [self extensionPhoneGetRBD];
- }
-
- /*初始化数据*/
- if (self.deviceModel.width > 200 && self.deviceModel.high > 200) {
- ksharedAppDelegate.couldPhone_W_PHONE = self.deviceModel.width;
- ksharedAppDelegate.couldPhone_H_PHONE = self.deviceModel.high;
- }else{
- if ([self.deviceModel.resolvingPower isEqualToString:@"720"]) {
- ksharedAppDelegate.couldPhone_W_PHONE = 720;
- ksharedAppDelegate.couldPhone_H_PHONE = 1280;
- }else{
- ksharedAppDelegate.couldPhone_W_PHONE = 1080;
- ksharedAppDelegate.couldPhone_H_PHONE = 1920;
- }
- }
-
-
- }
- }
- else
- {
- ;
- }
- } failure:^(NSError * _Nonnull error) {
- HLog(@"%@", error);
- }];
-
- outputVolumeKVO = NO;
-
- rbdNotification = 0;
-
- // 初始化
- self.isNeedRecyclResource = YES;
- self.isFirstEnterPhone = YES;
- [self initData];
-
- self.toolBar.hidden = YES;
- self.navigationBar.hidden = YES;
-
- [self drawView];
-
- [self showNewIndicator];
-
- mySelf = self;
- haveBack = NO;
- }
- - (void)initData
- {
- isInPan = NO;
- reConnectAccount = 0;
- netWorkStates = 0;
-
- canRate = NO;
- rate = -1;
- isLan = NO;
-
- // _ihandle = -1;
- [hidenTextField resignFirstResponder];
- hidenTextField.text = @"";
- hidenTextFieldOldStr = nil;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- // 屏幕常亮
- [UIApplication sharedApplication].idleTimerDisabled = YES;
- [[UIApplication sharedApplication] setStatusBarHidden:YES];
-
- [self setTimerCountDown];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
-
- if (mPlayerView.controlBtn) {
- [self.navigationController.view bringSubviewToFront:mPlayerView.controlBtn];
- }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- // 退出控制器 回收资源
- [self recyclResource];
- AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // app.allowAutoRotate = NO;
- [super viewWillDisappear:animated];
- }
-
- // 退出控制器 回收资源
- - (void)recyclResource {
-
- // 移除Alert
- if (self.presentedViewController) {
- [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
- }
- [mPlayerView.controlBtn removeFromSuperview];
- if ([[[UIApplication sharedApplication] keyWindow] viewWithTag:1235]) {
- [[[[UIApplication sharedApplication] keyWindow] viewWithTag:1235] removeFromSuperview];
- }
-
- // 销毁定时器
- [self cancelTimer];
-
- [self enablePanRightBack];
-
- // 播放器内部页面跳转-不能回收的资源
- if (self.isNeedRecyclResource) {
- // 屏幕常亮
- [UIApplication sharedApplication].idleTimerDisabled = NO;
- [[UIApplication sharedApplication] setStatusBarHidden:NO];
-
- if (USEAAC)
- {
- if (aacPlayer)
- {
- [aacPlayer stop];
-
- aacPlayer = nil;
- }
- }
- else
- {
- if (pcmPlayer)
- {
- [pcmPlayer stop];
- pcmPlayer = nil;
- }
- }
-
- [self toStopRecoder];
- [self toStopAudioRecoder];
- [self removeNSNotification];
-
- CloudPhoneModel *deviceDcit = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:phoneIndex];
-
- //清空WebSocket连接
- [self.commandChannelManager rc_close];
- [self.businessCommandChannelManager rc_close];
-
- globalBlock(^{
- [self.liveStreamManager rc_release];
- });
- }
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // app.allowAutoRotate = YES;
-
- [[UIApplication sharedApplication] setStatusBarHidden:YES];
- [self noEnablePanRightBack];
-
- [self.navigationController.view addSubview:mPlayerView.controlBtn];
- [self.navigationController.view bringSubviewToFront:mPlayerView.controlBtn];
-
- if (deviceModel){
- if (self.isNeedRecyclResource) {
- self.liveStreamManager = [[RCLiveSteamManager alloc] init];
- self.liveStreamManager.delegate = self;
-
- [self opencommandChannelManagerrc_openURL];
- [self openbusinessCommandChannelManagerrc_openURL];
- portConnect = [internetVideoPort intValue];
- ipConnect = ip;
-
- isLan = NO;
-
- globalBlock(^{
- // 初始化成功后连接
- @synchronized (self) {
- if ([self initVideoServer])
- {
- [self connectVideoServer];
- }
- }
- });
- [self addNSNotification];
- }
-
- self.isNeedRecyclResource = YES;
- }
- }
- - (void)opencommandChannelManagerrc_openURL
- {
- KWeakSelf
- //初始化指令通道
- self.commandChannelManager = [[RCCommandChannelManager alloc] init];
- NSString *instructionsChannelUrl = [[UseAccountManage shareInstance] getInstructionsChannelUrlWithInternetHttp:deviceModel.internetHttp localIp:deviceModel.localIp cardToken:deviceModel.cardToken];
- if (deviceModel.internetHttp && deviceModel.localIp && deviceModel.cardToken && instructionsChannelUrl) { //当都有值才可连接
- HLog(@"WebSocket11111指令通道连接开始11111 url = %@ ",instructionsChannelUrl);
- [self.commandChannelManager rc_openURL:instructionsChannelUrl connected:^{
- HLog(@"WebSocket11111指令通道连接成功11111 url = %@ ",instructionsChannelUrl);
- if (self.commandChannelManager.rc_socketStatus == RCSocketCloudPhoneStatusConnected){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- // /*获取自己的用户名(电话号码)*/
- // NSString *selfUseName = nil;
- // NSDictionary *dict111 = [[UseAccountManage shareInstance] getLoginInfo];
- // if ([[dict111 allKeys] containsObject:@"userName"]) {
- // selfUseName = [dict111 valueForKey:@"userName"];
- // /*查询是否有设备在远程控制*/
- // [self.commandChannelManager rc_sendData:[RCCommandHelp askControllcommandWithUseName:selfUseName]];
- // }
-
- /*开启输入法透传*/
- NSString *dataStr = [RCCommandHelp commandOpenLoaclKeyboad];
- [self.commandChannelManager rc_sendData:dataStr];
- });
- }
- } receive:^(id message, FLSocketCloudPhoneReceiveType type) {
- HLog(@"webSocket指令通道接收消息:------------------\n%@",message);
- if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
- {
- message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
- }
-
- NSError *error = nil;
- NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
- NSString *messageType = dataDict[@"type"];
-
- if ([messageType isEqualToString:@"cutting"]) {
- [[iToast makeText:@"复制成功"] show];
- }
- else if ([messageType isEqualToString:@"forwardMsg"]){/*转发*/
- /*获取指令类型*/
- NSString *code = nil;
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"code"]) {
- code = [data objectForKey:@"code"];
-
- if (![code isKindOfClass:[NSString class]]) {
- code = [NSString stringWithFormat:@"%ld",[code integerValue]];
- }
- }
- }
-
- /*获取用户名*/
- NSString *useName = nil;
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"userName"]) {
- useName = [data objectForKey:@"userName"];
- }
- }
-
- /*获取自己的用户名(电话号码)*/
- NSString *selfUseName = nil;
- NSDictionary *dict111 = [[UseAccountManage shareInstance] getLoginInfo];
- if ([[dict111 allKeys] containsObject:@"userName"]) {
- selfUseName = [dict111 valueForKey:@"userName"];
- }else{
- return;
- }
-
- /*无控制权提示*/
- //- (void)tipsNoDeviceContrWithPhoneIndex:(NSInteger)phoneIndex
- /*提醒拿回控制权*/
- //- (void)tipsGetBackDeviceContrWithPhoneIndex:(NSInteger)phoneIndex
- /*提醒控制权被拿回*/
- //- (void)tipsMainUserGetDeviceAuthBack
-
- // if ([code isEqualToString:@"3000"]) {/*有人询问控制权情况*/
- // if (self->deviceModel.authPhone==0 && self->deviceModel.phoneAuthStatus == 0){
- // return;/*自己的云手机且未授权直接返回*/
- // }
- //
- // if (![useName isEqualToString:selfUseName]){
- // /*根据实际情况进行相关回复*/
- // [self.commandChannelManager rc_sendData:[RCCommandHelp faceBackControllcommandWithUseName:selfUseName haveControl:self->canControl]];
- // }
- // }else if ([code isEqualToString:@"4000"]){/*有在控制*/
- // if (self->deviceModel.authPhone==0 && self->deviceModel.phoneAuthStatus == 0){
- // return;/*自己的云手机且未授权直接返回*/
- // }
- //
- // if (self->deviceModel.authPhone==0) {/*是自己的设备时候要询问是否夺回控制权*/
- // if (![useName isEqualToString:selfUseName]) {
- // /*弹窗询问是否夺回控制权*/
- // [self tipsGetBackDeviceContrWithPhoneIndex:self->deviceModel];
- // }
- // }else if (![useName isEqualToString:selfUseName]) {
- // if (self->canControl == YES) {
- // [self tipsNoDeviceContrWithPhoneIndex:self->deviceModel];
- // }
- // self->canControl = NO;
- // if (!self->canControl&&self->controlView){
- // [self->controlView diasbleControltPhoneView];
- // }else if (self->controlView){
- // [self->controlView enableControltPhoneView];
- // }
- // }
- // }else if ([code isEqualToString:@"4100"]){/*未控制*/
- // /*不用处理默认可以控制*/
- // }else if ([code isEqualToString:@"5000"]){/*夺回控制权*/
- // if (self->deviceModel.authPhone==0 && self->deviceModel.phoneAuthStatus == 0){
- // return;/*自己的云手机且未授权直接返回*/
- // }
- //
- // if ([useName isEqualToString:selfUseName]){
- // return;
- // }
- //
- // if (self->deviceModel.authPhone!=0) {/*不是自己的设备时候要进行关闭控制权*/
- // if (self->canControl == YES) {
- // /*弹窗提示控制权已经被夺回*/
- // [self tipsMainUserGetDeviceAuthBack];
- // }
- // self->canControl = NO;
- // if (!self->canControl&&self->controlView){
- // [self->controlView diasbleControltPhoneView];
- // }else if (self->controlView){
- // [self->controlView enableControltPhoneView];
- // }
- // }
- // }else
- if ([code isEqualToString:@"phoneSizeChange"]){/*分辨率改变*/
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"width"]) {
- self->deviceModel.width = [[data objectForKey:@"width"] integerValue];
- ksharedAppDelegate.couldPhone_W_PHONE = self->deviceModel.width;
- }
- if ([[data allKeys] containsObject:@"dpi"]) {
- self->deviceModel.dpi = [[data objectForKey:@"dpi"] integerValue];
- }
- if ([[data allKeys] containsObject:@"height"]) {
- self->deviceModel.high = [[data objectForKey:@"height"] integerValue];
- ksharedAppDelegate.couldPhone_H_PHONE = self->deviceModel.high;
- }
-
- if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
- CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
- ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
- ksharedAppDelegate.couldPhone_H_PHONE = temp;
- }
- if (self->deviceModel.width > self->deviceModel.high) {
- CGFloat temp = self->deviceModel.width;
- self->deviceModel.width = self->deviceModel.high;
- self->deviceModel.high = temp;
- }
- /*更新点对点数据*/
- PhoneP2PModel *p2pModel = [[P2PDataManager shareInstance] findRecoderWithPhoneID:self->deviceModel.phoneId];
- p2pModel.width = self->deviceModel.width;
- p2pModel.high = self->deviceModel.high;
- p2pModel.dpi = self->deviceModel.dpi;
- [[P2PDataManager shareInstance] saveOrUpdateRecoderWithModel:p2pModel];
- }
- }
- }
- else if ([messageType isEqualToString:@"getPhoneSize"] || [messageType isEqualToString:@"setPhoneSize"]){
- NSString *sn = nil;
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"sn"]) {
- sn = [data objectForKey:@"sn"];
-
- if (![sn isEqualToString:self->deviceModel.sn]) {/*不是当前设备直接返回*/
- return;
- }
- }
-
- if ([[data allKeys] containsObject:@"status"]) {
- NSInteger status = [[data objectForKey:@"status"] integerValue];
-
- if (status == 0) {/*不是当前设备直接返回*/
- if ([[data allKeys] containsObject:@"width"]) {
- self->deviceModel.width = [[data objectForKey:@"width"] integerValue];
- ksharedAppDelegate.couldPhone_W_PHONE = self->deviceModel.width;
- }
- if ([[data allKeys] containsObject:@"dpi"]) {
- self->deviceModel.dpi = [[data objectForKey:@"dpi"] integerValue];
- }
- if ([[data allKeys] containsObject:@"height"]) {
- self->deviceModel.high = [[data objectForKey:@"height"] integerValue];
- ksharedAppDelegate.couldPhone_H_PHONE = self->deviceModel.high;
- }
-
- if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
- CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
- ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
- ksharedAppDelegate.couldPhone_H_PHONE = temp;
- }
- if (self->deviceModel.width > self->deviceModel.high) {
- CGFloat temp = self->deviceModel.width;
- self->deviceModel.width = self->deviceModel.high;
- self->deviceModel.high = temp;
- }
- /*更新点对点数据*/
- PhoneP2PModel *p2pModel = [[P2PDataManager shareInstance] findRecoderWithPhoneID:self->deviceModel.phoneId];
- p2pModel.width = self->deviceModel.width;
- p2pModel.high = self->deviceModel.high;
- p2pModel.dpi = self->deviceModel.dpi;
- [[P2PDataManager shareInstance] saveOrUpdateRecoderWithModel:p2pModel];
- }
- }
- }
-
-
- // {
- // "type":"getPhoneSize", --接口类型
- // "data":{
- // "sn":"RK_XXX", --安卓卡SN
- // "status":"0", --状态:0:成功 1:失败
- // "msg":"success", --请求状态:success 成功 failed 失败
- // "width":xxx,
- // "height":xxx,
- // "dpi":yyy --屏幕密度
- // }
- // }
- }
- else if ([messageType isEqualToString:@"sync_wifi"]){
- [self.commandChannelManager rc_sendData:[RCCommandHelp noSyncWifiBack]];
- [[iToast makeText:@"本机参数已同步完成,IOS无法同步wifi"] show];
- }
- else if ([messageType isEqualToString:@"reProduceText"]){
- NSString *sn = nil;
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"text"]) {
- NSString *pasteboardStr = [data objectForKey:@"text"];
- UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = pasteboardStr;
- }
- }
- }
- else if ([messageType isEqualToString:@"downAdnInstallRep"]){
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"status"]) {
- NSString *status = [data objectForKey:@"status"];
- if ([status isEqualToString:@"1"]) {
- mainBlock(^{
- [[iToast makeText:@"App下载完成"] show];
- });
- }else if ([status isEqualToString:@"0"]){
- mainBlock(^{
- [[iToast makeText:@"App下载中"] show];
- });
- }
- }
- }
- }
- else if ([messageType isEqualToString:@"shakeit"]){
- HLog(@"\n-----摇一摇成功------");
- }else if ([messageType isEqualToString:@"keyboardFeedbackBean"]){/*调起键盘*/
- [self->hidenTextField becomeFirstResponder];
- // [self->hidenTextField setText:@"1234"];
- [self->hidenTextField setEnabled:YES];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- }
- - (void)openbusinessCommandChannelManagerrc_openURL
- {
- KWeakSelf
- //初始化业务通道
- self.businessCommandChannelManager = [[RCCommandChannelManager alloc] init];
- NSString *businessChannelUrl = [[UseAccountManage shareInstance] getBusinessChannelUrlWithInternetHttp:deviceModel.internetHttp localIp:deviceModel.localIp cardToken:deviceModel.cardToken];
- if (deviceModel.internetHttp && deviceModel.localIp && deviceModel.cardToken && businessChannelUrl) { //当都有值才可连接
- [self.businessCommandChannelManager rc_openURL:businessChannelUrl connected:^{
- if (self.businessCommandChannelManager.rc_socketStatus == RCSocketCloudPhoneStatusConnected){
- // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // //连接成功,发送预览图指令
- // NSString *taskUid = [iTools getTaskUidStr];
- // NSString *dataStr = [RCCommandHelp commandGetScreenPicWithTaskUid:taskUid intervalTime:0];
- // [self.businessCommandChannelManager rc_sendData:dataStr];
- //
- // });
- }
- HLog(@"WebSocket11111业务通道连接成功11111 url = %@ ",businessChannelUrl);
- } receive:^(id message, FLSocketCloudPhoneReceiveType type) {
- HLog(@"webSocket业务通道接收消息:------------------\n%@",message);
- if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
- {
- message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
- }
-
- NSError *error = nil;
- NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
- NSString *messageType = dataDict[@"type"];
-
- if ([messageType isEqualToString:@"cutting"]) {
-
- }
- else if ([messageType isEqualToString:@"getPhoneSize"] || [messageType isEqualToString:@"setPhoneSize"]){
- NSString *sn = nil;
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"sn"]) {
- sn = [data objectForKey:@"sn"];
-
- if (![sn isEqualToString:self->deviceModel.sn]) {/*不是当前设备直接返回*/
- return;
- }
- }
-
- if ([[data allKeys] containsObject:@"status"]) {
- NSInteger status = [[data objectForKey:@"status"] integerValue];
-
- if (status == 0) {/*不是当前设备直接返回*/
- if ([[data allKeys] containsObject:@"width"]) {
- self->deviceModel.width = [[data objectForKey:@"width"] integerValue];
- ksharedAppDelegate.couldPhone_W_PHONE = self->deviceModel.width;
- }
- if ([[data allKeys] containsObject:@"dpi"]) {
- self->deviceModel.dpi = [[data objectForKey:@"dpi"] integerValue];
- }
- if ([[data allKeys] containsObject:@"height"]) {
- self->deviceModel.high = [[data objectForKey:@"height"] integerValue];
- ksharedAppDelegate.couldPhone_H_PHONE = self->deviceModel.high;
- }
-
- if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
- CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
- ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
- ksharedAppDelegate.couldPhone_H_PHONE = temp;
- }
- if (self->deviceModel.width > self->deviceModel.high) {
- CGFloat temp = self->deviceModel.width;
- self->deviceModel.width = self->deviceModel.high;
- self->deviceModel.high = temp;
- }
- /*更新点对点数据*/
- PhoneP2PModel *p2pModel = [[P2PDataManager shareInstance] findRecoderWithPhoneID:self->deviceModel.phoneId];
- p2pModel.width = self->deviceModel.width;
- p2pModel.high = self->deviceModel.high;
- p2pModel.dpi = self->deviceModel.dpi;
- [[P2PDataManager shareInstance] saveOrUpdateRecoderWithModel:p2pModel];
- }
- }
- }
-
-
- // {
- // "type":"getPhoneSize", --接口类型
- // "data":{
- // "sn":"RK_XXX", --安卓卡SN
- // "status":"0", --状态:0:成功 1:失败
- // "msg":"success", --请求状态:success 成功 failed 失败
- // "width":xxx,
- // "height":xxx,
- // "dpi":yyy --屏幕密度
- // }
- // }
- }
- else if ([messageType isEqualToString:@"VPNstatus"]){
- NSString *sn = nil;
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"sn"]) {
- sn = [data objectForKey:@"sn"];
-
- if (![sn isEqualToString:self->deviceModel.sn]) {/*不是当前设备直接返回*/
- return;
- }
- }
-
- if ([[data allKeys] containsObject:@"status"]) {
- NSInteger status = [[data objectForKey:@"status"] integerValue];
- if (self->deviceModel.vpnMode == 0) {
- if (status != self.vpnStatus) {
- self.vpnStatus = status;
- [self reconnectDevice];
- }
- }
- }
- }
- }
- else if ([messageType isEqualToString:@"reProduceText"]){
- NSString *sn = nil;
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"text"]) {
- NSString *pasteboardStr = [data objectForKey:@"text"];
- UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = pasteboardStr;
- }
- }
- }
- else if ([messageType isEqualToString:@"keyboardFeedbackBean"]){/*调起键盘*/
- // [self->hidenTextField setKeyboardType:(UIKeyboardTypeURL)];
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
- if ([[data allKeys] containsObject:@"type"]) {
- NSInteger keyboadType = [[data objectForKey:@"type"] integerValue];
- if (1 == keyboadType){
- [self->hidenTextField setKeyboardType:(UIKeyboardTypeTwitter)];
- }else if (2 == keyboadType){
- [self->hidenTextField setKeyboardType:(UIKeyboardTypeNumberPad)];
- }else if (3 == keyboadType){
- [self->hidenTextField setKeyboardType:(UIKeyboardTypePhonePad)];
- }else{
- [self->hidenTextField setKeyboardType:(UIKeyboardTypeURL)];
- }
- }
- }
-
- [self->hidenTextField becomeFirstResponder];
-
- [self->hidenTextField setText:@"1"];
- self->hidenTextFieldOldStr = @"1";
- }
- } failure:^(NSError *error) {
-
- }];
- }
- }
- - (void)textDidChange:(UITextField *)textField{
- if (textField.markedTextRange == nil) {
- /*新内容 完全包含前面的内容 就是删除*/
- NSRange newInOld = [hidenTextFieldOldStr rangeOfString:textField.text];
- if (newInOld.location == 0 && newInOld.length == textField.text.length){/*删除*/
- NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
- [self.businessCommandChannelManager rc_sendData:dataStr];
- /*删除以后在输入框前面新增一个字符*/
- NSString *tempStr = textField.text;
- if (tempStr.length > 0){
- }else{
- tempStr = @" ";
- }
- textField.text = tempStr;
- }else{
- /*新增*/
- NSRange oldInNew = [textField.text rangeOfString:hidenTextFieldOldStr];
- if (oldInNew.location == 0 && oldInNew.length == hidenTextFieldOldStr.length){/*新增*/
- NSString *addStr = [textField.text substringWithRange:(NSMakeRange(hidenTextFieldOldStr.length, textField.text.length - hidenTextFieldOldStr.length))];
- NSLog(@"键盘透传--@@@@新增内容:%@",addStr);
- NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:addStr];
- [self.businessCommandChannelManager rc_sendData:dataStr];
- }else{/*部分覆盖*/
- /*覆盖分为两部分 1、覆盖的内容更长 2、覆盖的内容更短*/
- /*删除不同的部分 加上变化的部分*/
- /*后面不同内容的长度*/
- NSInteger sameLength = 0;
- if (hidenTextFieldOldStr.length < textField.text.length){
- sameLength = [self sameStrLengthSmallStr:hidenTextFieldOldStr longStr:textField.text];
- }else{
- sameLength = [self sameStrLengthSmallStr:textField.text longStr:hidenTextFieldOldStr];
- }
- /*需要删除的长度*/
- NSInteger needDeleteLength = hidenTextFieldOldStr.length - sameLength;
- for (NSInteger nFori = 0; nFori < needDeleteLength; nFori++) {
- NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
- [self.businessCommandChannelManager rc_sendData:dataStr];
- }
-
- /*需要增加的内容*/
- NSInteger needLength = textField.text.length - sameLength;
- NSString *addStr = [textField.text substringWithRange:(NSMakeRange(sameLength, needLength))];
- NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:addStr];
- [self.businessCommandChannelManager rc_sendData:dataStr];
- }
- }
- hidenTextFieldOldStr = textField.text;
- }
- }
- - (NSInteger)sameStrLengthSmallStr:(NSString *)litStr longStr:(NSString *)longStr{
- NSInteger samenumber = 0;
- for (NSInteger nFori = 1; nFori < litStr.length+1; nFori++) {
- NSString *temp0 = [litStr substringToIndex:nFori];
- NSString *temp1 = [longStr substringToIndex:nFori];
- if (![temp0 isEqualToString:temp1]){
- break;
- }
- samenumber++;
- }
-
- return samenumber;
- }
- #pragma mark - UI相关
- - (void)drawView
- {
- hidenTextField = [[UITextField alloc] initWithFrame:(CGRectMake(0, 0, 0, 0))];
- hidenTextField.delegate = self;
- [hidenTextField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
-
- [self.view addSubview:hidenTextField];
-
- [self.view setBackgroundColor:[UIColor whiteColor]];
- mPlayerView = [[PlayerView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
- mPlayerView.buyVipType = self.buyVipType;
- [mPlayerView initPoMas_makeWithImageRate:[deviceModel isOpenVirtualKey] isUsageMode:[deviceModel isOpenUsageMode]];
- [mPlayerView setBackgroundColor:[UIColor blackColor]];
- mPlayerView.delegate = self;
- mPlayerView.sn = self.deviceModel.sn;
-
- deviceShareStates = 2;
- CloudPhoneModel *deviceDcit = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:phoneIndex];
- /*判断是否已分享*/
- NSInteger screenShareStatus = deviceDcit.screenShareStatus;
-
- deviceShareStates = screenShareStatus;
-
- [self.view addSubview:mPlayerView];
-
- [mPlayerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.top.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- }];
-
- [self reSetPlayerViewFloatBtnFrame];
-
- if (isLan)/*直接g或者变为横屏*/
- {
- [mPlayerView setLanMas_makeWithImageRate:ksharedAppDelegate.couldPhone_W_PHONE/ksharedAppDelegate.couldPhone_H_PHONE isOpenVirtual:[deviceModel isOpenVirtualKey] isUsageMode:[deviceModel isOpenUsageMode]];
- }
- else
- {
- [mPlayerView setPoMas_makeWithImageRate:ksharedAppDelegate.couldPhone_W_PHONE/ksharedAppDelegate.couldPhone_H_PHONE isOpenVirtual:[deviceModel isOpenVirtualKey] isUsageMode:[deviceModel isOpenUsageMode]];
- }
- }
- /**
- * @brief 漂浮按钮位置初始化
- *
- *
- */
- - (void)reSetPlayerViewFloatBtnFrame
- {
- // [[[UIApplication sharedApplication] keyWindow] addSubview:mPlayerView.controlBtn];
- [self.navigationController.view addSubview:mPlayerView.controlBtn];
- [self.navigationController.view bringSubviewToFront:mPlayerView.controlBtn];
-
- NSDictionary *dict = [[UseAccountManage shareInstance] getDviceDriftInfoWithdeviceSN:deviceId];
-
- CGFloat h_w_controlBtn = 60.f;
- if (dict)
- {
- CGFloat pointx = [[dict objectForKey:@"pointx"] floatValue];
- CGFloat pointy = [[dict objectForKey:@"pointy"] floatValue];
-
- if (mPlayerView.width > mPlayerView.height){
- if (pointx < 30)
- {
- pointx = 30;
- }
- else if (pointx > mPlayerView.width - h_w_controlBtn - 10.f)
- {
- pointx = mPlayerView.width - h_w_controlBtn - 10.f;
- }
-
- if (pointy < 10)
- {
- pointy = 10;
- }
- else if (pointy > mPlayerView.height - h_w_controlBtn - 10.f)
- {
- pointy = mPlayerView.height - h_w_controlBtn - 10.f;
- }
- }else{
- if (pointx < 10)
- {
- pointx = 10;
- }
- else if (pointx > mPlayerView.width - h_w_controlBtn - 10.f)
- {
- pointx = mPlayerView.width - h_w_controlBtn - 10.f;
- }
-
- if (pointy < 10)
- {
- pointy = 10;
- }
- else if (pointy > mPlayerView.height - h_w_controlBtn - 10.f)
- {
- pointy = mPlayerView.height - h_w_controlBtn - 10.f;
- }
- }
-
- // BOOL hidden = [[dict objectForKey:@"hidden"] boolValue];
-
- [mPlayerView.controlBtn setFrame:CGRectMake(pointx, pointy, h_w_controlBtn, h_w_controlBtn)];
- }
- else
- {
- /*区分横竖屏*/
- if (mPlayerView.width > mPlayerView.height){
- [mPlayerView.controlBtn setFrame:CGRectMake((mPlayerView.width - h_w_controlBtn)/2.f, mPlayerView.height - h_w_controlBtn - 20.f, h_w_controlBtn, h_w_controlBtn)];
- }else{
- [mPlayerView.controlBtn setFrame:CGRectMake(mPlayerView.width - h_w_controlBtn - 20.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
- }
-
- [mPlayerView.controlBtn setHidden:NO];
- }
-
- HLog(@"云手机推流界面 控制按钮中点%@",NSStringFromCGPoint(mPlayerView.controlBtn.center));
- }
- #pragma mark - 手势权限控制处理
- - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer
- *)gestureRecognizer{
- return NO; //YES:允许右滑返回 NO:禁止右滑返回
- }
- - (void)enablePanRightBack
- {
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
-
- if ([self.tabBarController.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.tabBarController.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
- }
- - (void)noEnablePanRightBack
- {
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.navigationController.interactivePopGestureRecognizer.enabled = NO;
- }
-
- if ([self.tabBarController.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.tabBarController.navigationController.interactivePopGestureRecognizer.enabled = NO;
- }
- }
- - (void)saveCIImageAction:(NSString *)deviceId{
-
- UIImage *image = [UIImage imageWithCIImage:saveCIImage];
- if(image){ //执行返回最后一帧
- [mPlayerView.showImageView setImage:image];
- CloudPhoneModel *deviceDcit1 = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:phoneIndex];
- /*保存上传推流设备最新视图*/
- NSString *account = nil;
- NSString *imageUrl1 = nil;
- NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- if ([[dictLogin allKeys] containsObject:@"account"])
- {
- account = [dictLogin objectForKey:@"account"];
- imageUrl1 = [HWDataManager pathForDevicePhotoWithAccount:account deviceId:[NSString stringWithFormat:@"%ld",deviceDcit1.phoneId]];
- }
-
- deviceDcit1.needUpdateImageInSever = NO;
- [[NSFileManager defaultManager] removeItemAtPath:imageUrl1 error:nil];
- [UIImagePNGRepresentation(image) writeToFile:imageUrl1 atomically:NO];
- }
- }
- #pragma mark - RCLiveSteamManagerDelegate
- - (void)liveStreamManagerOutPut:(RCLiveSteamManager *)manager didOutPutVideoPixelBuffer:(CVPixelBufferRef)pixelBuffer {
- if (!mySelf || mySelf->haveBack) {
- return;
- }
- if (!pixelBuffer) {
- return;
- }
- [mySelf updateAutoRateAndNetWorkStates];//更新网络标识 以及自动码率
-
- if (mySelf&&!(mySelf->haveBack))
- {
- mySelf->reConnectAccount = 0;
-
- @autoreleasepool {
- if (!mySelf)
- {
- return ;
- }
-
- CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
- if (mySelf->saveCIImage) {
- mySelf->saveCIImage = nil;
- }
- mySelf->saveCIImage = ciImage;
-
- if (!mySelf->videoContext) mySelf->videoContext = [CIContext contextWithOptions:nil];
-
- if (USEOPENGL)
- {
- if (ciImage)
- {
- [mySelf showImageOpenglWithCIImage:ciImage];/*使用Opengl渲染*/
-
- mySelf.concentTime = [iTools getNowTimeStamp];
- mySelf.isConnectSuccess = YES;
- }
- }
- else
- {
- if (ciImage)
- {
- [mySelf showImageUIImageViewWithCIImage:ciImage pixelBufferRef:pixelBuffer];/*使用UIImageView渲染*/
-
- mySelf.concentTime = [iTools getNowTimeStamp];
- mySelf.isConnectSuccess = YES;
- }
- }
-
- if (mySelf&&!mySelf->haveBack && mySelf->wattingView)
- {
- mainBlock(^{
- [mySelf removeNewIndicator];
- });
- }
- }
- }
- }
- - (void)liveStreamManagerOutPut:(RCLiveSteamManager *)manager didOutPutAudioData:(NSData *)pcmData {
- @autoreleasepool {
- if (mySelf&&!(mySelf->haveBack))
- {
- [mySelf->connectLock lock];
- if (!mySelf->pcmPlayer)
- {
- mySelf->pcmPlayer = [[RCPCMPlayer alloc] initWithAudioBufferSize:4096 mSampleRate:44100 mChannelsPerFrame:2];
-
- mySelf.isNeedShowVoiceBar = NO;
-
- [mySelf->pcmPlayer start];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- mySelf.isNeedShowVoiceBar = YES;
- });
- }
- if (pcmData)
- {
- mySelf.isNeedShowVoiceBar = NO;
-
- [mySelf->pcmPlayer play:pcmData];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- mySelf.isNeedShowVoiceBar = YES;
- });
- }
-
- [mySelf->connectLock unlock];
- }
- }
- }
- - (void)liveStreamManager:(RCLiveSteamManager *)manager connectState:(ConnectState)state {
- HLog(@"\n------状态回调---state = %d--", state);
- //[[VclCrash sharedInstance] writeContent:[NSString stringWithFormat:@"_connectDisconnect连接返回句柄 = %d--state--=%d-",ihandle,state]];
-
- switch (state)
- {
- case 0:/*连接已释放*/
- {
- }
- break;
- case 1:/*正在连接*/
- {
-
- }
- break;
- case 2:/*连接成功*/
- {
- HLog(@"\n-----_%s------SSSSSSSSSSS连接成功",__FUNCTION__);
-
- if (self.isFirstEnterPhone) {
- // 埋点
- HWBuryPointModel *pointModel = [HWBuryPointModel buryPointWithEventType:(EventCodeTypeCloudPhonePushEvent) buttonType:(ClickButtonTypeCloudPhonePushEnter)];
- pointModel.eventResult = @"1";
- [BuryPoint saveHWBuryPointModelListWithModel:pointModel];
-
- self.isFirstEnterPhone = NO;
- }
- }
- break;
- case 3:/*正在渲染*/
- {
-
- }
- break;
- case 4:/*正在关闭*/
- {
-
- }
- break;
- case 5:/*已关闭*/
- {
- }
- break;
- case 6:
- {
- mainBlock(^{
- [self showNewIndicator];
- [self tryAgain];
- });
- }
- break;
- case ConnectStateVerifyErr:
- {
- HLog(@"\n------token异常----重新超分-----");
- /*鉴权失败 进行超分操作*/
- /*先清除当前的token*/
- // NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- // if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
- // {
- // /*判断数据库中有没有对应phoneid*/
- // NSString* username = [dictLogin objectForKey:@"userName"];
- // NSString * bg_tableName = P2PModelList_bg_tableName(username);
- // //先显示本地缓存数据
- // NSArray* finfAlls = [PhoneP2PListModel bg_findAll:bg_tableName];
- // if (finfAlls && finfAlls.count >0) {
- // PhoneP2PListModel *listMod = finfAlls[0];
- // for (PhoneP2PModel *p2pModel in listMod.data) {
- // if (p2pModel.phoneId == self.deviceModel.phoneId){
- // [listMod.data removeObject:p2pModel];
- // [listMod bg_cover];
- // break;
- // }
- // }
- // }
- // }
-
- [[P2PDataManager shareInstance] deleteRecoderWithPhoneID:self.deviceModel.phoneId];
-
- /*开启超分流程*/
- [self extensionPhoneGetRBD];
- }
- break;
-
-
- default:
- break;
- }
- }
- - (void)openVideForLiveStreamManager:(AVCaptureDevicePosition)position needPost:(BOOL)needPost
- {
- // 限免规则判断
- NSMutableArray *freeCodes = [UseAccountManage shareInstance].cloudPhoneListModel.freeCodes;
- BOOL isFreeUse = NO;
- for (NSString *code in freeCodes) { // 限免增值服务数组
- if ([code isEqualToString:@"PHONE_CAMERA"]) {
- isFreeUse = YES;
- break;
- }
- }
-
- if (mySelf->deviceModel.phoneCameraStatus == 2) {
- // 当前云手机摄像头不可用
- mainBlock(^{
- [[iToast makeText:@"当前云手机摄像头不可用"] show];
- });
- return;
- }else if (mySelf->deviceModel.phoneCameraStatus == 0 && !isFreeUse) {
- //未购买增值服务的摄像头功能&&不限免
- mainBlock(^{
- [[iToast makeText:@"当前未购买此功能\n请在增值服务-云机摄像头开通此功能"] show];
- });
- return;
- }
-
- if (mySelf&&!(mySelf->haveBack))
- {
- if (mySelf->canControl)
- {
- [mySelf toStopRecoder];
- HLog(@"\n-----打开视频透传 后置摄像头-------");
- [mySelf toStartRecoderWithAVCaptureDevicePosition:(position)];
-
- if (needPost) {
- // 云机摄像头使用上报
- [mySelf postCloudCamera];
- }
- }
- }
- }
- - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiveEvent:(EventState)event {
-
- EventState state = event;
- if (0 == state)/*横屏*/
- {
- isLan = YES;
- mySelf->mPlayerView.isLan = YES;
- [[VclCrash sharedInstance] writeContent:[NSString stringWithFormat:@"______________视频数据_______"]];
-
- /*横屏处理*/
- [self setDeviceOrientation:(UIDeviceOrientationLandscapeLeft)];
- HLog(@"\n---000000--横屏--000000-----");
- }
- else if (1 == state)/*竖屏*/
- {
- isLan = NO;
- mySelf->mPlayerView.isLan = NO;
- [[VclCrash sharedInstance] writeContent:[NSString stringWithFormat:@"______________视频数据_______"]];
- HLog(@"\n---1111111--竖屏--1111111-----");
- /*横屏处理*/
- [self setDeviceOrientation:(UIDeviceOrientationPortrait)];
- }
- else if (2 == state)/*打开音频透传*/
- {
- if (mySelf&&!(mySelf->haveBack))
- {
- if (mySelf->canControl)
- {
- HLog(@"\n-----打开视频透传-------");
- [mySelf toStartAudioRecoder];
- }
- }
- }
- else if (3 == state)/*关闭音频透传*/
- {
- [mySelf toStopAudioRecoder];
- }
- else if (4 == state)/*打开视频透传*/
- {
- [self openVideForLiveStreamManager:AVCaptureDevicePositionBack needPost:YES];
- }
- else if (5 == state)/*关闭视频透传*/
- {
- [mySelf toStopRecoder];
- }
- else if (7 == state)/*打开视频透传--前置摄像头*/
- {
- [self openVideForLiveStreamManager:AVCaptureDevicePositionFront needPost:YES];
- }
- else if (EventStateTurnOnVideoDontNeedToServer == state)/*打开视频透传*/
- {
- [self openVideForLiveStreamManager:AVCaptureDevicePositionBack needPost:NO];
- }
- else if (EventStateTurnOnVideoFrontDontNeedToServer == state)/*打开视频透传--前置摄像头*/
- {
- [self openVideForLiveStreamManager:AVCaptureDevicePositionFront needPost:NO];
- }
- else if (EventStateTurnOnVideoDontNeedToServer == state)/*打开视频透传*/
- {
- [self openVideForLiveStreamManager:AVCaptureDevicePositionBack needPost:NO];
- }
- else if (EventStateTurnOnVideoFrontDontNeedToServer == state)/*打开视频透传--前置摄像头*/
- {
- [self openVideForLiveStreamManager:AVCaptureDevicePositionFront needPost:NO];
- }
- }
- - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiveMessage:(NSString *)message {
-
- }
- - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiNetEstimator:(NetEstimator)estimator{
-
- }
- - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiveJitterDelay:(int)jitterDelayMs{
-
- }
- #pragma mark - 视频流回调
- void connectStateCallBack (void *client, ConnectState state, void *context)
- {
- NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:1],@"ihandle",[NSNumber numberWithInt:state],@"state" ,nil];
- [[NSNotificationCenter defaultCenter] postNotificationName:NotNameByCONNECT_DISCONNECT object:dict];
- }
- static int delayVideo = 0;/*当前最高延时*/
- static int okdelayVideo = 0;/*当前连续延时较好帧数*/
- static int baddelayVideo = 0;/*当前较坏延时帧数个数*/
- static int havedelayVideoCount = 0;/*当前帧数个数*/
- NSDate *lastVideoTome;/*上一帧数据时间*/
- - (void)toStartRecoderWithAVCaptureDevicePosition:(AVCaptureDevicePosition)position
- {
- if (!self.recoderManager)
- {
- self.recoderManager = [[RCVideoRecoderManager alloc] initWithAVCaptureDevicePosition:position];
- self.recoderManager.delegate = self;
- }
-
- if (!self.recoderManager.isRecoding)
- {
- [self.recoderManager startRecording];
- }
- }
- - (void)toStopRecoder
- {
- if (self.recoderManager)
- {
- [self.recoderManager stopRecording];
- self.recoderManager = nil;
- }
- }
- - (void)toStartAudioRecoder
- {
- if (!self.audioRecoderMamager)
- {
- self.audioRecoderMamager = [[RCAudioRecoderMamager alloc] init];
- self.audioRecoderMamager.delegate = self;
- }
-
- if (!self.audioRecoderMamager.isRecoding)
- {
- [self.audioRecoderMamager startRecording];
- }
- }
- - (void)toStopAudioRecoder
- {
- if (self.audioRecoderMamager)
- {
- [self.audioRecoderMamager stopRecording];
- self.audioRecoderMamager = nil;
- }
- }
- /**
- * @brief 请求I帧数据
- */
- - (void)requestIFrame
- {
- [self.liveStreamManager rc_requestIDFrame];
- }
- #pragma mark - 流媒体服务器
- // 初始化
- - (BOOL)initVideoServer {
- return YES;
- }
- // 连接
- - (void)connectVideoServer {
- if (!mySelf || haveBack){
- return;
- }
-
- if (!connectLock)
- {
- connectLock = [[NSLock alloc] init];
- }
- [connectLock lock];
- delayVideo = 0;
- okdelayVideo = 0;
- havedelayVideoCount = 0;
- HLog(@"__________连接000000__________deviceModel.cardToken = %@",deviceModel.cardToken);
- RCStateInt result = -1;
-
- if([deviceModel.pushFlowCode isEqualToString:@"H265"])
- {
- if (deviceModel.vpnMode == 1){//UPD
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_udp
- videoQuality:RCCloudPhoneVideoQuality_High
- verify:deviceModel.cardToken
- streamAESKey:nil];
-
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- KyoLog(@"__________连接方式000000___UDP____H265___");
- }
- else if (deviceModel.vpnMode == 2){//TCP
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_websocket
- videoQuality:RCCloudPhoneVideoQuality_High
- verify:deviceModel.cardToken
- streamAESKey:nil];
-
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- HLog(@"__________连接方式000000___TCP__H265_____");
- }
- else{
- if (vpnStatus == 1) {
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_websocket
- videoQuality:RCCloudPhoneVideoQuality_High
- verify:deviceModel.cardToken
- streamAESKey:nil];
-
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- HLog(@"__________连接方式000000___TCP__H265_____");
- }
- else //默认使用UDP
- {
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_udp
- videoQuality:RCCloudPhoneVideoQuality_High
- verify:deviceModel.cardToken
- streamAESKey:nil];
-
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- KyoLog(@"__________连接方式000000___UDP____H265___");
- }
- }
- }
- else
- {
- if (deviceModel.vpnMode == 1) {
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_udp
- videoQuality:RCCloudPhoneVideoQuality_Default
- verify:deviceModel.cardToken
- streamAESKey:nil];
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- if (result > 0) {
- KyoLog(@"__________连接方式__000000___UDP____H264_ip = %@__ port = %@", ip, internetVideoPort);
- } else {
- KyoLog(@"__________连接失败__000000___UDP____H264_ip = %@__ port = %@", ip, internetVideoPort);
- }
- }
- else if (deviceModel.vpnMode == 2){
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_websocket
- videoQuality:RCCloudPhoneVideoQuality_Default
- verify:deviceModel.cardToken
- streamAESKey:nil];
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- KyoLog(@"__________连接方式000000___TCP____H264___");
- }else{
- //如果安卓卡用户开启VPN,需切换TCP
- if (vpnStatus == 1) {
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_websocket
- videoQuality:RCCloudPhoneVideoQuality_Default
- verify:deviceModel.cardToken
- streamAESKey:nil];
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- KyoLog(@"__________连接方式000000___TCP____H264___");
- }
- else //默认使用UDP
- {
- NSString *tempIP = ip;
- result = [self.liveStreamManager rc_openWithIp:ip
- port:internetVideoPort.intValue
- connectType:RCCloudPhoneConnectType_udp
- videoQuality:RCCloudPhoneVideoQuality_Default
- verify:deviceModel.cardToken
- streamAESKey:nil];
- if ([tempIP isEqualToString:ip])
- {
- if (result < 0)
- {
- [self tryAgain];
- }
- else if (result == 12)
- {
- [[iToast makeText:@"画面异常,请重新进入"] show];
- }
- }
- if (result > 0) {
- KyoLog(@"__________连接方式__000000___UDP____H264_ip = %@__ port = %@", ip, internetVideoPort);
- } else {
- KyoLog(@"__________连接失败__000000___UDP____H264_ip = %@__ port = %@", ip, internetVideoPort);
- }
- }
- }
- }
-
- HLog(@"______连接____ip = %@ port = %@",ip,internetVideoPort);
-
- [[VclCrash sharedInstance] writeContent:[NSString stringWithFormat:@"connectVideoServer连接返回句柄 = %d--",result]];
-
- HLog(@"__________连接1111111__________");
- HLog(@"__________连接成功__________");
- lastVideoTome = [NSDate date];
- NSString *dataStr = [RCCommandHelp commandResolution500WithType:(NSUInteger)BITRATE_WIFI_HD];
- [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
- // // 20210305 因为安卓做了分辨率适应 而iOS不需要 所以现在指定接收码率 这个就不用修改对应触摸点的范围比例了 W_PHONE H_PHONE
- // // 发送数据
- // if ([deviceModel.buyVipType isEqualToString:CloudPhoneTypeWuJiPro]) {
- // NSString *commondStr = @"{\"data\":{\"height\":1920,\"width\":1080},\"type\":\"setPhoneSize\"}";
- // [self send_data:commondStr];
- // }
- //
- // //记录推流开始时间
- // NSString *connectedDataStr = [RCCommandHelp commandConnectedWithDeviceId:deviceId];
- // [self send_data:connectedDataStr];
- [connectLock unlock];
- }
- // 断开连接
- - (void)disconnectVideoServer {
- NSString *commondStr = [RCCommandHelp toStopControllerDevice500];
- [self send_data:commondStr];
- HLog(@"\n-----...commondStr = %@....",commondStr);
- [self.liveStreamManager rc_disconnect];
- }
- - (void)send_data:(NSString *)dataStr
- {
- if (canControl)
- {
- KyoLog(@"\n-commandChannelManager---%ld--%@",self.commandChannelManager.rc_socketStatus,dataStr);
- [self.commandChannelManager rc_sendData:dataStr];
- }
- }
- #pragma mark - PlayerViewDelegate---下方虚拟按键
- - (void)mueBtnBePressed:(id)sender
- {
- HLog(@"__________%s__________",__func__);
- NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:187];
- HLog(@"\n-----...dataStr = %@....",dataStr);
-
- [self send_data:dataStr];
- }
- - (void)homeBtnBePressed:(id)sender
- {
- HLog(@"__________%s__________",__func__);
- NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:3];
- HLog(@"\n-----...dataStr = %@....",dataStr);
-
- [self send_data:dataStr];
- }
- - (void)backBtnBePressed:(id)sender
- {
- HLog(@"__________%s__________",__func__);
- NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:4];
- HLog(@"\n-----...dataStr = %@....",dataStr);
-
- [self send_data:dataStr];
- }
- - (void)useInfoBtnBePressed:(id)sender
- {
- HLog(@"云手机推流界面 控制按钮点击手势开始");
- [[NSNotificationCenter defaultCenter] postNotificationName:PlayerViewControlBtnTouchBeganNotification object:nil userInfo:nil];
- HLog(@"云手机推流界面 控制按钮点击手势结束");
- [[NSNotificationCenter defaultCenter] postNotificationName:PlayerViewControlBtnTouchEndNotification object:nil userInfo:nil];
-
- HLog(@"__________%s__________",__func__);
- MySetViewController *nextVC = [[MySetViewController alloc] init];
- [self.navigationController pushViewController:nextVC animated:YES];
- self.isNeedRecyclResource = NO;
- }
- #pragma mark - PlayerControlViewDelegate---控制器按键
- //- (void)stopShareBtnBePressed:(id)sender
- //{
- // HLog(@"__________%s__________",__func__);
- // /*关闭分享成功后调用*/
- // CloudPhoneModel *deviceDcit = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:phoneIndex];
- // NSString *userCardId = @"";
- // userCardId = [NSString stringWithFormat:@"%ld",deviceDcit.phoneId];
- //
- // NSString *username = deviceDcit.username;
- //
- // if (0 == deviceShareStates || deviceShareStates == 3)/*分享中*/
- // {
- // /*暂停分享*/
- // NSString *reqsturl = [NSString stringWithFormat:SuspendScreenShareAPI,userCardId,username];
- // [[UseAccountManage shareInstance] CommonGetWithCallBackCode:reqsturl Parameters:nil success:^(id _Nonnull responseObject) {
- // SuperModel *mod = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
- // [self removeNewIndicator];
- // NSString *showStr = nil;
- // showStr = mod.msg;
- // if (mod.status && mod.status.integerValue == 0)
- // {
- // deviceDcit.screenShareStatus = 1;
- // self->deviceShareStates = 1;
- // [self->controlView pauseShareView];
- // /*刷新视图 更新设备列表*/
- // deviceDcit.screenShareStatus = self->deviceShareStates;
- // }
- // else
- // {
- // if (mod.msg == nil || [mod.msg isEqualToString:@""])
- // {
- // showStr = @"暂停分享失败";
- // }
- // [[iToast makeText:showStr] show];
- // }
- // }
- // failure:^(NSError * _Nonnull error) {
- // [[iToast makeText:@"暂停分享失败"] show];
- // [self removeNewIndicator];
- // }];
- // }
- // else if (1 == deviceShareStates)/*暂停分享*/
- // {
- // /*开启分享*/
- // NSString *reqsturl = [NSString stringWithFormat:StartAgainScreenShareAPI,userCardId,username];
- // [[UseAccountManage shareInstance] CommonGetWithCallBackCode:reqsturl Parameters:nil success:^(id _Nonnull responseObject) {
- // SuperModel *mod = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
- // [self removeNewIndicator];
- // NSString *showStr = nil;
- // showStr = mod.msg;
- // if (mod.status && mod.status.integerValue == 0)
- // {
- // self->deviceShareStates = 3;
- // deviceDcit.screenShareStatus = self->deviceShareStates;
- // [self->controlView shareingShareView];
- // }
- // else
- // {
- // if (mod.msg == nil || [mod.msg isEqualToString:@""])
- // {
- // showStr = @"开启分享失败";
- // }
- // [[iToast makeText:showStr] show];
- // }
- // }
- // failure:^(NSError * _Nonnull error) {
- // [[iToast makeText:@"开启分享失败"] show];
- // [self removeNewIndicator];
- // }];
- // }
- //}
- - (void)exitAndClosePlayerView
- {
- // 埋点
- HWBuryPointModel *pointModel = [HWBuryPointModel buryPointWithEventType:(EventCodeTypeCloudPhonePushEvent) buttonType:(ClickButtonTypeCloudPhonePushExit)];
- [BuryPoint saveHWBuryPointModelListWithModel:pointModel];
- }
- - (void)exitPlayerViewBtnBePressed:(id)sender
- {
- // 埋点
- HWBuryPointModel *pointModel = [HWBuryPointModel buryPointWithEventType:(EventCodeTypeCloudPhonePushEvent) buttonType:(ClickButtonTypeCloudPhonePushExit)];
- [BuryPoint saveHWBuryPointModelListWithModel:pointModel];
- [self exitPlayerView];
- }
- - (void)exitAndClosePlayerViewBtnBePressed:(id)sender{
- [self exitAndClosePlayerView];
- }
- - (void)exitPlayerView{
-
- [[UseAccountManage shareInstance] saveDviceDriftInfoWith:self->mPlayerView.controlBtn.frame.origin.x
- ponitY:self->mPlayerView.controlBtn.frame.origin.y
- hidden:self->mPlayerView.controlBtn.hidden
- deviceSN:self->deviceId];
- [self.navigationController popViewControllerAnimated:YES];
- [self removeNewIndicator];
- [self->mPlayerView.controlBtn removeFromSuperview];
- [self->connectLock lock];
- mySelf = nil;
- self->haveBack = YES;
- [self->connectLock unlock];
-
- //返回回调
- mainBlock(^{
- //退出返回最后一帧
- [self saveCIImageAction:self->deviceId];
- });
- }
- - (void)showAlertToWaitForTrial:(NSInteger)mins {
- NSString *tipsStr = [NSString stringWithFormat:@"由于系统资源繁忙\n请在%ld分钟后再次进入云手机", mins];
- NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:tipsStr attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:16],NSForegroundColorAttributeName: HWCFD1D4Color}];
-
- UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- }];
- [sureAction setValue:HW3B7FFFColor forKey:@"titleTextColor"];//iOS8.3
-
- [self showAlertWithTitle:nil message:string tilteAlignment:NSTextAlignmentCenter messageAlignment:NSTextAlignmentCenter sureAction:sureAction cancelAction:nil];
- }
- #pragma mark - 新的手势回调委托
- - (void)playerShowImageViewtouchesStr:(NSString *)commondStr
- {
- if (canControl)
- {
- [self send_data:commondStr];
- }
- }
- -(void)initAlertWithTitle:(NSString *_Nullable)title message:(NSString *)message sureActionBlock:(sureActionBlock)sureActionBlock {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- sureActionBlock(alertController);
- }];
- [alertController addAction:cancelAction];
-
- // 弹窗边框
- UIView *subview = alertController.view.subviews.firstObject;
- UIView *alertContentView = subview.subviews.firstObject;
- alertContentView.layer.cornerRadius = 10;
- // alertContentView.layer.masksToBounds = YES;
- alertContentView.layer.shadowColor = [UIColor colorWithRed:30/255.0 green:32/255.0 blue:34/255.0 alpha:1.0].CGColor;
- alertContentView.layer.shadowOffset = CGSizeMake(0,0);
- alertContentView.layer.shadowOpacity = 1;
- alertContentView.layer.shadowRadius = 7;
- // 弹窗背景颜色
- if (@available(iOS 13.0, *)) {
- alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
- }
-
- UIViewController *currentVC = [[ShortcutManager shareInstance] findCurrentShowingViewController];
- [currentVC presentViewController:alertController animated:YES completion:nil];
- // [self presentViewController:alertController animated:YES completion:nil];
- }
- #pragma - mark - 监听网络变化
- - (void)networkStateChange:(NSNotification *)notification
- {
- /*退出登录状态 直接无视通知*/
- NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
-
- if ([[dictLogin allKeys] containsObject:@"account"])
- {
- /*处理*/
- switch ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus)
- {
- case AFNetworkReachabilityStatusUnknown:/*网络状态未知*/
- {
- ;
- }
- break;
- case AFNetworkReachabilityStatusNotReachable:/*网络不可用*/
- {
- [[iToast makeText:@"网络异常,请稍后重试!"] show];
-
- // if (_ihandle > 0)
- // {
- [self disconnectVideoServer];
- // }
- }
- break;
- case AFNetworkReachabilityStatusReachableViaWWAN:/*流量*/
- {
- mainBlock(^{
- [self showNewIndicator];
- });
- [self tryAgain];
- }
- break;
- case AFNetworkReachabilityStatusReachableViaWiFi:/*WiFi*/
- {
- mainBlock(^{
- [self showNewIndicator];
- });
- [self tryAgain];
- }
- break;
-
- default:
- break;
- }
- }
- else
- {
- /*设备已在别处登录*/
- [self initAlertWithTitle:nil message:NSLocalizedString(@"log_login_other",nil) sureActionBlock:^(UIAlertController * _Nonnull alertView) {
- [self.tabBarController.navigationController popToRootViewControllerAnimated:YES];
- }];
- }
- }
- BOOL inReconnect = NO;
- - (void)tryAgain
- {
- reConnectAccount++;
-
- if (reConnectAccount == 4)
- {
- mainBlock(^{
-
- if (self.isFirstEnterPhone) {
- // 埋点
- HWBuryPointModel *pointModel = [HWBuryPointModel buryPointWithEventType:(EventCodeTypeCloudPhonePushEvent) buttonType:(ClickButtonTypeCloudPhonePushEnter)];
- pointModel.eventResult = @"0";
- [BuryPoint saveHWBuryPointModelListWithModel:pointModel];
-
- self.isFirstEnterPhone = NO;
- }
-
- [self exitPlayerView];
-
- [[iToast makeText:@"云手机连接超时,请稍后再试!"] show];
- });
-
- return;
- }
- [self reconnectDevice];
- }
- - (void)reconnectDevice{
- globalBlock(^{
- @synchronized (self) {
- inReconnect = YES;
- [self disconnectVideoServer];
- if ([self initVideoServer])
- {
- [self connectVideoServer];
- }
- }
- });
- }
- #pragma mark -- /*视频码率按钮文字、索引、指令 之间相互转换*/
- - (NSUInteger)resolutionBtnIndexToTypeWithIndex:(NSInteger)index
- {
- NSInteger type = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
-
- AFNetworkReachabilityStatus netStatus = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
- if (netWorkStates == AFNetworkReachabilityStatusReachableViaWiFi) {
- type = BITRATE_WIFI_STANDARD_CLEARING;
- }
-
- switch (index)
- {
- case 2:/*极速*/
- type = BITRATE_EXTREME_SPEED;
- break;
- // case 1:/*高速*/
- // type = BITRATE_HIGH_SPEED;
- // break;
- case 0:/*高清*/
- if (netStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
- type = BITRATE_WIFI_HD;
- } else {
- type = BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/;
- }
- break;
- case 1:/*标清*/
- if (netStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
- type = BITRATE_WIFI_STANDARD_CLEARING;
- } else {
- type = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
- }
- break;
- case 3:/*自动*/
- type = BITRATE_AUTO;
- break;
-
- default:
- break;
- }
-
- return type;
- }
- - (NSInteger)resolutionBtnTypeToIndexWithType:(NSInteger)type
- {
- NSInteger index = 2;
- switch (type)
- {
- case BITRATE_EXTREME_SPEED:
- index = 2;
- break;
- // case BITRATE_HIGH_SPEED:
- // index = 1;
- // break;
- case BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/:
- index = 0;
- break;
- // case BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/:
- // index = 1;
- // break;
- case BITRATE_AUTO:
- index = 3;
- break;
-
- default:
- index = 2;
- break;
- }
-
- return index;
- }
- - (NSString *)resolutionBtnIndexToStringWithType:(NSInteger)index
- {
- NSString *qualitySelectBtnString = @"标清";
- switch (index)
- {
- case 2:
- qualitySelectBtnString = @"极速";
- break;
- // case 1:
- // qualitySelectBtnString = @"高速";
- // break;
- case 0:
- qualitySelectBtnString = @"高清";
- break;
- case 1:
- qualitySelectBtnString = @"标清";
- break;
- case 4:
- qualitySelectBtnString = @"自动";
- break;
-
- default:
- break;
- }
-
- return qualitySelectBtnString;
- }
- #pragma mark -- /*通知添加与移除*/
- - (void)addNSNotification
- {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange:) name:NetWorkChangeNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connectDisconnect:) name:NotNameByCONNECT_DISCONNECT object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:AVSystemController_SystemVolumeDidChangeNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(extensionRBDGetRbdDeviceNotification:) name:GetRbdDeviceNotification object:nil];
-
- outputVolumeKVO = YES;
- [[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:(void *)[AVAudioSession sharedInstance]];
-
- // 控制按钮收拾开始、结束
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerViewControlBtnTouchBegan) name:PlayerViewControlBtnTouchBeganNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerViewControlBtnTouchEnd) name:PlayerViewControlBtnTouchEndNotification object:nil];
- }
- - (void)removeNSNotification
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:NetWorkChangeNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:NotNameByCONNECT_DISCONNECT object:nil];
-
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
-
- if (outputVolumeKVO)
- {
- [[AVAudioSession sharedInstance] removeObserver:self forKeyPath:@"outputVolume" context:(void *)[AVAudioSession sharedInstance]];
- outputVolumeKVO = NO;
- }
-
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- #pragma mark -- 音视频数据透传回调
- static double firstTime;
- static double lastTime;
- static int couneeee = 0;
- - (void)videoOutPutH264Data:(void *)h264Data dataLenth:(NSInteger)lenth
- {
- if (couneeee == 0)
- {
- firstTime = [[NSDate date] timeIntervalSince1970];
- }
- couneeee++;
- [self.liveStreamManager rc_sendTransportData:(const char *)h264Data length:(int)lenth dataType:VirtualDataTypeVideo];
- if (couneeee == 100)
- {
- lastTime = [[NSDate date] timeIntervalSince1970];
- HLog(@"\nvideoOutPutH264DataTime --%f",lastTime - firstTime);
- }
- }
- - (void)audioOutPutData:(void *)audioData dataLenth:(NSInteger)lenth
- {
- [self.liveStreamManager rc_sendTransportData:(const char *)audioData length:(int)lenth dataType:VirtualDataTypeAudio];
- }
- -(NSString *)hexStringWithData:(NSData *)data
- {
- const unsigned char* dataBuffer = (const unsigned char*)[data bytes];
- if(!dataBuffer){
- return nil;
- }
- NSUInteger dataLength = [data length];
- NSMutableString* hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
- for(int i = 0; i < dataLength; i++){
- [hexString appendString:[NSString stringWithFormat:@"%02lx", (unsigned long)dataBuffer[i]]];
- }
- NSString* result = [NSString stringWithString:hexString];
- return result;
- }
- // 板卡切换通知
- - (void)changeCardNotification:(NSNotification *)notification {
- CloudPhoneModel *model = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:self->phoneIndex];
-
- NSDictionary *dict = [notification userInfo];
- if ([[dict allKeys] containsObject:@"data"])
- {
- NSDictionary *data = [dict objectForKey:@"data"];
-
- if ([[data allKeys] containsObject:@"userCardId"]) {
-
- NSInteger userCardId = [[data objectForKey:@"userCardId"] integerValue];
- if (model.phoneId == userCardId) { // 通知是否是当前设备
-
- [[iToast makeText:@"设备信息已切换,请重新进入云机"] show];
-
- [self exitPlayerView];
- }
- }
- }
- }
- - (NSArray *)getAllIvar:(id)object
- {
- NSMutableArray *array = [NSMutableArray array];
- unsigned int count;
- Ivar *ivars = class_copyIvarList([object class], &count);
- for (int i = 0; i < count; i++) {
- Ivar ivar = ivars[i];
- const char *keyChar = ivar_getName(ivar);
- NSString *keyStr = [NSString stringWithCString:keyChar encoding:NSUTF8StringEncoding];
- @try {
- id valueStr = [object valueForKey:keyStr];
- NSDictionary *dic = nil;
- if (valueStr) {
- dic = @{keyStr : valueStr};
- } else {
- dic = @{keyStr : @"值为nil"};
- }
- [array addObject:dic];
- }
- @catch (NSException *exception) {}
- }
- return [array copy];
- }
- //系统声音改变
- #pragma -mark 系统声音改变
- -(void)volumeChanged:(NSNotification *)notification
- {
- if (!self.isNeedShowVoiceBar) { // 不需要展示音量工具条
- return;
- }
-
- /*音量开关打开时 允许发送指令 否则直接返回*/
- NSDictionary *loginDict = [[UseAccountManage shareInstance] getLoginInfo];
- NSString *account = [loginDict objectForKey:@"account"];
- NSString *key = [account stringByAppendingString:Const_Volume_Info_Dict];
-
- NSDictionary *volumeDict = [[NSUserDefaults standardUserDefaults] objectForKey:key];
-
- NSString *volumeStr = [volumeDict safeStringForKey:deviceId];
-
- if (!volumeStr || ![volumeStr isEqualToString:@"1"]){
- return;
- }
-
- float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
- HLog(@"FlyElephant-系统音量:%f", volume);
-
- if (volume == 0)
- {
- NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:25];
-
- [self send_data:dataStr];
- }
- else if (volume == 1)
- {
- NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:24];
-
- [self send_data:dataStr];
- }
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
- if(context == (__bridge void *)[AVAudioSession sharedInstance])
- {
- /*音量开关打开时 允许发送指令 否则直接返回*/
- NSDictionary *loginDict = [[UseAccountManage shareInstance] getLoginInfo];
- NSString *account = [loginDict objectForKey:@"account"];
- NSString *key = [account stringByAppendingString:Const_Volume_Info_Dict];
-
- NSDictionary *volumeDict = [[NSUserDefaults standardUserDefaults] objectForKey:key];
-
- NSString *volumeStr = [volumeDict safeStringForKey:deviceId];
-
- if (!volumeStr || ![volumeStr isEqualToString:@"1"]){
- return;
- }
-
- float newValue = [[change objectForKey:@"new"] floatValue];
- float oldValue = [[change objectForKey:@"old"] floatValue];
-
- if (newValue > oldValue)
- {
- HLog(@"\n-----音量增加");
- NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:24];
-
- [self send_data:dataStr];
- }
- else
- {
- HLog(@"\n-----音量降低");
- NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:25];
-
- [self send_data:dataStr];
- }
- }
- }
- #pragma mark-----------------------------------------------------------------------------------------------
- #pragma mark - 画面渲染、画面调整相关
- #pragma mark - 更新网络标识 以及自动码率
- - (void)updateAutoRateAndNetWorkStates
- {
- int audio_time = 0;
- NSDate *nowTime = [NSDate date];
- NSString *nowTimeStr = [NSString stringWithFormat:@"%f", (double)[nowTime timeIntervalSince1970]];
- NSString *lastTimeStr = [NSString stringWithFormat:@"%f", (double)[lastVideoTome timeIntervalSince1970]];
- audio_time = ([nowTimeStr doubleValue] - [lastTimeStr doubleValue]) * 1000;
- lastVideoTome = nowTime;
-
- static int frameCount = 200;
-
- if (0 == frameCount)
- {
- frameCount = 200;
-
- if (audio_time > 500 && !haveBack && self->netWorkStates != 0)
- {
- self->netWorkStates = 0;
- mainBlock(^{
- [self->mPlayerView.controlBtn setImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
- });
- }
- else if (audio_time > 100 && !haveBack && self->netWorkStates != 1)
- {
- self->netWorkStates = 1;
- mainBlock(^{
- [self->mPlayerView.controlBtn setImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
- });
- }
- else if (!haveBack && self->netWorkStates != 2)
- {
- self->netWorkStates = 2;
- mainBlock(^{
- [self->mPlayerView.controlBtn setImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
- });
- }
- }
- else
- {
- frameCount--;
- }
-
- if (delayVideo < audio_time)
- {
- delayVideo = audio_time;
- }
-
- if (delayVideo < 80)
- {
- okdelayVideo++;
- }
- else
- {
- okdelayVideo = 0;
- }
-
- if (delayVideo > 120)
- {
- baddelayVideo++;
- }
-
- havedelayVideoCount++;
-
- if (havedelayVideoCount % 1000 == 0)
- {
- baddelayVideo = 0;
- }
-
- if (!haveBack && self->rate == 3) {
- if (baddelayVideo > 10)
- {
- /*降低码率*/
- if (self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/ || self->rateForAuto == BITRATE_WIFI_HD)
- {
- if (self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/) {
- self->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
- } else {
- self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING;
- }
- }
- else if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/ || self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING)
- {
- self->rateForAuto = BITRATE_EXTREME_SPEED;
- }
- // else if (mySelf->rateForAuto == BITRATE_HIGH_SPEED)
- // {
- // mySelf->rateForAuto = BITRATE_EXTREME_SPEED;
- // NSString *dataStr = [RCCommandHelp commondResolution500WithType:mySelf->rateForAuto];
- // int result = send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
- // }
- NSString *dataStr = [RCCommandHelp commandResolution500WithType:self->rateForAuto];
- // send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
- [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
- baddelayVideo = 0;
- }
-
- if (okdelayVideo > 1000)
- {
- /*上升码率*/
- if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/ || self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING)
- {
- if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/) {
- self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/;
- } else {
- self->rateForAuto = BITRATE_WIFI_HD;
- }
- }
- // else if (mySelf->rateForAuto == BITRATE_HIGH_SPEED)
- // {
- // mySelf->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
- // NSString *dataStr = [RCCommandHelp commondResolution500WithType:mySelf->rateForAuto];
- // int result = send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
- // }
- else if (self->rateForAuto == BITRATE_EXTREME_SPEED)
- {
- if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
- self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING;
- } else {
- self->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
- }
- }
- NSString *dataStr = [RCCommandHelp commandResolution500WithType:self->rateForAuto];
- // send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
- [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
- okdelayVideo = 0;
- }
- }
- }
- #pragma mark - opengl渲染
- - (void)showImageOpenglWithCIImage:(CIImage *)ciImage
- {
- // CGFloat tempRate = ciImage.extent.size.width/ciImage.extent.size.height;
- // if (w_h_rate != tempRate)
- // {
- //// ksharedAppDelegate.couldPhone_W_PHONE = ciImage.extent.size.width;
- //// ksharedAppDelegate.couldPhone_H_PHONE = ciImage.extent.size.height;
- //
- // w_h_rate = tempRate;
- // mainBlock(^{
- // [self updatePlayViewRate:tempRate];
- // });
- // }
- [mPlayerView glkShowImage:ciImage];
- }
- #pragma mark - UIImageView渲染
- - (void)showImageUIImageViewWithCIImage:(CIImage *)ciImage pixelBufferRef:(CVPixelBufferRef)pixelBuff1
- {
- CGImageRef videoImage = [videoContext createCGImage:ciImage fromRect:CGRectMake(0, 0, CVPixelBufferGetWidth(pixelBuff1), CVPixelBufferGetHeight(pixelBuff1))];
- UIImage *image = [UIImage imageWithCGImage:videoImage];
- CGFloat tempRate = image.size.width/image.size.height;
-
- mainBlock(^{
- if (image)
- {
- // if (w_h_rate != tempRate)
- // {
- //// ksharedAppDelegate.couldPhone_W_PHONE = ciImage.extent.size.width;
- //// ksharedAppDelegate.couldPhone_H_PHONE = ciImage.extent.size.height;
- //
- // [self updatePlayViewRate:tempRate];
- // }
- self->mPlayerView.showImageView.image = image;
- }
- });
- CGImageRelease(videoImage);
- }
- #pragma mark -- /*画面布局调整*/
- - (void)updatePlayViewRate:(CGFloat)tempRate
- {
- /*设置横竖屏*/
- if (tempRate > 1) {/*横屏*/
- [self setDeviceOrientation:(UIDeviceOrientationLandscapeRight)];
- // [self saveCIImageAction:self->deviceId];
- [mPlayerView setLanMas_makeWithImageRate:tempRate isOpenVirtual:[deviceModel isOpenVirtualKey] isUsageMode:[deviceModel isOpenUsageMode]];
- }else{/*竖屏*/
- [self setDeviceOrientation:(UIDeviceOrientationPortrait)];
- // [self saveCIImageAction:self->deviceId];
- [mPlayerView setPoMas_makeWithImageRate:tempRate isOpenVirtual:[deviceModel isOpenVirtualKey] isUsageMode:[deviceModel isOpenUsageMode]];
- }
- }
- #pragma mark------------------------------------------------------------------------------------------------------------------
- #pragma mark-提示 loading 相关
- #pragma mark-添加带有文字loading
- - (void)addLoadingWithTipsView:(NSString *)tipsStr
- {
- if (loadingWithTipsView)
- {
- [loadingWithTipsView removeFromSuperview];
- loadingWithTipsView = nil;
- }
- loadingWithTipsView = [self loadingViewWithTipsStr:tipsStr];
-
- [self.view addSubview:loadingWithTipsView];
- }
- - (void)removeLoadingWithTipsView
- {
- if (loadingWithTipsView)
- {
- [loadingWithTipsView removeFromSuperview];
- loadingWithTipsView = nil;
- }
- }
- - (UIView *)loadingViewWithTipsStr:(NSString*)tipsStr
- {
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
- [bgView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
-
- FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"loadingWhiteGif" withExtension:@"gif"]]];
-
- FLAnimatedImageView *upView = [[FLAnimatedImageView alloc] init];
- [upView setFrame:CGRectMake((SCREEN_W - 65.f)/2.f, (SCREEN_H - 65.f)/2.f, 65.f, 65.f)];
- [upView setContentMode:UIViewContentModeScaleAspectFill];
- [upView setBackgroundColor:[ UIColor clearColor]];
- upView.animatedImage = image;
- [bgView addSubview:upView];
-
- /*标签文字*/
- UILabel *tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_W - 100.f)/2.f, (SCREEN_H - 65.f)/2.f + 65.f + 10.f, 100.f*AUTOSCALE, 20.f)];
- [tipsLabel setText:tipsStr];
- [tipsLabel setBackgroundColor:[UIColor clearColor]];
- [tipsLabel setTextColor:[UIColor whiteColor]];
- [tipsLabel setFont:[UIFont systemFontOfSize:14.f]];
- [tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
-
- [bgView addSubview:tipsLabel];
-
- return bgView;
- }
- #pragma mark-添加loading
- -(void)showNewIndicator
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- if (self->wattingView == nil)
- {
- HLog(@"Tan +++++开");
- self->wattingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
- [self->wattingView setBackgroundColor:RGBACOLOR(0.f, 0.f, 0.f, 0.7)];
- [self->wattingView.layer setCornerRadius:10.f];
- self->wattingView.center = [[UIApplication sharedApplication] keyWindow].center;// 将wattingVideoImageindicator放于播放画面的中央位置
- self->wattingView.hidden = NO;
-
- FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"loadingWhiteGif" withExtension:@"gif"]]];
-
- FLAnimatedImageView *upView = [[FLAnimatedImageView alloc] init];
- [upView setFrame:CGRectMake((100 - 65.f)/2.f, (100 - 65.f)/2.f, 65.f, 65.f)];
- [upView setContentMode:UIViewContentModeScaleAspectFill];
- [upView setBackgroundColor:[ UIColor clearColor]];
- upView.animatedImage = image;
- [self->wattingView addSubview:upView];
- [self->mPlayerView addSubview:self->wattingView];
- }
- });
- }
- -(void)removeNewIndicator
- {
- if (self->wattingView != nil)
- {
- [[self->wattingView viewWithTag:1111].layer removeAllAnimations];
-
- self->wattingView.hidden = YES;
- [self->wattingView removeFromSuperview];
- self->wattingView = nil;
- }
- }
- #pragma mark 定时器
- - (void)setTimerCountDown {
- HLog(@"开启一个");
-
- if (_timer) {
- // 取消定时器
- [self cancelTimer];
- }
-
- // 初始化值计时数据
- self.adjustTime = 3;
- self.concentTime = [iTools getNowTimeStamp];
- self.currentTime = 0;
-
- _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
- }
- - (void)cancelTimer {
- // 取消定时器
- [_timer invalidate];
- _timer = nil;
- }
- - (void)timerChange {
-
- self.currentTime++;// 0、定时器计数
-
- [self extensionAdjustBtnFrameCheckAdjustTime];// 1、悬浮球3s后 自动靠边隐藏
-
-
- // [self checkConcentTime];// 3、30s之后 没有收到拉流数据 自动断开链接
-
- [self checkCloudPhoneIsV];// 4、60s 检测一次 云手机是否过期
- }
- // 3、30s之后 没有收到拉流数据 自动断开链接
- - (void)checkConcentTime {
-
- NSInteger now = [iTools getNowTimeStamp];
- NSInteger timeDiff = now - self.concentTime; // 渲染时间与当前时间 时间差
- if (self.concentTime == 0) { //云手机未连接成功
- HLog(@"云手机未连接成功");
- }else if (timeDiff >= 30) { // 30s 无渲染数据
- HLog(@"云手机30s 无渲染数据 自动断开连接");
- [[iToast makeText:@"云手机连接超时,请稍后再试!"] show];
- [self exitPlayerView];
- }else {
- // HLog(@"云手机渲染数据时间差:%zd", timeDiff);
- }
- }
- // 4、60s 检测一次 云手机是否过期
- - (void)checkCloudPhoneIsV {
-
- if (self.currentTime % 60 == 0) { // 每60s检测一次
- //判断云手机是否已过期
- [self judgeDeviceVaildTimeIsExpire];
- }
- }
- //判断云手机是否已过期
- - (void)judgeDeviceVaildTimeIsExpire
- {
- if ([UseAccountManage shareInstance].cloudPhoneListModel.diskInfo && [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo count] > phoneIndex)
- {
- /*倒计时*/
- CloudPhoneModel *deviceDcit = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:self->phoneIndex];
- int timeMin = (int)deviceDcit.validTime;
- double nowDataTime = [[NSDate date] timeIntervalSince1970];
- timeMin = timeMin - (nowDataTime - deviceDcit.getDeviceTime)/60;
- if (deviceDcit.userCardType == 1 || deviceDcit.userCardType == 2 || deviceDcit.userCardType == 3) {
- timeMin = (int)deviceDcit.validTime;
- }
- if (0 >= timeMin) //已到期
- {
- // 通知代理云手机已过期
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if ([self->_delegate respondsToSelector:@selector(playerViewControllerBackWithPhoneIndex:)]) {
- [self->_delegate playerViewControllerBackWithPhoneIndex:self->phoneIndex];
- }
- });
- [self exitPlayerView];
- }
- }
- }
- #pragma mark 云机摄像头使用记录上报
- - (void)postCloudCamera {
- HLog(@"\n----摄像头---调用上报----");
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- [params setObject:@"PHONE_CAMERA" forKey:@"code"];
- [params setObject:deviceId forKey:@"userCardId"];
-
- [[UseAccountManage shareInstance] CommonPostCallBackCode:PostServiceUseAPI Parameters:params success:^(id _Nonnull responseObject) {
-
- if (CODE == 0) {
-
- }
-
- } failure:^(NSError * _Nonnull error) {
- HLog(@"%@",error);
- }];
- }
- #pragma mark - 提示框
- - (void)showAlertWithTitle:(NSAttributedString*_Nullable)atbTitle
- message:(NSAttributedString*_Nullable)atbmessage
- tilteAlignment:(NSTextAlignment)tilteAlignment
- messageAlignment:(NSTextAlignment)messageAlignment
- sureAction:(UIAlertAction*_Nullable)sureAction
- cancelAction:(UIAlertAction*_Nullable)cancelAction
- {
- // 当前控制器是UIAlertController 退出
- UIViewController *currentVC = [[ShortcutManager shareInstance] findCurrentShowingViewController];
- if ([currentVC isKindOfClass:[UIAlertController class]]) {
-
- //获得极致体验服务 请购买云手机(不退出 优先级最高)
- UIAlertController *alertVC = (UIAlertController *)currentVC;
- NSMutableAttributedString *attriMsg = [alertVC valueForKey:@"_attributedMessage"];
- if ([attriMsg.string containsString:@"获得极致体验服务"]) {
- return;
- }
- HLog(@"%@",attriMsg.string);
- [currentVC dismissViewControllerAnimated:NO completion:nil];
- }
-
- self.alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
- if (atbTitle)
- {
- [self.alertController setValue:atbTitle forKey:@"_attributedTitle"];
- }
-
- if (atbmessage)
- {
- [self.alertController setValue:atbmessage forKey:@"_attributedMessage"];
- }
-
- UIView *subView1 = self.alertController.view.subviews[0];
- if (subView1 && [subView1 subviews])
- {
- UIView *subView2 = subView1.subviews[0];
- if (subView2 && [subView2 subviews])
- {
- UIView *subView3 = subView2.subviews[0];
- if (subView3 && [subView3 subviews])
- {
- UIView *subView4 = subView3.subviews[0];
- if (subView4 && [subView4 subviews])
- {
- UIView *subView5 = subView4.subviews[0];
- if (subView5 && [[subView5 subviews] count] > 1)
- {
- for (UIView *msg in subView5.subviews)
- {
- if ([msg isKindOfClass:[UILabel class]])
- {
- NSArray *trmp = [self getAllIvar:msg];
-
- for (NSDictionary *dict in trmp)
- {
- if ([[dict allKeys] containsObject:@"_content"])
- {
- NSAttributedString *dsfds = [dict objectForKey:@"_content"];
- if ([atbTitle.string isEqualToString:dsfds.string])
- {
- [(UILabel*)msg setTextAlignment:(tilteAlignment)];
- }
- else if ([atbmessage.string isEqualToString:dsfds.string])
- {
- if (((UILabel*)msg).numberOfLines == 0)
- {
- [(UILabel*)msg setTextAlignment:(messageAlignment)];
- }
- else if (((UILabel*)msg).numberOfLines == 1)
- {
- [(UILabel*)msg setTextAlignment:NSTextAlignmentCenter];
- }
- else
- {
- [(UILabel*)msg setTextAlignment:(NSTextAlignmentCenter)];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- if (sureAction)
- {
- [self.alertController addAction:sureAction];
- }
-
- if (cancelAction)
- {
- [self.alertController addAction:cancelAction];
- }
-
- // 弹窗边框
- UIView *subview = self.alertController.view.subviews.firstObject;
- UIView *alertContentView = subview.subviews.firstObject;
- alertContentView.layer.cornerRadius = 10;
- // alertContentView.layer.masksToBounds = YES;
- alertContentView.layer.shadowColor = [UIColor colorWithRed:30/255.0 green:32/255.0 blue:34/255.0 alpha:1.0].CGColor;
- alertContentView.layer.shadowOffset = CGSizeMake(0,0);
- alertContentView.layer.shadowOpacity = 1;
- alertContentView.layer.shadowRadius = 7;
- // 弹窗背景颜色
- if (@available(iOS 13.0, *)) {
- self.alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
- }
-
- [self presentViewController:self.alertController animated:YES completion:nil];
- }
- #pragma mark - 屏幕旋转相关
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
- return UIInterfaceOrientationPortrait;
- }
- - (BOOL)shouldAutorotate {
- if (canRate)/*画面发现变化 状态变为YES*/
- {
- canRate = NO;/*关键点 只能旋转一次*/
-
- return YES;
- }
-
- //是否允许转屏
- return NO;/*平时禁止*/
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return
- UIInterfaceOrientationMaskPortrait |
- UIInterfaceOrientationMaskLandscapeLeft |
- UIInterfaceOrientationMaskLandscapeRight;
- }
- #pragma mark -- /* 屏幕旋转通知接收函数*/
- - (void)orientationChanged:(NSNotification *)notification
- {
- KyoLog(@"rotated");
- }
- - (void)setDeviceOrientation:(UIDeviceOrientation)orientationPortrait
- {
- mainBlock(^{
- UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
- //isPortraitMode
- BOOL ScreenMode = ((UIDeviceOrientation)orientation == orientationPortrait);
-
- NSNumber *value = nil;
- if (ScreenMode)
- {
- }
- else
- {
- self.adjustTime = 3;
- if (orientationPortrait == UIDeviceOrientationLandscapeLeft){
- [self->mPlayerView setLanMas_makeWithImageRate:16.0/9.0 isOpenVirtual:[self->deviceModel isOpenVirtualKey] isUsageMode:[self->deviceModel isOpenUsageMode]];
- // [self.basebgView mas_remakeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(0);
- // make.right.mas_equalTo(0);
- // make.top.mas_equalTo(0);
- // make.bottom.mas_equalTo(0);
- // }];
- /*悬浮按钮旋转*/
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self reSetPlayerViewFloatBtnFrame];
- });
-
- [self->mPlayerView.controlBtn setHidden:NO];
-
- }else{
- [self->mPlayerView setPoMas_makeWithImageRate:9.0/16.0 isOpenVirtual:[self->deviceModel isOpenVirtualKey] isUsageMode:[self->deviceModel isOpenUsageMode]];
- // [self.basebgView mas_remakeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(0);
- // make.right.mas_equalTo(0);
- // make.top.mas_equalTo(0);
- // make.bottom.mas_equalTo(0);
- // }];
- }
- self->canRate = YES;/*关键点 设置临时允许*/
- value = [NSNumber numberWithInteger:orientationPortrait];//横竖屏值设置
- [[UIDevice currentDevice] setValue:value forKey:@"orientation"];/*先将状态栏旋转(影响系统通知弹框方向)*/
- [[NSNotificationCenter defaultCenter] postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];/*发送通知*/
- }
- });
- }
- /*上传用户设置的分辨率*/
- - (void)uploadPhoneReslotingsWithWidth:(NSInteger)width high:(NSInteger)high userCardId:(NSInteger)userCardId dpi:(NSInteger)dpi resolvingPowerId:(NSInteger)resolvingPowerId{
- NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
- [params setObject:[NSNumber numberWithInteger:userCardId] forKey:@"userCardId"];
- [params setObject:[NSNumber numberWithInteger:width] forKey:@"width"];
- [params setObject:[NSNumber numberWithInteger:high] forKey:@"high"];
- [params setObject:[NSNumber numberWithInteger:dpi] forKey:@"dpi"];
- [params setObject:[NSNumber numberWithInteger:resolvingPowerId] forKey:@"resolvingPowerId"];
- [[UseAccountManage shareInstance] CommonPostCallBackCode:PostUploadPhoneResolvingsAPI
- Parameters:params
- success:^(id _Nonnull responseObject) {
- if (CODE != 0) {
- [[UseAccountManage shareInstance] CommonPostCallBackCode:PostUploadPhoneResolvingsAPI
- Parameters:params
- success:^(id _Nonnull responseObject) {
- }
- failure:^(NSError * _Nonnull error) {
- }];
- }
- }
- failure:^(NSError * _Nonnull error) {
- [[UseAccountManage shareInstance] CommonPostCallBackCode:PostUploadPhoneResolvingsAPI
- Parameters:params
- success:^(id _Nonnull responseObject) {
- }
- failure:^(NSError * _Nonnull error) {
- }];
- }];
- // PostUploadPhoneResolvingsAPI
- }
- /*设置设备的分辨率*/
- - (void)setPhoneReslotingsInWebsocketWidth:(NSInteger)width high:(NSInteger)high dpi:(NSInteger)dpi{
- HLog(@"\n---设置设备的分辨率--width:%ld---high:%ld---dpi:%ld-",width,high,dpi);
- [self.commandChannelManager rc_sendData:[RCCommandHelp setPhoneSizecommandWithWidth:width
- high:high
- dpi:dpi]];
- }
- /*切换连接方式*/
- - (void)connectTypeChange{
- [self reconnectDevice];
- }
- - (void)cloudPhonechangeVPNNotification:(NSNotification *)notification{
- if (deviceModel.vpnMode!=0) {
- return;
- }else{
- NSDictionary *dict = [notification userInfo];
- if ([[dict allKeys] containsObject:@"data"])
- {
- NSDictionary *data = [dict objectForKey:@"data"];
-
- if ([[data allKeys] containsObject:@"userCardId"]) {
-
- NSInteger userCardId = [[data objectForKey:@"userCardId"] integerValue];
- if (deviceModel.phoneId == userCardId) { // 通知是否是当前设备
-
- if ([[data allKeys] containsObject:@"vpnStatus"])
- {
- NSInteger tempvpnStatus = [[data objectForKey:@"vpnStatus"] integerValue];
-
- if (tempvpnStatus != self.vpnStatus) {
- self.vpnStatus = tempvpnStatus;
- [self reconnectDevice];
- }
- }
- }
- }
-
- }
- }
- }
- #pragma mark - UITextFieldDelegate 透传输入法委托
- //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
- //
- // /*长度为0时表示删除内容*/
- // if (string.length > 0){
- // NSString *replaceStr = [textField.text substringWithRange:range];
- // HLog(@"\n000000要增加的文字:--%@-------",replaceStr);
- // replaceStr = [replaceStr stringByReplacingOccurrencesOfString:@" " withString:@""];
- // HLog(@"\n111111要增加的文字:--%@-------",replaceStr);
- // for (NSInteger nFori = 0; nFori < replaceStr.length; nFori++) {
- // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
- // [self.businessCommandChannelManager rc_sendData:dataStr];
- // }
- // HLog(@"\n-----输入内容:--%@-------",string);
- // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:string];
- // [self.businessCommandChannelManager rc_sendData:dataStr];
- // }
- // else{
- // HLog(@"\n-----删除:--%ld-------",range.length);
- // NSInteger needDeleteLength = range.length;
- // for (NSInteger nFori = 0; nFori < needDeleteLength; nFori++) {
- // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
- // [self.businessCommandChannelManager rc_sendData:dataStr];
- //
- // /*初始内容无法删除问题处理*/
- // hidenTextField.text = @"1234";
- // hidenTextFieldOldStr = @"1234";
- //
- // /*如果两者内容差距较大 是否会有删除后出现两者内容不一样的情况*/
- // if (![hidenTextField.text isEqualToString:hidenTextFieldOldStr]){
- // /*两者不相等时需要做等值处理*/
- // hidenTextFieldOldStr = hidenTextField.text;
- // }
- // }
- // }
- //
- // return YES;
- //}
- - (void)textFieldDidEndEditing:(UITextField *)textField{
- HLog(@"\n-----输入法透传 1111111 关闭键盘-------");
- NSString *dataStr = [RCCommandHelp commandClosePhoneKeyboad];
- [self.businessCommandChannelManager rc_sendData:dataStr];
- }
- -(BOOL)prefersHomeIndicatorAutoHidden {
- return YES;
- }
- @end
|