webRtcManager.m 41 KB

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