webRtcManager.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. //
  2. // webRtcManager.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/9/5.
  6. //
  7. #import "webRtcManager.h"
  8. #import "webRtcManager+StatisticsReport.h"
  9. #import "RcGameWQKeyChain.h"
  10. #import "errorAlertTool.h"
  11. #import "webRtcManager+downloadNasFile.h"
  12. #import "nasMixUploadManager.h"
  13. #import "nasUploadFileManager.h"
  14. #import "nasDownloadFileManager.h"
  15. @interface webRtcManager ()<MediaStreamClientEventsDelegate>
  16. {
  17. NSMutableArray *commandSendCheckArr;//需要检测任务是否发出的的指令
  18. NSTimer *linkCheckSecondTimer; // 检测链接状态
  19. NSInteger tryRelinkNum;//重连次数
  20. }
  21. //第一次链接设备 要发送指令信息 实现单点登录
  22. @property (nonatomic, assign)BOOL didSendfristMsg;
  23. @end
  24. @implementation webRtcManager
  25. + (instancetype)shareManager {
  26. static webRtcManager *_instance;
  27. static dispatch_once_t onceToken;
  28. dispatch_once(&onceToken, ^{
  29. _instance = [[self alloc] init];
  30. });
  31. return _instance;
  32. }
  33. - (instancetype)init {
  34. if (self = [super init]) {
  35. //[self registeNotification];
  36. tryRelinkNum = 0;
  37. //2.客户端开始写日志
  38. [ksharedAppDelegate.WebRtcLogger start];
  39. HLog(@"webrtc :%@",ksharedAppDelegate.WebRtcLogger)
  40. _webRtcChannelSessionId = [iTools getNowTimeStampString];
  41. _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
  42. [_mediaStream setEventDelegate:self];
  43. linkCheckSecondTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
  44. [[NSRunLoop currentRunLoop] addTimer:linkCheckSecondTimer forMode:NSRunLoopCommonModes];
  45. }
  46. return self;
  47. }
  48. #pragma mark 十秒一次的timer检测
  49. - (void)timerChange{
  50. [self checkChannelLinkStateFun];
  51. [self checkAllTaskFun];
  52. }
  53. #pragma mark 检测链接是否OK
  54. - (void)checkChannelLinkStateFun
  55. {
  56. if(_channelState != RTCDataChannelStateOpen
  57. ||(_ConnectionState != RTCIceConnectionStateConnected
  58. && _ConnectionState != RTCIceConnectionStateCompleted)
  59. ){
  60. if(!_didReportWebRtcFailType){//还没上报过通道链接情况
  61. tryRelinkNum ++;
  62. if(tryRelinkNum == 2){
  63. _didReportWebRtcFailType = YES;
  64. KWeakSelf
  65. globalBlock(^{
  66. [[addLogObject shareInstance] gotoAddLogFunBySuccess:^(NSString * _Nonnull key) {
  67. [weakSelf reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:self->_webRtcChannelSessionId withLogKey:key];
  68. }];
  69. });
  70. //检测盒子心跳
  71. [self checkBoxHeartbeatFun];
  72. }
  73. }
  74. [self relinkWebRtcFun];
  75. }
  76. }
  77. #pragma mark 关闭链接
  78. - (void)closeLinkWebRtcFun
  79. {
  80. if((_ConnectionState == RTCIceConnectionStateConnected
  81. && _ConnectionState == RTCIceConnectionStateCompleted)
  82. || _channelState == RTCDataChannelStateOpen)
  83. {
  84. KWeakSelf
  85. mainBlock(^{
  86. [weakSelf.mediaStream disconnect];
  87. });
  88. }
  89. }
  90. #pragma mark 开始链接
  91. - (void)beginToLinkWebRtcFun
  92. {
  93. KWeakSelf
  94. mainBlock(^{
  95. [weakSelf secondBeginToLinkWebRtcFun];
  96. });
  97. }
  98. - (void)secondBeginToLinkWebRtcFun
  99. {
  100. if(ksharedAppDelegate.isWebSockLinkOKAginType
  101. || !ksharedAppDelegate.DeviceWebRtcMsgMod){
  102. return;
  103. }
  104. webRtcMsgModel * _webRtcMsgMod = ksharedAppDelegate.DeviceWebRtcMsgMod;
  105. webrtcServerModel * webrtcServerMod = ksharedAppDelegate.bestWebrtcServerModel;
  106. //链接用
  107. NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",webrtcServerMod.signallingIp,webrtcServerMod.signallingPort];
  108. NSURL *url = [NSURL URLWithString:signallingUrl];
  109. //ice用
  110. NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",webrtcServerMod.turnIp,webrtcServerMod.turnPort];
  111. NSMutableDictionary *ice = [NSMutableDictionary new];
  112. if(iceUrl){
  113. [ice setValue:iceUrl forKey:@"CHINANET"];
  114. [ice setValue:iceUrl forKey:@"CMNET"];
  115. [ice setValue:iceUrl forKey:@"UNICOM"];
  116. }
  117. NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
  118. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"webrtc channel startUploadChannel--%@",signallingUrl]];
  119. //1.盒子开始写20秒日志
  120. [_mediaStream setCardLogToFile:@"/sdcard/webrtc_box.log" captureTime:@"20"];
  121. //2.客户端开始写日志
  122. [ksharedAppDelegate.WebRtcLogger start];
  123. HLog(@"webrtc :%@ --- channl start:%@",ksharedAppDelegate.WebRtcLogger,url)
  124. //vclusters 信令不鉴权 写不写都OK
  125. NSInteger result = [_mediaStream startUploadChannel:url ice:ice sn:roomName token:@"vclusters"];
  126. HLog(@"webrtc 发起连接 result:%ld",result)
  127. [_mediaStream setShouldGetStats:YES];
  128. }
  129. - (void)relinkWebRtcFun{
  130. ksharedAppDelegate.isWebSockLinkOKAginType = NO;
  131. if(!_isChangeBoxType){
  132. //客户端停止写日志
  133. [ksharedAppDelegate.WebRtcLogger stop];
  134. [cachesFileManager writeLogsWithMsg:@"webrtc channel relinkWebRtcFun"];
  135. [self beginToLinkWebRtcFun];
  136. }
  137. }
  138. #pragma mark webrtc P2P通道发送消息
  139. - (void)send_data:(NSString *)dataStr
  140. {
  141. [_mediaStream sendData:dataStr];
  142. HLog(@"客户端发出命令:%@",dataStr);
  143. }
  144. #pragma mark 盒子链接成功后需要处理的各种各样事情
  145. - (void)handlAllMsgAfterDidLinkFun
  146. {
  147. _isRebootIngType = NO;
  148. _isResetingType = NO;
  149. _isChangeBoxType = NO;
  150. tryRelinkNum = 0;
  151. ksharedAppDelegate.isWebSockLinkOKAginType = YES;
  152. //获取云机尺寸 兼容 720*1080 &1080*1920 不同分辨率的展示和触控
  153. NSString *getPhoneSizeStr = [RCCommandHelp getPhoneSizecommand];
  154. [self send_data:getPhoneSizeStr];
  155. //判断是否为需要改机
  156. BOOL isNeedRandomChangeParams = [HWDataManager getBoolWithKey:Const_need_random_Change_Params];
  157. if(isNeedRandomChangeParams)
  158. {
  159. NSString *commondStr = @"{\"type\":\"randomChangeParams\"}";
  160. [self send_data:commondStr];
  161. [HWDataManager setBoolWithKey:Const_need_random_Change_Params value:NO];
  162. }
  163. [self fristConnectNeedGiveAMsgFun];
  164. [self updateCopydata];
  165. // 报链接失败 后面又连接上了
  166. [[errorAlertTool shareInstance] dismissErrorAlertFun];
  167. //处理相册备份
  168. [[nasBackupsManager shareInstance] AutohandlePhotosBackupsFun];
  169. //获取磁盘外挂
  170. [self getExtraFilesListFun];
  171. [self getBaseInfoFun];
  172. [self getTvStatusFun];
  173. [self closeBoxHeartbeatReStartViewFun];
  174. if(ksharedAppDelegate.needToShowReStratSucType){
  175. ksharedAppDelegate.needToShowReStratSucType = NO;
  176. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  177. [self showReStartSucFun];
  178. });
  179. }
  180. }
  181. #pragma mark 盒子第一次连接成功 给ws发送信息 单点登录 把其他账号挤下去
  182. - (void)fristConnectNeedGiveAMsgFun{
  183. if(!_didSendfristMsg )
  184. {
  185. [self getSysInfoFun];
  186. // NSString *curOaidStr = [RcGameWQKeyChain getOaidStringFun];
  187. // if(!curOaidStr){
  188. // curOaidStr = @"";
  189. // }
  190. // //未调通挤下线
  191. // NSString *commondStr = [[NSString alloc] initWithFormat:@"{\"type\":\"login\",\"value\":\"%@\"}",curOaidStr];
  192. // [self send_data:commondStr];
  193. // [self addCommandSendTaskFunWithType:@"offline_notification" WithCommandStr:commondStr];
  194. _didSendfristMsg = YES;
  195. [self getPreferredLanguage];
  196. NSString *commondStr2 = @"{\"type\":\"TvStatus\"}";
  197. [self send_data:commondStr2];
  198. }
  199. }
  200. #pragma mark 语言和市区 同步云机
  201. -(void)getPreferredLanguage
  202. {//{"data":{"language":"zh-CN","timeZone":"Etc/GMT+8"},"type":"setLanguages"}
  203. // iOS 获取设备当前语言的代码
  204. NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
  205. HLog(@"当前语言:%@", preferredLanguage);
  206. //en-US 英文 ja-JP 日文
  207. NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  208. NSLog(@"arLanguages:%@",arLanguages);
  209. ///获取设备当前地区的代码和APP语言环境
  210. NSString *languageCode = [NSLocale preferredLanguages][0];
  211. //目前支持 中文(简体 繁体) 英文 日语
  212. if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
  213. {
  214. preferredLanguage = @"zh-CN";
  215. }
  216. else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
  217. {
  218. preferredLanguage = @"zh-HK";
  219. }
  220. else if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  221. {
  222. preferredLanguage = @"ja-JP";
  223. }
  224. else{
  225. preferredLanguage = @"en-US";
  226. }
  227. // if([languageCode rangeOfString:preferredLanguage].location != NSNotFound){
  228. // preferredLanguage = languageCode;
  229. // }
  230. // else{
  231. // preferredLanguage = @"en-US";
  232. // }
  233. NSString*gmtStr = [self UTCOffset];
  234. HLog(@"%@",gmtStr);
  235. // //获取名字,如“GMT+08:00
  236. NSString *commondStr = [NSString stringWithFormat:@"{\"type\":\"setLanguages\",\"data\":{\"language\":\"%@\",\"timeZone\":\"%@\"}}",preferredLanguage,gmtStr];
  237. [self send_data:commondStr];
  238. }
  239. #pragma mark 获取云机系统镜像等信息
  240. - (void)getSysInfoFun
  241. {
  242. NSString *commondStr = @"{\"type\":\"getSysInfo\"}";
  243. [self send_data:commondStr];
  244. }
  245. -(NSString *)UTCOffset {
  246. NSTimeZone *localTZ = [NSTimeZone localTimeZone];
  247. float offset = localTZ.secondsFromGMT/3600.0;
  248. if(offset > 0){
  249. return [NSString stringWithFormat:@"Etc/GMT+%g",offset];
  250. }
  251. return [NSString stringWithFormat:@"Etc/GMT%g",offset];
  252. }
  253. #pragma mark 收到系统信息消息回调处理
  254. - (void)getCouldPhoneSysInfoResponseFun:(NSDictionary *)dataDict{
  255. couldphoneSysInfoModel *model = [[couldphoneSysInfoModel alloc] initWithDictionary:dataDict error:nil];
  256. //[[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
  257. // NSString *hostImgVer = model.data.data.hostImgVer;
  258. // NSString *MyNewVersion = model.data.data.MyNewVersion;
  259. NSString *hostImgVer = model.data.hostImgVer;
  260. NSString *MyNewVersion = model.data.MyNewVersion;
  261. //test code
  262. // hostImgVer = @"1.2.3";
  263. // MyNewVersion = @"1.2.0";
  264. //判断当前版本号 待更新版本
  265. if (!hostImgVer || hostImgVer.length < 3
  266. ||!MyNewVersion || MyNewVersion.length < 3) {
  267. return;
  268. }
  269. NSArray *versionArr = [hostImgVer componentsSeparatedByString:@"."];
  270. NSArray *MyNewVersionArr = [MyNewVersion componentsSeparatedByString:@"."];
  271. NSInteger versionArrCount = versionArr.count;
  272. NSInteger MyNewVersionArrCount = MyNewVersionArr.count;
  273. NSInteger maxCount = versionArrCount < MyNewVersionArrCount ? versionArrCount:MyNewVersionArrCount;
  274. BOOL isNeedShowType = NO;
  275. //判断是否要更新镜像框
  276. if(maxCount > 0){
  277. for (int i=0; i<maxCount; i++) {
  278. NSString * numberStr1 = versionArr[i];
  279. NSString * numberStr2 = MyNewVersionArr[i];
  280. if(numberStr2.intValue > numberStr1.intValue){
  281. isNeedShowType =YES;
  282. break;
  283. }
  284. }
  285. }
  286. if(isNeedShowType){
  287. ksharedAppDelegate.isNeedShowImageNewType = YES;
  288. }
  289. //是否禁用文件传输 (1.3以及以上的镜像可以使用文件传输)
  290. if(versionArr.count >= 3)
  291. {
  292. NSString * oneStr = versionArr[0];
  293. NSString * twoStr = versionArr[1];
  294. NSString * threeStr = versionArr[2];
  295. if(oneStr.integerValue <=1 && twoStr.integerValue <=3 && threeStr.integerValue <=0){//禁用
  296. ksharedAppDelegate.DisabledFileTransferType = YES;
  297. if(MyNewVersionArr.count >= 3)
  298. {
  299. NSString * newOneStr = MyNewVersionArr[0];
  300. NSString * newTwoStr = MyNewVersionArr[1];
  301. NSString * newThreeStr = MyNewVersionArr[2];
  302. if(newOneStr.integerValue >=1 && newTwoStr.integerValue >=3 && newThreeStr.integerValue >= 1){
  303. ksharedAppDelegate.isImageNewFor130 = YES;
  304. }
  305. else{
  306. ksharedAppDelegate.isImageNewFor130 = NO;
  307. }
  308. }
  309. }
  310. else{
  311. ksharedAppDelegate.DisabledFileTransferType = NO;
  312. }
  313. //判断镜像是否为1.4.4以后
  314. if(oneStr.integerValue >=2){
  315. ksharedAppDelegate.isImageFor144Orlater = YES;
  316. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_image_version_for_new_token) value:YES];
  317. }
  318. else if(twoStr.integerValue > 4){
  319. ksharedAppDelegate.isImageFor144Orlater = YES;
  320. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_image_version_for_new_token) value:YES];
  321. }
  322. else if(threeStr.integerValue >= 4){
  323. ksharedAppDelegate.isImageFor144Orlater = YES;
  324. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_image_version_for_new_token) value:YES];
  325. }
  326. else{
  327. ksharedAppDelegate.isImageFor144Orlater = NO;
  328. }
  329. }
  330. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
  331. }
  332. #pragma mark 添加消息重复机制
  333. -(void)addCommandSendTaskFunWithType:(NSString*)type WithCommandStr:(NSString*)commandStr
  334. {
  335. if(!commandSendCheckArr){
  336. commandSendCheckArr = [NSMutableArray new];
  337. }
  338. BOOL didAddType = NO;
  339. for (commandSendCheckModel *model in commandSendCheckArr) {
  340. if([model.type isEqualToString:type]){
  341. didAddType = YES;
  342. model.reSendNum = 0;
  343. model.sendTimerStamp = [iTools getNowTimeStamp];
  344. break;
  345. }
  346. }
  347. if(!didAddType){
  348. commandSendCheckModel *model = [commandSendCheckModel new];
  349. model.commandStr = commandStr;
  350. model.type = type;
  351. model.reSendNum = 0;
  352. model.sendTimerStamp = [iTools getNowTimeStamp];
  353. [commandSendCheckArr addObject:model];
  354. }
  355. }
  356. #pragma mark 删除代理确认收到的消息
  357. -(void)deleteCommandSendTaskFunWith:(NSString*)type
  358. {
  359. if(commandSendCheckArr && commandSendCheckArr.count >0){
  360. NSArray *taskArr = [NSArray arrayWithArray:commandSendCheckArr];
  361. for (commandSendCheckModel *model in taskArr) {
  362. if([type isEqualToString:model.type]){
  363. [commandSendCheckArr removeObject:model];
  364. }
  365. }
  366. }
  367. }
  368. #pragma mark 复制手机消息到云机
  369. - (void)updateCopydata{
  370. UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  371. NSString *str = [pasteboard string];
  372. HLog(@"__________%s______%@____",__func__,str);
  373. if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound)
  374. {
  375. str = nil;
  376. }
  377. if (str && str.length >0)
  378. {
  379. //HLog(@"hxd111 cutting %@",str);
  380. /*发送数据*/
  381. NSString *dataStr = [RCCommandHelp commandCuttingWithContent:str];
  382. [self send_data:dataStr];
  383. //pasteboard.string = @"";
  384. }
  385. }
  386. #pragma mark 获取云机以及外挂磁盘
  387. - (void)getExtraFilesListFun
  388. {
  389. // NSString *ExtraCommondStr = [RCCommandHelp getExtraFilesList];
  390. // [self send_data:ExtraCommondStr];
  391. //改走http方案
  392. [[NSNotificationCenter defaultCenter] postNotificationName:getExtraFilesDoneNotification object:nil];/*发送通知*/
  393. }
  394. #pragma mark 获取到云机以及外挂磁盘信息
  395. - (void)getExtraFilesResponseFun:(NSDictionary *)dataDict
  396. {
  397. cloudPhoneExtraFileListModel *model = [[cloudPhoneExtraFileListModel alloc] initWithDictionary:dataDict error:nil];
  398. ksharedAppDelegate.cloudPhoneExtraFileListMod = model;
  399. [[NSNotificationCenter defaultCenter] postNotificationName:getExtraFilesDoneNotification object:dataDict];/*发送通知*/
  400. }
  401. #pragma mark 获取云机基本信息
  402. - (void)getBaseInfoFun
  403. {
  404. NSString *commondStr = @"{\"type\":\"getBaseInfo\"}";
  405. [self send_data:commondStr];
  406. }
  407. #pragma mark 获取到云机基本信息
  408. - (void)getCouldPhoneBaseInfoResponseFun:(NSDictionary *)dataDict
  409. {
  410. couldPhoneBaseInfoModel *model = [[couldPhoneBaseInfoModel alloc] initWithDictionary:dataDict error:nil];
  411. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneBaseInfoNotification object:model];
  412. }
  413. #pragma mark 获取到TV投屏状态
  414. - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
  415. {
  416. TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
  417. ksharedAppDelegate.TvStatusMod = model;
  418. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
  419. // if(![model.msg containsString:@"PushStreamBActivity"])
  420. // {
  421. // return;
  422. // }
  423. //
  424. // UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  425. // if([topVc isKindOfClass:[PlayerViewController class]]){
  426. // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  427. // }
  428. }
  429. #pragma mark 重启云机
  430. - (void)needToRebootFun
  431. {
  432. NSString *commondStr = @"{\"type\":\"reboot\"}";
  433. [self send_data:commondStr];
  434. //添加到任务监听
  435. [self addCommandSendTaskFunWithType:@"reboot" WithCommandStr:commondStr];
  436. //数据埋点
  437. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Cloud_restart"];
  438. _isRebootIngType = YES;
  439. }
  440. #pragma mark 恢复出厂设置
  441. - (void)needToResetFun
  442. {
  443. NSString *commondStr = @"{\"type\":\"reset\"}";
  444. [self send_data:commondStr];
  445. //添加到任务监听
  446. [self addCommandSendTaskFunWithType:@"reset" WithCommandStr:commondStr];
  447. //数据埋点
  448. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Cloud_restore_factory"];
  449. _isResetingType = YES;
  450. }
  451. #pragma mark 云机截图保存到云机图库
  452. - (void)screenshotInCloudPhoneFun{
  453. NSString*taskUid = [iTools getTaskUidStr];
  454. NSString *commondStr = [RCCommandHelp commandCloudPhoneScreenshotWithTaskUid:taskUid];
  455. [self send_data:commondStr];
  456. }
  457. #pragma mark 获取TV投屏状态
  458. - (void)getTvStatusFun
  459. {
  460. NSString *commondStr = @"{\"type\":\"TvStatus\"}";
  461. [self send_data:commondStr];
  462. }
  463. #pragma mark 关闭TV投屏状态
  464. - (void)offTvFun
  465. {
  466. NSString *commondStr = @"{\"type\":\"TvOff\"}";
  467. [self send_data:commondStr];
  468. }
  469. #pragma mark 开启TV投屏状态
  470. - (void)onTvFun
  471. {
  472. NSString *commondStr = @"{\"type\":\"wakeupTV\"}";
  473. [self send_data:commondStr];
  474. }
  475. #pragma mark 创建备份文件夹
  476. - (void)createBackupsFolderBy:(NSString*)backupsDefaultPath
  477. {
  478. NSString *folderName = backupsDefaultPath;
  479. if(folderName && folderName.length >0){
  480. NSString * commandStr = [RCCommandHelp applyForCreateFolderwithFolderName:folderName];
  481. [self send_data:commandStr];
  482. }
  483. }
  484. #pragma mark 获取备份文件夹列表
  485. - (void)getBackupFolderListFun
  486. {
  487. NSString * commandStr = [RCCommandHelp getCreateFolderList];
  488. [self send_data:commandStr];
  489. }
  490. #pragma mark 创建文件夹回调
  491. - (void)createFolderResponseFun:(NSDictionary *)dataDict
  492. {
  493. couldPhoneCommonModel *model = [[couldPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  494. if(model){
  495. NSNumber *curNum = [NSNumber numberWithInteger:model.status];
  496. [[NSNotificationCenter defaultCenter] postNotificationName:createFolderDoneNotification object:curNum];/*发送通知*/
  497. }
  498. }
  499. - (void)getFolderListResponseFun:(NSDictionary *)dataDict
  500. {
  501. [[NSNotificationCenter defaultCenter] postNotificationName:getFolderListDoneNotification object:dataDict];/*发送通知*/
  502. }
  503. - (void)searchFileListResponseFun:(NSDictionary *)dataDict
  504. {
  505. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListDoneNotification object:dataDict];/*发送通知*/
  506. }
  507. #pragma mark U盘插入相关
  508. - (void)getExtraMediaEventResponseFun:(NSDictionary *)dataDict
  509. {
  510. mainBlock((^{
  511. extraMediaEventModel *model = [[extraMediaEventModel alloc] initWithDictionary:dataDict error:nil];
  512. NSString *tip = nil;
  513. if(model.data.event == 0){
  514. tip = NSLocalizedString(@"disk_insertion_tip",nil);
  515. [self showInsertPopViewFun:model.data.name];
  516. }
  517. else if(model.data.event == 1){
  518. tip = NSLocalizedString(@"disk_extract_tip",nil);
  519. }
  520. else if(model.data.event == 2){
  521. tip = NSLocalizedString(@"disk_save_extract_tip",nil);
  522. }
  523. NSString *totalTips = [[NSString alloc] initWithFormat:@"%@%@",model.data.name,tip];
  524. [[iToast makeText:totalTips] show];
  525. }));
  526. }
  527. #pragma mark 显示插入UI弹框
  528. - (void)showInsertPopViewFun:(NSString*)name
  529. {
  530. if(self->curUSBInsertPopV){
  531. [self->curUSBInsertPopV removeFromSuperview];
  532. self->curUSBInsertPopV = nil;
  533. }
  534. self->curUSBInsertPopV = [[USBInsertPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) withName:name];
  535. [[iTools getKeyWindow] addSubview:self->curUSBInsertPopV];
  536. }
  537. #pragma mark 检测nas任务情况
  538. - (void)checkAllTaskFun
  539. {
  540. HLog(@"checkAllTaskFun");
  541. //处理相册备份
  542. [[nasBackupsManager shareInstance] checkReBackupsFileFun];
  543. //处理上传失败的重新上传
  544. //[[nasUploadFileManager shareInstance] reUploadFileFunByNetWork];
  545. //[[nasDownloadFileManager shareInstance] reDownloadloadFileFunByNetWork];
  546. //if([AudioSessionObject shareManager].isBackgroundType)
  547. {
  548. [self checkFileTransfeTaskFun];
  549. }
  550. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown){
  551. [ksharedAppDelegate MonitorNetworkChangesFun];
  552. }
  553. }
  554. #pragma mark 检测是否正在进行的文件传输任务 设置后台状态
  555. - (void)checkFileTransfeTaskFun
  556. {
  557. BOOL isBackupsingType = [[nasBackupsManager shareInstance] checkBackupsingFun];
  558. BOOL isUploadingType = [[nasMixUploadManager shareManager] checkUploadTaskDoingFun];
  559. BOOL isDownloadingType = [[nasDownloadManager shareManager] isDownLoadIngType];
  560. BOOL isNasDownloadingType = [customDownloadManager shareManager].isDownLoadIngType;
  561. BOOL isBackground = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_working_background)];
  562. if ((isBackupsingType || isUploadingType || isDownloadingType ||isNasDownloadingType) && isBackground) {
  563. HLog(@"后台保活中");
  564. //[cachesFileManager writeLogsWithMsg:@"Background working"];
  565. }
  566. else{
  567. HLog(@"停止后台保活");
  568. //[cachesFileManager writeLogsWithMsg:@"stop Background working"];
  569. //[[AudioSessionObject shareManager] stopBackgroundActiveFun];
  570. }
  571. }
  572. #pragma mark 收到的webrtc消息处理
  573. - (void)handleWebRtcMsgResponseBy:(NSData*)message
  574. {
  575. if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
  576. {
  577. message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
  578. }
  579. NSError *error = nil;
  580. NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
  581. HLog(@"webRtc P2P 通道接收消息:------------------%@",dataDict);
  582. // if([message isKindOfClass:[NSData class]] && [message length] == 0){
  583. // if(type == RCSocketCloudPhoneReceiveTypeForPong)
  584. // {
  585. // [weakSelf keepWebSocketOKFun];
  586. // }
  587. // return;
  588. // }
  589. //
  590. // HLog(@"webSocket指令通道接收消息:------------------\n%@",message);
  591. //
  592. // if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
  593. // {
  594. // message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
  595. // }
  596. //
  597. // NSError *error = nil;
  598. // NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
  599. if(!dataDict){
  600. //[weakSelf handleDownloadResponseFunBy:message];
  601. return;
  602. }
  603. if(![dataDict isKindOfClass:[NSDictionary class]]){
  604. //[__NSCFString allKeys] unrecognized selector sent to ins
  605. return;
  606. }
  607. if(![[dataDict allKeys] containsObject:@"type"]){
  608. return;
  609. }
  610. NSString *messageType = dataDict[@"type"];
  611. if ([messageType isEqualToString:@"cutting"]) {
  612. //[[iToast makeText:@"复制成功"] show];
  613. }
  614. // else if ([messageType isEqualToString:@"forwardMsgRep"]){/*转发的回复*/
  615. //
  616. // cloudPhoneCommonModel *model = [[cloudPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  617. // if(!model){
  618. // return;
  619. // }
  620. //
  621. // if([model.data.msg isEqualToString:@"only one socket"]||
  622. // [model.data.msg isEqualToString:@"only one socket2"]){
  623. // [weakSelf deleteCommandSendTaskFunWith:@"offline_notification"];
  624. // }
  625. // }
  626. // else if ([messageType isEqualToString:@"forwardMsg"]){/*转发*/
  627. // /*获取指令类型*/
  628. // NSString *code = nil;
  629. // if ([[dataDict allKeys] containsObject:@"data"]) {
  630. // NSDictionary *data = dataDict[@"data"];
  631. //
  632. // if([data isKindOfClass:[NSString class]]){
  633. // NSString * dataStr = (NSString*)data;
  634. // if([dataStr isEqualToString:@"offline_notification"]){
  635. // HLog(@"被别人挤下线了");
  636. // [weakSelf LogoutByOtherFun];
  637. // }
  638. //
  639. // return;
  640. // }
  641. // else if ([data isKindOfClass:[NSDictionary class]] && [[data allKeys] containsObject:@"code"]) {
  642. // code = [data objectForKey:@"code"];
  643. //
  644. // if (![code isKindOfClass:[NSString class]]) {
  645. // code = [NSString stringWithFormat:@"%ld",[code integerValue]];
  646. // }
  647. // }
  648. // }
  649. //
  650. // /*获取用户名*/
  651. // NSString *useName = nil;
  652. // if ([[dataDict allKeys] containsObject:@"data"]) {
  653. // NSDictionary *data = dataDict[@"data"];
  654. // if ([[data allKeys] containsObject:@"userName"]) {
  655. // //useName = [data objectForKey:@"userName"];
  656. // }
  657. // }
  658. //
  659. //
  660. // if ([code isEqualToString:@"phoneSizeChange"]){/*分辨率改变*/
  661. // if ([[dataDict allKeys] containsObject:@"data"]) {
  662. // NSDictionary *data = dataDict[@"data"];
  663. // if ([[data allKeys] containsObject:@"width"]) {
  664. // ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
  665. // }
  666. // if ([[data allKeys] containsObject:@"height"]) {
  667. // ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
  668. // }
  669. //
  670. // if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
  671. // CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
  672. // ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
  673. // ksharedAppDelegate.couldPhone_H_PHONE = temp;
  674. // }
  675. // }
  676. // }
  677. // }
  678. else if ([messageType isEqualToString:@"getPhoneSize"] || [messageType isEqualToString:@"setPhoneSize"]){
  679. //NSString *sn = nil;
  680. if([messageType isEqualToString:@"setPhoneSize"]){
  681. self.isDiDChangePhoneSizeType = YES;
  682. }
  683. if ([[dataDict allKeys] containsObject:@"data"]) {
  684. NSDictionary *data = dataDict[@"data"];
  685. if ([[data allKeys] containsObject:@"status"]) {
  686. NSInteger status = [[data objectForKey:@"status"] integerValue];
  687. if (status == 0) {/*不是当前设备直接返回*/
  688. if ([[data allKeys] containsObject:@"width"]) {
  689. ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
  690. }
  691. if ([[data allKeys] containsObject:@"height"]) {
  692. ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
  693. }
  694. if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
  695. CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
  696. ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
  697. ksharedAppDelegate.couldPhone_H_PHONE = temp;
  698. }
  699. }
  700. }
  701. }
  702. }
  703. // else if ([messageType isEqualToString:@"sync_wifi"]){
  704. // [weakSelf sync_wifiBackHandleFun];
  705. // }
  706. // else if ([messageType isEqualToString:@"reProduceText"]){
  707. // if ([[dataDict allKeys] containsObject:@"data"]) {
  708. // NSDictionary *data = dataDict[@"data"];
  709. //
  710. // if ([[data allKeys] containsObject:@"text"]) {
  711. // NSString *pasteboardStr = [data objectForKey:@"text"];
  712. // UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  713. // pasteboard.string = pasteboardStr;
  714. // }
  715. // }
  716. // }
  717. // else if ([messageType isEqualToString:@"downAdnInstallRep"]){
  718. // if ([[dataDict allKeys] containsObject:@"data"]) {
  719. // NSDictionary *data = dataDict[@"data"];
  720. //
  721. // if ([[data allKeys] containsObject:@"status"]) {
  722. // NSString *status = [data objectForKey:@"status"];
  723. // if ([status isEqualToString:@"1"]) {
  724. // mainBlock(^{
  725. // // [[iToast makeText:@"App下载完成"] show];
  726. // });
  727. // }else if ([status isEqualToString:@"0"]){
  728. // mainBlock(^{
  729. // //[[iToast makeText:@"App下载中"] show];
  730. // });
  731. // }
  732. // }
  733. // }
  734. // }
  735. // else if ([messageType isEqualToString:@"shakeit"]){
  736. // HLog(@"\n-----摇一摇成功------");
  737. // }else if ([messageType isEqualToString:@"keyboardFeedbackBean"]){/*调起键盘*/
  738. // HLog(@"\n-----待处理 调起键盘------");
  739. // // [weakSelf keyboardFeedbackBeanFun];
  740. // }else if ([messageType isEqualToString:@"FileRandomReady"]
  741. // ||[messageType isEqualToString:@"FilePartReady"]
  742. // ){/*申请文件上传得到答复*/
  743. // [weakSelf applyUploadFileServiceResponseFun:dataDict];
  744. // }
  745. // else if ([messageType isEqualToString:@"uploadFileRandomRet"]
  746. // ||[messageType isEqualToString:@"uploadFilePartRet"]
  747. // ){/*文件上传得到答复*/
  748. // [weakSelf upLoadFileFunServiceResponseFun:dataDict];
  749. // }
  750. // else if ([messageType isEqualToString:@"backUpFileRandomReady"]
  751. // ||[messageType isEqualToString:@"backUpPartReady"]
  752. // ){/*文件备份得到答复*/
  753. // [weakSelf applyBackupsFileServiceResponseFun:dataDict];
  754. // }
  755. // else if ([messageType isEqualToString:@"backUpFileRandomRet"]
  756. // ||[messageType isEqualToString:@"backUpFilePartRet"]){/*文件备份得到答复*/
  757. // [weakSelf backupsFileFunServiceResponseFun:dataDict];
  758. // }
  759. else if ([messageType isEqualToString:@"getBaseInfo"]){/*获取云机的基本信息*/
  760. [self getCouldPhoneBaseInfoResponseFun:dataDict];
  761. }
  762. else if ([messageType isEqualToString:@"getSysInfo"]){/*获取云机的系统信息*/
  763. [self getCouldPhoneSysInfoResponseFun:dataDict];
  764. }
  765. else if ([messageType isEqualToString:@"TvStatus"]){/*获取TV投屏信息*/
  766. [self getCouldPhoneTvStatusResponseFun:dataDict];
  767. }
  768. else if ([messageType isEqualToString:@"TvOff"]){/*关闭TV投屏*/
  769. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  770. [self getTvStatusFun];
  771. });
  772. }
  773. else if ([messageType isEqualToString:@"wakeupTV"]){/*开启TV投屏*/
  774. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  775. [self getTvStatusFun];
  776. });
  777. }
  778. else if ([messageType isEqualToString:@"reboot"]){/*重启*/
  779. //[weakSelf stopForceStartTimerFun];
  780. }
  781. else if ([messageType isEqualToString:@"mkdir"]){/*创建文件夹*/
  782. [self createFolderResponseFun:dataDict];
  783. }
  784. else if ([messageType isEqualToString:@"getBackupPath"]){/*创建文件夹*/
  785. [self getFolderListResponseFun:dataDict];
  786. }
  787. else if ([messageType isEqualToString:@"search"]){/*创建文件夹*/
  788. [self searchFileListResponseFun:dataDict];
  789. }
  790. else if ([messageType isEqualToString:@"getExtraFiles"]){/*获取云机产品信息*/
  791. [self getExtraFilesResponseFun:dataDict];
  792. }
  793. else if ([messageType isEqualToString:@"extraMediaEvent"]){/*磁盘插拔*/
  794. [self getExtraMediaEventResponseFun:dataDict];
  795. [self getExtraFilesListFun];
  796. }
  797. else if ([messageType isEqualToString:@"reset"]){/**/
  798. [self deleteCommandSendTaskFunWith:@"reset"];
  799. }
  800. else if ([messageType isEqualToString:@"shortcatRep"]){/*截图*/
  801. [[iToast makeText:NSLocalizedString(@"shortcatRep_tip",nil)] show];
  802. }
  803. }
  804. #pragma mark WebRTC 回调 MediaStreamClientEventsDelegate
  805. #pragma mark 不能再这里函数判断 这个是推拉流的
  806. -(void)onChangeConnectionStateFromPeerName:(NSString*)peerName didChangeIceConnectionState:(RTCIceConnectionState)state
  807. {
  808. HLog(@"channel P2P onChangeConnectionStateFromPeerName: state:%ld",state)
  809. self.ConnectionState = state;
  810. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"webrtc channel onChangeConnectionStateFromPeerName:%ld",state]];
  811. switch (state) {
  812. case RTCIceConnectionStateConnected:{
  813. //链接成功
  814. }
  815. break;
  816. case RTCIceConnectionStateCompleted:
  817. //链接完成
  818. break;
  819. case RTCIceConnectionStateFailed:
  820. case RTCIceConnectionStateDisconnected:
  821. case RTCIceConnectionStateClosed:{
  822. if(!_didReportWebRtcFailType && state == RTCIceConnectionStateFailed){//还没上报过通道链接情况
  823. _didReportWebRtcFailType = YES;
  824. KWeakSelf
  825. globalBlock(^{
  826. [[addLogObject shareInstance] gotoAddLogFunBySuccess:^(NSString * _Nonnull key) {
  827. [weakSelf reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:self->_webRtcChannelSessionId withLogKey:key];
  828. }];
  829. });
  830. }
  831. //链接关闭
  832. [self relinkWebRtcFun];
  833. }
  834. break;
  835. default:
  836. break;
  837. }
  838. }
  839. #pragma mark 通道连接状态变化监听
  840. - (void)dataChannelDidChangeFromPeerName:(NSString*)peerName State:(RTCDataChannelState)state
  841. {
  842. HLog(@"webRtc P2P dataChannelDidChangeFromPeerName: state:%ld",state)
  843. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"webrtc channel dataChannelDidChangeFromPeerName:%ld",state]];
  844. self.channelState = state;
  845. switch (state) {
  846. case RTCDataChannelStateConnecting:
  847. {
  848. }
  849. break;
  850. case RTCDataChannelStateOpen:
  851. {
  852. //链接成功
  853. [self handlAllMsgAfterDidLinkFun];
  854. //客户端停止写日志
  855. [ksharedAppDelegate.WebRtcLogger stop];
  856. }
  857. break;
  858. case RTCDataChannelStateClosing:
  859. {
  860. }
  861. break;
  862. case RTCDataChannelStateClosed:
  863. {
  864. //链接断开
  865. [self relinkWebRtcFun];
  866. }
  867. break;
  868. default:
  869. break;
  870. }
  871. }
  872. -(void)onChannelDataFromPeerName:(NSString*)peerName buffer:(RTC_OBJC_TYPE(RTCDataBuffer) *)buffer
  873. {
  874. //HLog(@"onIceConnectedFromPeerName:%@",buffer.data);
  875. if(buffer && buffer.data){
  876. KWeakSelf
  877. mainBlock(^{
  878. [weakSelf handleWebRtcMsgResponseBy:buffer.data];
  879. });
  880. }
  881. }
  882. -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats
  883. {
  884. //HLog(@"didGetStats:%@",stats)
  885. if(!_didReportWebRtcOKType
  886. && (self.ConnectionState == RTCIceConnectionStateConnected ||self.ConnectionState == RTCIceConnectionStateCompleted)){
  887. [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats withSessionId:_webRtcChannelSessionId withLogKey:@""];
  888. _didReportWebRtcOKType = YES;
  889. _didReportWebRtcFailType = NO;//链接成功后 失败要重新上报
  890. [_mediaStream setShouldGetStats:NO];
  891. }
  892. }
  893. -(void)onAuthResultFromPeerName:(NSString*)peerName code:(int)code descriptions:(NSString*)descriptions
  894. {
  895. //HLog(@"webRtc P2P onAuthResultFromPeerName")
  896. }
  897. - (void)connectionChange:(NSString*)peerName
  898. didChangeLocalCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)local
  899. remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote
  900. lastReceivedMs:(int)lastDataReceivedMs
  901. changeReason:(NSString *)reason
  902. {
  903. //HLog(@"webRtc P2P didChangeLocalCandidate")
  904. [self reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcChannelSessionId withLogKey:@""];
  905. }
  906. #pragma mark 检测盒子的心跳情况
  907. - (void)checkBoxHeartbeatFun
  908. {
  909. if(ksharedAppDelegate.didShowBoxHeartbeatAlertType
  910. ||[webRtcManager shareManager].isResetingType
  911. ||[webRtcManager shareManager].isRebootIngType
  912. || [ksharedAppDelegate didShowImageRenewViewFun]){
  913. return;
  914. }
  915. //1.隐私模式密码界面 3秒检测一次是否输入完成密码了
  916. if(ksharedAppDelegate.isDidShowPwdType){
  917. KWeakSelf
  918. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  919. [weakSelf checkBoxHeartbeatFun];
  920. });
  921. return;
  922. }
  923. // [[BoxHeartbeatAlertTool shareInstance] showBoxHeartbeatAlertFun:1 didClickBut:^(NSInteger tag) {
  924. //
  925. // }];
  926. if(ksharedAppDelegate.isWebSockLinkOKAginType && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  927. return;
  928. }
  929. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  930. KWeakSelf
  931. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryHeartbeat Parameters:paraDict success:^(id _Nonnull responseObject){
  932. queryHeartbeatModel *heartbeatMod = [[queryHeartbeatModel alloc] initWithDictionary:responseObject error:nil];
  933. if(heartbeatMod && heartbeatMod.data){
  934. [weakSelf checkBoxHeartbeatToShowPopViewFunBy:heartbeatMod];
  935. }
  936. } failure:^(NSError * _Nonnull error) {
  937. }];
  938. }
  939. #pragma mark 根据盒子的心跳情况 显示异常谈了
  940. - (void)checkBoxHeartbeatToShowPopViewFunBy:(queryHeartbeatModel*)heartbeatMod
  941. {
  942. if(!heartbeatMod || !heartbeatMod.data){
  943. return;
  944. }
  945. if (//!heartbeatMod.data.frpStatus&&
  946. !heartbeatMod.data.hostAgentStatus
  947. &&!heartbeatMod.data.containerAgentStatus) {//全部异常
  948. [[BoxHeartbeatAlertTool shareInstance] showBoxHeartbeatAlertFun:1 didClickBut:^(NSInteger tag) {
  949. }];
  950. }
  951. else if (heartbeatMod.data.hostAgentStatus
  952. //&& !heartbeatMod.data.frpStatus
  953. && !heartbeatMod.data.containerAgentStatus) {//frp异常
  954. [[BoxHeartbeatAlertTool shareInstance] showBoxHeartbeatAlertFun:2 didClickBut:^(NSInteger tag) {
  955. }];
  956. }
  957. }
  958. #pragma mark 显示重启成功
  959. - (void)showReStartSucFun
  960. {
  961. //1.隐私模式密码界面 3秒检测一次是否输入完成密码了
  962. if(ksharedAppDelegate.isDidShowPwdType){
  963. KWeakSelf
  964. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  965. [weakSelf showReStartSucFun];
  966. });
  967. return;
  968. }
  969. [self closeBoxHeartbeatReStartViewFun];
  970. BoxHeartbeatReStartSucView *view = [[BoxHeartbeatReStartSucView alloc] init];
  971. [ksharedAppDelegate.window addSubview:view];
  972. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  973. make.left.mas_equalTo(0.f);
  974. make.bottom.mas_equalTo(0.f);
  975. make.right.mas_equalTo(0.f);
  976. make.top.mas_equalTo(0.f);
  977. }];
  978. }
  979. #pragma mark 关闭心跳弹框
  980. - (void)closeBoxHeartbeatReStartViewFun
  981. {
  982. NSArray * subViews = ksharedAppDelegate.window.subviews;
  983. for (BoxHeartbeatReStartView*view in subViews) {
  984. if([view isKindOfClass:[BoxHeartbeatReStartView class]]){
  985. [view colseFun];
  986. break;
  987. }
  988. }
  989. }
  990. @end