webRtcManager.m 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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. [self checkFileTransfeTaskFun];
  547. }
  548. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown){
  549. [ksharedAppDelegate MonitorNetworkChangesFun];
  550. }
  551. }
  552. #pragma mark 检测是否正在进行的文件传输任务 设置后台状态
  553. - (void)checkFileTransfeTaskFun
  554. {
  555. BOOL isBackupsingType = [[nasBackupsManager shareInstance] checkBackupsingFun];
  556. BOOL isUploadingType = [[nasMixUploadManager shareManager] checkUploadTaskDoingFun];
  557. BOOL isDownloadingType = [[nasDownloadManager shareManager] isDownLoadIngType];
  558. BOOL isNasDownloadingType = [customDownloadManager shareManager].isDownLoadIngType;
  559. BOOL isBackground = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_working_background)];
  560. if ((isBackupsingType || isUploadingType || isDownloadingType ||isNasDownloadingType) && isBackground) {
  561. HLog(@"后台保活中");
  562. //[cachesFileManager writeLogsWithMsg:@"Background working"];
  563. }
  564. else{
  565. HLog(@"停止后台保活");
  566. //[cachesFileManager writeLogsWithMsg:@"stop Background working"];
  567. [[AudioSessionObject shareManager] stopBackgroundActiveFun];
  568. }
  569. }
  570. #pragma mark 收到的webrtc消息处理
  571. - (void)handleWebRtcMsgResponseBy:(NSData*)message
  572. {
  573. if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
  574. {
  575. message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
  576. }
  577. NSError *error = nil;
  578. NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
  579. HLog(@"webRtc P2P 通道接收消息:------------------%@",dataDict);
  580. // if([message isKindOfClass:[NSData class]] && [message length] == 0){
  581. // if(type == RCSocketCloudPhoneReceiveTypeForPong)
  582. // {
  583. // [weakSelf keepWebSocketOKFun];
  584. // }
  585. // return;
  586. // }
  587. //
  588. // HLog(@"webSocket指令通道接收消息:------------------\n%@",message);
  589. //
  590. // if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
  591. // {
  592. // message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
  593. // }
  594. //
  595. // NSError *error = nil;
  596. // NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
  597. if(!dataDict){
  598. //[weakSelf handleDownloadResponseFunBy:message];
  599. return;
  600. }
  601. if(![dataDict isKindOfClass:[NSDictionary class]]){
  602. //[__NSCFString allKeys] unrecognized selector sent to ins
  603. return;
  604. }
  605. if(![[dataDict allKeys] containsObject:@"type"]){
  606. return;
  607. }
  608. NSString *messageType = dataDict[@"type"];
  609. if ([messageType isEqualToString:@"cutting"]) {
  610. //[[iToast makeText:@"复制成功"] show];
  611. }
  612. // else if ([messageType isEqualToString:@"forwardMsgRep"]){/*转发的回复*/
  613. //
  614. // cloudPhoneCommonModel *model = [[cloudPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  615. // if(!model){
  616. // return;
  617. // }
  618. //
  619. // if([model.data.msg isEqualToString:@"only one socket"]||
  620. // [model.data.msg isEqualToString:@"only one socket2"]){
  621. // [weakSelf deleteCommandSendTaskFunWith:@"offline_notification"];
  622. // }
  623. // }
  624. // else if ([messageType isEqualToString:@"forwardMsg"]){/*转发*/
  625. // /*获取指令类型*/
  626. // NSString *code = nil;
  627. // if ([[dataDict allKeys] containsObject:@"data"]) {
  628. // NSDictionary *data = dataDict[@"data"];
  629. //
  630. // if([data isKindOfClass:[NSString class]]){
  631. // NSString * dataStr = (NSString*)data;
  632. // if([dataStr isEqualToString:@"offline_notification"]){
  633. // HLog(@"被别人挤下线了");
  634. // [weakSelf LogoutByOtherFun];
  635. // }
  636. //
  637. // return;
  638. // }
  639. // else if ([data isKindOfClass:[NSDictionary class]] && [[data allKeys] containsObject:@"code"]) {
  640. // code = [data objectForKey:@"code"];
  641. //
  642. // if (![code isKindOfClass:[NSString class]]) {
  643. // code = [NSString stringWithFormat:@"%ld",[code integerValue]];
  644. // }
  645. // }
  646. // }
  647. //
  648. // /*获取用户名*/
  649. // NSString *useName = nil;
  650. // if ([[dataDict allKeys] containsObject:@"data"]) {
  651. // NSDictionary *data = dataDict[@"data"];
  652. // if ([[data allKeys] containsObject:@"userName"]) {
  653. // //useName = [data objectForKey:@"userName"];
  654. // }
  655. // }
  656. //
  657. //
  658. // if ([code isEqualToString:@"phoneSizeChange"]){/*分辨率改变*/
  659. // if ([[dataDict allKeys] containsObject:@"data"]) {
  660. // NSDictionary *data = dataDict[@"data"];
  661. // if ([[data allKeys] containsObject:@"width"]) {
  662. // ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
  663. // }
  664. // if ([[data allKeys] containsObject:@"height"]) {
  665. // ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
  666. // }
  667. //
  668. // if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
  669. // CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
  670. // ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
  671. // ksharedAppDelegate.couldPhone_H_PHONE = temp;
  672. // }
  673. // }
  674. // }
  675. // }
  676. else if ([messageType isEqualToString:@"getPhoneSize"] || [messageType isEqualToString:@"setPhoneSize"]){
  677. //NSString *sn = nil;
  678. if([messageType isEqualToString:@"setPhoneSize"]){
  679. self.isDiDChangePhoneSizeType = YES;
  680. }
  681. if ([[dataDict allKeys] containsObject:@"data"]) {
  682. NSDictionary *data = dataDict[@"data"];
  683. if ([[data allKeys] containsObject:@"status"]) {
  684. NSInteger status = [[data objectForKey:@"status"] integerValue];
  685. if (status == 0) {/*不是当前设备直接返回*/
  686. if ([[data allKeys] containsObject:@"width"]) {
  687. ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
  688. }
  689. if ([[data allKeys] containsObject:@"height"]) {
  690. ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
  691. }
  692. if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
  693. CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
  694. ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
  695. ksharedAppDelegate.couldPhone_H_PHONE = temp;
  696. }
  697. }
  698. }
  699. }
  700. }
  701. // else if ([messageType isEqualToString:@"sync_wifi"]){
  702. // [weakSelf sync_wifiBackHandleFun];
  703. // }
  704. // else if ([messageType isEqualToString:@"reProduceText"]){
  705. // if ([[dataDict allKeys] containsObject:@"data"]) {
  706. // NSDictionary *data = dataDict[@"data"];
  707. //
  708. // if ([[data allKeys] containsObject:@"text"]) {
  709. // NSString *pasteboardStr = [data objectForKey:@"text"];
  710. // UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  711. // pasteboard.string = pasteboardStr;
  712. // }
  713. // }
  714. // }
  715. // else if ([messageType isEqualToString:@"downAdnInstallRep"]){
  716. // if ([[dataDict allKeys] containsObject:@"data"]) {
  717. // NSDictionary *data = dataDict[@"data"];
  718. //
  719. // if ([[data allKeys] containsObject:@"status"]) {
  720. // NSString *status = [data objectForKey:@"status"];
  721. // if ([status isEqualToString:@"1"]) {
  722. // mainBlock(^{
  723. // // [[iToast makeText:@"App下载完成"] show];
  724. // });
  725. // }else if ([status isEqualToString:@"0"]){
  726. // mainBlock(^{
  727. // //[[iToast makeText:@"App下载中"] show];
  728. // });
  729. // }
  730. // }
  731. // }
  732. // }
  733. // else if ([messageType isEqualToString:@"shakeit"]){
  734. // HLog(@"\n-----摇一摇成功------");
  735. // }else if ([messageType isEqualToString:@"keyboardFeedbackBean"]){/*调起键盘*/
  736. // HLog(@"\n-----待处理 调起键盘------");
  737. // // [weakSelf keyboardFeedbackBeanFun];
  738. // }else if ([messageType isEqualToString:@"FileRandomReady"]
  739. // ||[messageType isEqualToString:@"FilePartReady"]
  740. // ){/*申请文件上传得到答复*/
  741. // [weakSelf applyUploadFileServiceResponseFun:dataDict];
  742. // }
  743. // else if ([messageType isEqualToString:@"uploadFileRandomRet"]
  744. // ||[messageType isEqualToString:@"uploadFilePartRet"]
  745. // ){/*文件上传得到答复*/
  746. // [weakSelf upLoadFileFunServiceResponseFun:dataDict];
  747. // }
  748. // else if ([messageType isEqualToString:@"backUpFileRandomReady"]
  749. // ||[messageType isEqualToString:@"backUpPartReady"]
  750. // ){/*文件备份得到答复*/
  751. // [weakSelf applyBackupsFileServiceResponseFun:dataDict];
  752. // }
  753. // else if ([messageType isEqualToString:@"backUpFileRandomRet"]
  754. // ||[messageType isEqualToString:@"backUpFilePartRet"]){/*文件备份得到答复*/
  755. // [weakSelf backupsFileFunServiceResponseFun:dataDict];
  756. // }
  757. else if ([messageType isEqualToString:@"getBaseInfo"]){/*获取云机的基本信息*/
  758. [self getCouldPhoneBaseInfoResponseFun:dataDict];
  759. }
  760. else if ([messageType isEqualToString:@"getSysInfo"]){/*获取云机的系统信息*/
  761. [self getCouldPhoneSysInfoResponseFun:dataDict];
  762. }
  763. else if ([messageType isEqualToString:@"TvStatus"]){/*获取TV投屏信息*/
  764. [self getCouldPhoneTvStatusResponseFun:dataDict];
  765. }
  766. else if ([messageType isEqualToString:@"TvOff"]){/*关闭TV投屏*/
  767. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  768. [self getTvStatusFun];
  769. });
  770. }
  771. else if ([messageType isEqualToString:@"wakeupTV"]){/*开启TV投屏*/
  772. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  773. [self getTvStatusFun];
  774. });
  775. }
  776. else if ([messageType isEqualToString:@"reboot"]){/*重启*/
  777. //[weakSelf stopForceStartTimerFun];
  778. }
  779. else if ([messageType isEqualToString:@"mkdir"]){/*创建文件夹*/
  780. [self createFolderResponseFun:dataDict];
  781. }
  782. else if ([messageType isEqualToString:@"getBackupPath"]){/*创建文件夹*/
  783. [self getFolderListResponseFun:dataDict];
  784. }
  785. else if ([messageType isEqualToString:@"search"]){/*创建文件夹*/
  786. [self searchFileListResponseFun:dataDict];
  787. }
  788. else if ([messageType isEqualToString:@"getExtraFiles"]){/*获取云机产品信息*/
  789. [self getExtraFilesResponseFun:dataDict];
  790. }
  791. else if ([messageType isEqualToString:@"extraMediaEvent"]){/*磁盘插拔*/
  792. [self getExtraMediaEventResponseFun:dataDict];
  793. [self getExtraFilesListFun];
  794. }
  795. else if ([messageType isEqualToString:@"reset"]){/**/
  796. [self deleteCommandSendTaskFunWith:@"reset"];
  797. }
  798. else if ([messageType isEqualToString:@"shortcatRep"]){/*截图*/
  799. [[iToast makeText:NSLocalizedString(@"shortcatRep_tip",nil)] show];
  800. }
  801. }
  802. #pragma mark WebRTC 回调 MediaStreamClientEventsDelegate
  803. #pragma mark 不能再这里函数判断 这个是推拉流的
  804. -(void)onChangeConnectionStateFromPeerName:(NSString*)peerName didChangeIceConnectionState:(RTCIceConnectionState)state
  805. {
  806. HLog(@"channel P2P onChangeConnectionStateFromPeerName: state:%ld",state)
  807. self.ConnectionState = state;
  808. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"webrtc channel onChangeConnectionStateFromPeerName:%ld",state]];
  809. switch (state) {
  810. case RTCIceConnectionStateConnected:{
  811. //链接成功
  812. }
  813. break;
  814. case RTCIceConnectionStateCompleted:
  815. //链接完成
  816. break;
  817. case RTCIceConnectionStateFailed:
  818. case RTCIceConnectionStateDisconnected:
  819. case RTCIceConnectionStateClosed:{
  820. if(!_didReportWebRtcFailType && state == RTCIceConnectionStateFailed){//还没上报过通道链接情况
  821. _didReportWebRtcFailType = YES;
  822. KWeakSelf
  823. globalBlock(^{
  824. [[addLogObject shareInstance] gotoAddLogFunBySuccess:^(NSString * _Nonnull key) {
  825. [weakSelf reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:self->_webRtcChannelSessionId withLogKey:key];
  826. }];
  827. });
  828. }
  829. //链接关闭
  830. [self relinkWebRtcFun];
  831. }
  832. break;
  833. default:
  834. break;
  835. }
  836. }
  837. #pragma mark 通道连接状态变化监听
  838. - (void)dataChannelDidChangeFromPeerName:(NSString*)peerName State:(RTCDataChannelState)state
  839. {
  840. HLog(@"webRtc P2P dataChannelDidChangeFromPeerName: state:%ld",state)
  841. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"webrtc channel dataChannelDidChangeFromPeerName:%ld",state]];
  842. self.channelState = state;
  843. switch (state) {
  844. case RTCDataChannelStateConnecting:
  845. {
  846. }
  847. break;
  848. case RTCDataChannelStateOpen:
  849. {
  850. //链接成功
  851. [self handlAllMsgAfterDidLinkFun];
  852. //客户端停止写日志
  853. [ksharedAppDelegate.WebRtcLogger stop];
  854. }
  855. break;
  856. case RTCDataChannelStateClosing:
  857. {
  858. }
  859. break;
  860. case RTCDataChannelStateClosed:
  861. {
  862. //链接断开
  863. [self relinkWebRtcFun];
  864. }
  865. break;
  866. default:
  867. break;
  868. }
  869. }
  870. -(void)onChannelDataFromPeerName:(NSString*)peerName buffer:(RTC_OBJC_TYPE(RTCDataBuffer) *)buffer
  871. {
  872. //HLog(@"onIceConnectedFromPeerName:%@",buffer.data);
  873. if(buffer && buffer.data){
  874. KWeakSelf
  875. mainBlock(^{
  876. [weakSelf handleWebRtcMsgResponseBy:buffer.data];
  877. });
  878. }
  879. }
  880. -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats
  881. {
  882. //HLog(@"didGetStats:%@",stats)
  883. if(!_didReportWebRtcOKType
  884. && (self.ConnectionState == RTCIceConnectionStateConnected ||self.ConnectionState == RTCIceConnectionStateCompleted)){
  885. [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats withSessionId:_webRtcChannelSessionId withLogKey:@""];
  886. _didReportWebRtcOKType = YES;
  887. _didReportWebRtcFailType = NO;//链接成功后 失败要重新上报
  888. [_mediaStream setShouldGetStats:NO];
  889. }
  890. }
  891. -(void)onAuthResultFromPeerName:(NSString*)peerName code:(int)code descriptions:(NSString*)descriptions
  892. {
  893. //HLog(@"webRtc P2P onAuthResultFromPeerName")
  894. }
  895. - (void)connectionChange:(NSString*)peerName
  896. didChangeLocalCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)local
  897. remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote
  898. lastReceivedMs:(int)lastDataReceivedMs
  899. changeReason:(NSString *)reason
  900. {
  901. //HLog(@"webRtc P2P didChangeLocalCandidate")
  902. [self reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcChannelSessionId withLogKey:@""];
  903. }
  904. #pragma mark 检测盒子的心跳情况
  905. - (void)checkBoxHeartbeatFun
  906. {
  907. //1.隐私模式密码界面 3秒检测一次是否输入完成密码了
  908. if(ksharedAppDelegate.isDidShowPwdType){
  909. KWeakSelf
  910. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  911. [weakSelf checkBoxHeartbeatFun];
  912. });
  913. return;
  914. }
  915. // [[BoxHeartbeatAlertTool shareInstance] showBoxHeartbeatAlertFun:1 didClickBut:^(NSInteger tag) {
  916. //
  917. // }];
  918. if(ksharedAppDelegate.isWebSockLinkOKAginType && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  919. return;
  920. }
  921. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  922. KWeakSelf
  923. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryHeartbeat Parameters:paraDict success:^(id _Nonnull responseObject){
  924. queryHeartbeatModel *heartbeatMod = [[queryHeartbeatModel alloc] initWithDictionary:responseObject error:nil];
  925. if(heartbeatMod && heartbeatMod.data){
  926. [weakSelf checkBoxHeartbeatToShowPopViewFunBy:heartbeatMod];
  927. }
  928. } failure:^(NSError * _Nonnull error) {
  929. }];
  930. }
  931. #pragma mark 根据盒子的心跳情况 显示异常谈了
  932. - (void)checkBoxHeartbeatToShowPopViewFunBy:(queryHeartbeatModel*)heartbeatMod
  933. {
  934. if(!heartbeatMod || !heartbeatMod.data){
  935. return;
  936. }
  937. if (!heartbeatMod.data.frpStatus
  938. &&!heartbeatMod.data.hostAgentStatus
  939. &&!heartbeatMod.data.containerAgentStatus) {//全部异常
  940. [[BoxHeartbeatAlertTool shareInstance] showBoxHeartbeatAlertFun:1 didClickBut:^(NSInteger tag) {
  941. }];
  942. }
  943. else if (heartbeatMod.data.hostAgentStatus
  944. && !heartbeatMod.data.frpStatus
  945. && !heartbeatMod.data.containerAgentStatus) {//frp异常
  946. [[BoxHeartbeatAlertTool shareInstance] showBoxHeartbeatAlertFun:2 didClickBut:^(NSInteger tag) {
  947. }];
  948. }
  949. }
  950. #pragma mark 显示重启成功
  951. - (void)showReStartSucFun
  952. {
  953. //1.隐私模式密码界面 3秒检测一次是否输入完成密码了
  954. if(ksharedAppDelegate.isDidShowPwdType){
  955. KWeakSelf
  956. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  957. [weakSelf showReStartSucFun];
  958. });
  959. return;
  960. }
  961. NSArray * subViews = ksharedAppDelegate.window.subviews;
  962. for (BoxHeartbeatReStartView*view in subViews) {
  963. if([view isKindOfClass:[BoxHeartbeatReStartView class]]){
  964. [view colseFun];
  965. break;
  966. }
  967. }
  968. BoxHeartbeatReStartSucView *view = [[BoxHeartbeatReStartSucView alloc] init];
  969. [ksharedAppDelegate.window addSubview:view];
  970. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  971. make.left.mas_equalTo(0.f);
  972. make.bottom.mas_equalTo(0.f);
  973. make.right.mas_equalTo(0.f);
  974. make.top.mas_equalTo(0.f);
  975. }];
  976. }
  977. @end