webRtcManager.m 43 KB

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