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