webRtcManager.m 40 KB

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