webRtcManager.m 40 KB

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