webRtcManager.m 43 KB

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