webRtcManager.m 42 KB

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