webRtcManager.m 41 KB

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