webRtcManager.m 44 KB

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