webSocketManager.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. //
  2. // webSocketManager.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/6/20.
  6. //
  7. #import "webSocketManager.h"
  8. #import "webSocketManager+baseDownload.h"
  9. #import "webSocketManager+downloadFile.h"
  10. #import "webSocketManager+downloadThumbnailImage.h"
  11. #import "webSocketManager+upLoadFile.h"
  12. #import "webSocketManager+backupsFile.h"
  13. @interface webSocketManager ()
  14. {
  15. NSMutableArray *commandSendCheckArr;//需要检测任务是否发出的的指令
  16. }
  17. @property(copy,nonatomic)NSString *curIp;
  18. /**定时器计数*/
  19. @property (nonatomic, assign) NSInteger webSocketTime;
  20. /**定时器计数 任务检测*/
  21. @property (nonatomic, assign) NSInteger webSocketTaskTime;
  22. @property (nonatomic, copy) NSTimer *timer; // 定时器-控制按钮
  23. //第一次链接设备 要发送指令信息 实现单点登录
  24. @property (nonatomic, assign)BOOL didSendfristMsg;
  25. @end
  26. @implementation webSocketManager
  27. static webSocketManager *webSocketManagerInstance = nil;
  28. +(webSocketManager *)shareInstance;
  29. {
  30. static dispatch_once_t onceToken;
  31. dispatch_once(&onceToken, ^{
  32. webSocketManagerInstance = [[webSocketManager alloc] init];
  33. });
  34. return webSocketManagerInstance;
  35. }
  36. - (void)initOtherFun
  37. {
  38. if(_timer){
  39. //[_timer invalidate];
  40. return;
  41. }
  42. _timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
  43. [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
  44. commandSendCheckArr = [NSMutableArray new];
  45. }
  46. - (void)opencommandChannelManagerrc_openURL
  47. {
  48. if(self.commandChannelManager){
  49. if([self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusConnected
  50. ||[self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusReceived){
  51. //链接中不处理
  52. HLog(@"WebSocket 链接时已经存在并且链接中");
  53. }
  54. else{
  55. HLog(@"WebSocket 链接时已经存在并且链接失效");
  56. [self.commandChannelManager rc_close];
  57. self.commandChannelManager = nil;
  58. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  59. [self opencommandChannelManagerrc_openURL];
  60. });
  61. }
  62. return;
  63. }
  64. KWeakSelf
  65. //初始化指令通道
  66. self.commandChannelManager = [[RCCommandChannelManager alloc] init];
  67. NSString *wsPort = @"";
  68. if([connectDeviceManager shareInstance].isPingOk
  69. && [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi){
  70. _curIp = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.ip;
  71. wsPort = @"9300";
  72. }
  73. else{
  74. _curIp = ruiyunlinkIp;
  75. wsPort = [[connectDeviceManager shareInstance] tcpPortStr];
  76. }
  77. NSString *instructionsChannelUrl = [NSString stringWithFormat:@"ws://%@:%@/businessChannel",_curIp,wsPort];
  78. if (instructionsChannelUrl && instructionsChannelUrl.length > 0) { //当都有值才可连接
  79. HLog(@"WebSocket11111指令通道连接开始11111 url = %@ ",instructionsChannelUrl);
  80. [self.commandChannelManager rc_openURL:instructionsChannelUrl connected:^{
  81. HLog(@"WebSocket11111指令通道连接成功11111 url = %@ ",instructionsChannelUrl);
  82. if (weakSelf.commandChannelManager.rc_socketStatus == RCSocketCloudPhoneStatusConnected){
  83. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  84. [weakSelf initOtherFun];
  85. [weakSelf handlAllMsgAfterDidLinkFun];
  86. });
  87. }
  88. } receive:^(id message, FLSocketCloudPhoneReceiveType type) {
  89. if([message isKindOfClass:[NSData class]] && [message length] == 0){
  90. if(type == RCSocketCloudPhoneReceiveTypeForPong)
  91. {
  92. [weakSelf keepWebSocketOKFun];
  93. }
  94. return;
  95. }
  96. HLog(@"webSocket指令通道接收消息:------------------\n%@",message);
  97. if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
  98. {
  99. message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
  100. }
  101. NSError *error = nil;
  102. NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
  103. if(!dataDict){
  104. [weakSelf handleDownloadResponseFunBy:message];
  105. return;
  106. }
  107. if(![dataDict isKindOfClass:[NSDictionary class]]){
  108. //[__NSCFString allKeys] unrecognized selector sent to ins
  109. return;
  110. }
  111. NSString *messageType = dataDict[@"type"];
  112. if ([messageType isEqualToString:@"cutting"]) {
  113. //[[iToast makeText:@"复制成功"] show];
  114. }
  115. else if ([messageType isEqualToString:@"forwardMsgRep"]){/*转发的回复*/
  116. cloudPhoneCommonModel *model = [[cloudPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  117. if(!model){
  118. return;
  119. }
  120. if([model.data.msg isEqualToString:@"only one socket"]){
  121. [weakSelf deleteCommandSendTaskFunWith:@"offline_notification"];
  122. }
  123. }
  124. else if ([messageType isEqualToString:@"forwardMsg"]){/*转发*/
  125. /*获取指令类型*/
  126. NSString *code = nil;
  127. if ([[dataDict allKeys] containsObject:@"data"]) {
  128. NSDictionary *data = dataDict[@"data"];
  129. if([data isKindOfClass:[NSString class]]){
  130. NSString * dataStr = (NSString*)data;
  131. if([dataStr isEqualToString:@"offline_notification"]){
  132. HLog(@"被别人挤下线了");
  133. //[weakSelf LogoutByOtherFun];
  134. }
  135. return;
  136. }
  137. else if ([data isKindOfClass:[NSDictionary class]] && [[data allKeys] containsObject:@"code"]) {
  138. code = [data objectForKey:@"code"];
  139. if (![code isKindOfClass:[NSString class]]) {
  140. code = [NSString stringWithFormat:@"%ld",[code integerValue]];
  141. }
  142. }
  143. }
  144. /*获取用户名*/
  145. NSString *useName = nil;
  146. if ([[dataDict allKeys] containsObject:@"data"]) {
  147. NSDictionary *data = dataDict[@"data"];
  148. if ([[data allKeys] containsObject:@"userName"]) {
  149. useName = [data objectForKey:@"userName"];
  150. }
  151. }
  152. if ([code isEqualToString:@"phoneSizeChange"]){/*分辨率改变*/
  153. if ([[dataDict allKeys] containsObject:@"data"]) {
  154. NSDictionary *data = dataDict[@"data"];
  155. if ([[data allKeys] containsObject:@"width"]) {
  156. ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
  157. }
  158. if ([[data allKeys] containsObject:@"height"]) {
  159. ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
  160. }
  161. if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
  162. CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
  163. ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
  164. ksharedAppDelegate.couldPhone_H_PHONE = temp;
  165. }
  166. }
  167. }
  168. }
  169. else if ([messageType isEqualToString:@"getPhoneSize"] || [messageType isEqualToString:@"setPhoneSize"]){
  170. NSString *sn = nil;
  171. if ([[dataDict allKeys] containsObject:@"data"]) {
  172. NSDictionary *data = dataDict[@"data"];
  173. if ([[data allKeys] containsObject:@"status"]) {
  174. NSInteger status = [[data objectForKey:@"status"] integerValue];
  175. if (status == 0) {/*不是当前设备直接返回*/
  176. if ([[data allKeys] containsObject:@"width"]) {
  177. ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
  178. }
  179. if ([[data allKeys] containsObject:@"height"]) {
  180. ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
  181. }
  182. if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
  183. CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
  184. ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
  185. ksharedAppDelegate.couldPhone_H_PHONE = temp;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. else if ([messageType isEqualToString:@"sync_wifi"]){
  192. [weakSelf sync_wifiBackHandleFun];
  193. }
  194. else if ([messageType isEqualToString:@"reProduceText"]){
  195. if ([[dataDict allKeys] containsObject:@"data"]) {
  196. NSDictionary *data = dataDict[@"data"];
  197. if ([[data allKeys] containsObject:@"text"]) {
  198. NSString *pasteboardStr = [data objectForKey:@"text"];
  199. UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  200. pasteboard.string = pasteboardStr;
  201. }
  202. }
  203. }
  204. else if ([messageType isEqualToString:@"downAdnInstallRep"]){
  205. if ([[dataDict allKeys] containsObject:@"data"]) {
  206. NSDictionary *data = dataDict[@"data"];
  207. if ([[data allKeys] containsObject:@"status"]) {
  208. NSString *status = [data objectForKey:@"status"];
  209. if ([status isEqualToString:@"1"]) {
  210. mainBlock(^{
  211. // [[iToast makeText:@"App下载完成"] show];
  212. });
  213. }else if ([status isEqualToString:@"0"]){
  214. mainBlock(^{
  215. //[[iToast makeText:@"App下载中"] show];
  216. });
  217. }
  218. }
  219. }
  220. }
  221. else if ([messageType isEqualToString:@"shakeit"]){
  222. HLog(@"\n-----摇一摇成功------");
  223. }else if ([messageType isEqualToString:@"keyboardFeedbackBean"]){/*调起键盘*/
  224. HLog(@"\n-----待处理 调起键盘------");
  225. // [weakSelf keyboardFeedbackBeanFun];
  226. }else if ([messageType isEqualToString:@"FileRandomReady"]
  227. ||[messageType isEqualToString:@"FilePartReady"]
  228. ){/*申请文件上传得到答复*/
  229. [weakSelf applyUploadFileServiceResponseFun:dataDict];
  230. }
  231. else if ([messageType isEqualToString:@"uploadFileRandomRet"]
  232. ||[messageType isEqualToString:@"uploadFilePartRet"]
  233. ){/*文件上传得到答复*/
  234. [weakSelf upLoadFileFunServiceResponseFun:dataDict];
  235. }
  236. else if ([messageType isEqualToString:@"backUpFileRandomReady"]
  237. ||[messageType isEqualToString:@"backUpPartReady"]
  238. ){/*文件备份得到答复*/
  239. [weakSelf applyBackupsFileServiceResponseFun:dataDict];
  240. }
  241. else if ([messageType isEqualToString:@"backUpFileRandomRet"]
  242. ||[messageType isEqualToString:@"backUpFilePartRet"]){/*文件备份得到答复*/
  243. [weakSelf backupsFileFunServiceResponseFun:dataDict];
  244. }
  245. else if ([messageType isEqualToString:@"getBaseInfo"]){/*获取云机的基本信息*/
  246. [weakSelf getCouldPhoneBaseInfoResponseFun:dataDict];
  247. }
  248. else if ([messageType isEqualToString:@"getSysInfo"]){/*获取云机的系统信息*/
  249. [weakSelf getCouldPhoneSysInfoResponseFun:dataDict];
  250. }
  251. else if ([messageType isEqualToString:@"TvStatus"]){/*获取TV投屏信息*/
  252. [weakSelf getCouldPhoneTvStatusResponseFun:dataDict];
  253. }
  254. else if ([messageType isEqualToString:@"reboot"]){/*重启*/
  255. [weakSelf stopForceStartTimerFun];
  256. }
  257. else if ([messageType isEqualToString:@"mkdir"]){/*创建文件夹*/
  258. [weakSelf createFolderResponseFun:dataDict];
  259. }
  260. else if ([messageType isEqualToString:@"getBackupPath"]){/*创建文件夹*/
  261. [weakSelf getFolderListResponseFun:dataDict];
  262. }
  263. else if ([messageType isEqualToString:@"search"]){/*创建文件夹*/
  264. [weakSelf searchFileListResponseFun:dataDict];
  265. }
  266. else if ([messageType isEqualToString:@"getExtraFiles"]){/*创建文件夹*/
  267. [weakSelf getExtraFilesResponseFun:dataDict];
  268. }
  269. else if ([messageType isEqualToString:@"extraMediaEvent"]){/*磁盘插拔*/
  270. [weakSelf getExtraMediaEventResponseFun:dataDict];
  271. [weakSelf getExtraFilesListFun];
  272. }
  273. else if ([messageType isEqualToString:@"reset"]){/**/
  274. [weakSelf deleteCommandSendTaskFunWith:@"reset"];
  275. }
  276. } failure:^(NSError *error) {
  277. ksharedAppDelegate.isWebSockLinkOKAginType = NO;
  278. // [self showNetErrorAlertFun:2];
  279. // [self WebSocketNeedRelinkFun];
  280. }];
  281. }
  282. }
  283. - (void)keepWebSocketOKFun
  284. {
  285. self.webSocketTime = 0;
  286. }
  287. - (void)WebSocketNeedRelinkFun
  288. {
  289. self.webSocketTime = 0;
  290. if(self.commandChannelManager){
  291. [self opencommandChannelManagerrc_openURL];
  292. }
  293. }
  294. - (void)timerChange {
  295. //处理websockt是否断开
  296. self.webSocketTime += 2;
  297. //处理其他任务
  298. self.webSocketTaskTime += 2;
  299. if(self.webSocketTime > 8)
  300. {
  301. [self WebSocketNeedRelinkFun];
  302. }
  303. if(self.webSocketTaskTime > 10)
  304. {
  305. self.webSocketTaskTime = 0;
  306. [self checkAllTaskFun];
  307. }
  308. }
  309. - (void)checkAllTaskFun
  310. {
  311. if([self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusConnected
  312. ||[self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusReceived){
  313. HLog(@"WebSocket 链接正常");
  314. }
  315. else{
  316. HLog(@"WebSocket 链接异常:%ld",[self.commandChannelManager rc_socketStatus]);
  317. return;
  318. }
  319. //处理相册备份
  320. [[backupsFileManager shareInstance] checkReBackupsFileFun];
  321. [[uploadFileManager shareInstance] checkReUploadFileFun];
  322. [[downloadManager shareInstance] checkReDownloadFileFun];
  323. [[downloadThumbnailManager shareInstance] checkReDownloadThumbnailFileFun];
  324. [self checkCommandSendTaskFun];
  325. if([AudioSessionObject shareManager].isBackgroundType){
  326. [self checkFileTransfeTaskFun];
  327. }
  328. HLog(@"checkAllTaskFun");
  329. }
  330. //检测是否正在进行的文件传输任务
  331. - (void)checkFileTransfeTaskFun
  332. {
  333. BOOL isBackupsingType = [[backupsFileManager shareInstance] checkBackupsingFun];
  334. BOOL isUploadingType = [[uploadFileManager shareInstance] checkUploadingFun];
  335. BOOL isDownloadingType = [[downloadManager shareInstance] checkDownloadingFun];
  336. BOOL isBackground = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_working_background)];
  337. if ((isBackupsingType || isUploadingType || isDownloadingType) && isBackground) {
  338. HLog(@"后台保活中");
  339. [cachesFileManager writeLogsWithMsg:@"Background working"];
  340. }
  341. else{
  342. HLog(@"停止后台保活");
  343. [cachesFileManager writeLogsWithMsg:@"stop Background working"];
  344. [[AudioSessionObject shareManager] stopBackgroundActiveFun];
  345. }
  346. }
  347. -(void)checkCommandSendTaskFun
  348. {
  349. if(commandSendCheckArr && commandSendCheckArr.count >0){
  350. for (commandSendCheckModel *model in commandSendCheckArr) {
  351. if(model.reSendNum < 3){
  352. model.reSendNum ++;
  353. if(model.commandStr){
  354. [self send_data:model.commandStr];
  355. HLog(@"\n\n\n任务重发 重发次数:%ld 指令:%@\n\n\n",model.reSendNum,model.commandStr);
  356. }
  357. // if([model.type isEqualToString:@"offline_notification"]){
  358. // model.reSendNum = 1;//只要不收到
  359. // }
  360. }
  361. }
  362. }
  363. }
  364. - (void)send_data:(NSString *)dataStr
  365. {
  366. [self.commandChannelManager rc_sendData:dataStr];
  367. }
  368. #pragma mark 盒子链接成功后需要处理的各种各样事情
  369. - (void)handlAllMsgAfterDidLinkFun
  370. {
  371. ksharedAppDelegate.isWebSockLinkOKAginType = YES;
  372. //获取云机尺寸 兼容 720*1080 &1080*1920 不同分辨率的展示和触控
  373. NSString *getPhoneSizeStr = [RCCommandHelp getPhoneSizecommand];
  374. [self send_data:getPhoneSizeStr];
  375. //判断是否为需要改机
  376. BOOL isNeedRandomChangeParams = [HWDataManager getBoolWithKey:Const_need_random_Change_Params];
  377. if(isNeedRandomChangeParams)
  378. {
  379. NSString *commondStr = @"{\"type\":\"randomChangeParams\"}";
  380. [self send_data:commondStr];
  381. [HWDataManager setBoolWithKey:Const_need_random_Change_Params value:NO];
  382. }
  383. [self fristConnectNeedGiveAMsgFun];
  384. [self updateCopydata];
  385. // 报链接失败 后面又连接上了
  386. // if(linkFailAlretVC && linkFailAlretVC.view.tag == 2){
  387. // mainBlock(^{
  388. // [self->linkFailAlretVC dismissViewControllerAnimated:YES completion:^{
  389. //
  390. // }];
  391. // self->linkFailAlretVC = nil;
  392. // });
  393. // }
  394. //处理相册备份
  395. [[backupsFileManager shareInstance] AutohandlePhotosBackupsFun];
  396. //获取磁盘外挂
  397. [self getExtraFilesListFun];
  398. [self getBaseInfoFun];
  399. }
  400. #pragma mark 盒子第一次连接成功 给ws发送信息 单点登录 把其他账号挤下去
  401. - (void)fristConnectNeedGiveAMsgFun{
  402. if(!_didSendfristMsg )
  403. {
  404. NSString *commondStr3 = @"{\"type\":\"getSysInfo\"}";
  405. [self send_data:commondStr3];
  406. // NSString *commondStr = @"{\"type\":\"forwardMsg\",\"data\":\"offline_notification\"}";
  407. // [self send_data:commondStr];
  408. // [self addCommandSendTaskFunWithType:@"offline_notification" WithCommandStr:commondStr];
  409. _didSendfristMsg = true;
  410. [self getPreferredLanguage];
  411. NSString *commondStr2 = @"{\"type\":\"TvStatus\"}";
  412. [self send_data:commondStr2];
  413. }
  414. }
  415. #pragma mark 语言和市区 同步云机
  416. -(void)getPreferredLanguage
  417. {//{"data":{"language":"zh-CN","timeZone":"Etc/GMT+8"},"type":"setLanguages"}
  418. // iOS 获取设备当前语言的代码
  419. NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
  420. HLog(@"当前语言:%@", preferredLanguage);
  421. //en-US 英文 ja-JP 日文
  422. NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  423. NSLog(@"arLanguages:%@",arLanguages);
  424. ///获取设备当前地区的代码和APP语言环境
  425. NSString *languageCode = [NSLocale preferredLanguages][0];
  426. //目前支持 中文(简体 繁体) 英文 日语
  427. if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
  428. {
  429. preferredLanguage = @"zh-CN";
  430. }
  431. else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
  432. {
  433. preferredLanguage = @"zh-HK";
  434. }
  435. else if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  436. {
  437. preferredLanguage = @"ja-JP";
  438. }
  439. else{
  440. preferredLanguage = @"en-US";
  441. }
  442. // if([languageCode rangeOfString:preferredLanguage].location != NSNotFound){
  443. // preferredLanguage = languageCode;
  444. // }
  445. // else{
  446. // preferredLanguage = @"en-US";
  447. // }
  448. NSString*gmtStr = [self UTCOffset];
  449. HLog(@"%@",gmtStr);
  450. // //获取名字,如“GMT+08:00
  451. NSString *commondStr = [NSString stringWithFormat:@"{\"type\":\"setLanguages\",\"data\":{\"language\":\"%@\",\"timeZone\":\"%@\"}}",preferredLanguage,gmtStr];
  452. [self send_data:commondStr];
  453. }
  454. -(NSString *)UTCOffset {
  455. NSTimeZone *localTZ = [NSTimeZone localTimeZone];
  456. float offset = localTZ.secondsFromGMT/3600.0;
  457. if(offset > 0){
  458. return [NSString stringWithFormat:@"Etc/GMT+%g",offset];
  459. }
  460. return [NSString stringWithFormat:@"Etc/GMT%g",offset];
  461. }
  462. - (void)updateCopydata{
  463. UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  464. NSString *str = [pasteboard string];
  465. HLog(@"__________%s______%@____",__func__,str);
  466. if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound)
  467. {
  468. str = nil;
  469. }
  470. if (str && str.length >0)
  471. {
  472. //HLog(@"hxd111 cutting %@",str);
  473. /*发送数据*/
  474. NSString *dataStr = [RCCommandHelp commandCuttingWithContent:str];
  475. [self.commandChannelManager rc_sendData:dataStr];
  476. //pasteboard.string = @"";
  477. }
  478. }
  479. #pragma mark 获取云机以及外挂磁盘
  480. - (void)getExtraFilesListFun
  481. {
  482. NSString *ExtraCommondStr = [RCCommandHelp getExtraFilesList];
  483. [self send_data:ExtraCommondStr];
  484. }
  485. -(void)addCommandSendTaskFunWithType:(NSString*)type WithCommandStr:(NSString*)commandStr
  486. {
  487. if(!commandSendCheckArr){
  488. commandSendCheckArr = [NSMutableArray new];
  489. }
  490. BOOL didAddType = NO;
  491. for (commandSendCheckModel *model in commandSendCheckArr) {
  492. if([model.type isEqualToString:type]){
  493. didAddType = YES;
  494. model.reSendNum = 0;
  495. model.sendTimerStamp = [iTools getNowTimeStamp];
  496. break;
  497. }
  498. }
  499. if(!didAddType){
  500. commandSendCheckModel *model = [commandSendCheckModel new];
  501. model.commandStr = commandStr;
  502. model.type = type;
  503. model.reSendNum = 0;
  504. model.sendTimerStamp = [iTools getNowTimeStamp];
  505. [commandSendCheckArr addObject:model];
  506. }
  507. }
  508. -(void)deleteCommandSendTaskFunWith:(NSString*)type
  509. {
  510. if(commandSendCheckArr && commandSendCheckArr.count >0){
  511. NSArray *taskArr = [NSArray arrayWithArray:commandSendCheckArr];
  512. for (commandSendCheckModel *model in taskArr) {
  513. if([type isEqualToString:model.type]){
  514. [commandSendCheckArr removeObject:model];
  515. }
  516. }
  517. }
  518. }
  519. #pragma mark wifi handle
  520. - (void)sync_wifiBackHandleFun
  521. {
  522. [self.commandChannelManager rc_sendData:[RCCommandHelp noSyncWifiBack]];
  523. [[iToast makeText:NSLocalizedString(@"player_Tip_ios_no_wifi_Sync",nil)] show];
  524. }
  525. - (void)getCouldPhoneBaseInfoResponseFun:(NSDictionary *)dataDict
  526. {
  527. couldPhoneBaseInfoModel *model = [[couldPhoneBaseInfoModel alloc] initWithDictionary:dataDict error:nil];
  528. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneBaseInfoNotification object:model];
  529. }
  530. - (void)getCouldPhoneSysInfoResponseFun:(NSDictionary *)dataDict{
  531. couldphoneSysInfoModel *model = [[couldphoneSysInfoModel alloc] initWithDictionary:dataDict error:nil];
  532. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
  533. NSString *hostImgVer = model.data.data.hostImgVer;
  534. NSString *MyNewVersion = model.data.data.MyNewVersion;
  535. //test code
  536. // hostImgVer = @"1.2.3";
  537. // MyNewVersion = @"1.2.0";
  538. //判断当前版本号 待更新版本
  539. if (!hostImgVer || hostImgVer.length < 3
  540. ||!MyNewVersion || MyNewVersion.length < 3) {
  541. //[self showImageViewRenewTipViewFun];
  542. return;
  543. }
  544. NSArray *versionArr = [hostImgVer componentsSeparatedByString:@"."];
  545. NSArray *MyNewVersionArr = [MyNewVersion componentsSeparatedByString:@"."];
  546. NSInteger versionArrCount = versionArr.count;
  547. NSInteger MyNewVersionArrCount = MyNewVersionArr.count;
  548. NSInteger maxCount = versionArrCount < MyNewVersionArrCount ? versionArrCount:MyNewVersionArrCount;
  549. BOOL isNeedShowType = NO;
  550. //判断是否要更新镜像框
  551. if(maxCount > 0){
  552. for (int i=0; i<maxCount; i++) {
  553. NSString * numberStr1 = versionArr[i];
  554. NSString * numberStr2 = MyNewVersionArr[i];
  555. if(numberStr2.intValue > numberStr1.intValue){
  556. isNeedShowType =YES;
  557. break;
  558. }
  559. }
  560. }
  561. if(isNeedShowType){
  562. HLog(@"hxd 镜像弹框 待处理")
  563. //[self showImageViewRenewTipViewFun];
  564. }
  565. //是否禁用文件传输 (1.3以及以上的镜像可以使用文件传输)
  566. if(versionArr.count >= 3)
  567. {
  568. NSString * oneStr = versionArr[0];
  569. NSString * twoStr = versionArr[1];
  570. NSString * threeStr = versionArr[2];
  571. if(oneStr.integerValue <=1 && twoStr.integerValue <=3 && threeStr.integerValue <=0){//禁用
  572. ksharedAppDelegate.DisabledFileTransferType = YES;
  573. if(MyNewVersionArr.count >= 3)
  574. {
  575. NSString * newOneStr = MyNewVersionArr[0];
  576. NSString * newTwoStr = MyNewVersionArr[1];
  577. NSString * newThreeStr = MyNewVersionArr[2];
  578. if(newOneStr.integerValue >=1 && newTwoStr.integerValue >=3 && newThreeStr.integerValue >= 1){
  579. ksharedAppDelegate.isImageNewFor130 = YES;
  580. }
  581. else{
  582. ksharedAppDelegate.isImageNewFor130 = NO;
  583. }
  584. }
  585. }
  586. else{
  587. ksharedAppDelegate.DisabledFileTransferType = NO;
  588. }
  589. }
  590. }
  591. - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
  592. {
  593. TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
  594. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
  595. if(![model.msg containsString:@"PushStreamBActivity"])
  596. {
  597. return;
  598. }
  599. HLog(@"hxd 待处理")
  600. // UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  601. // if([topVc isKindOfClass:[PlayerViewController class]]){
  602. // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  603. // }
  604. }
  605. - (void)stopForceStartTimerFun
  606. {
  607. HLog(@"hxd 待处理")
  608. // if(forceStartTimer){
  609. // [forceStartTimer invalidate];
  610. // forceStartTimer = nil;
  611. // }
  612. }
  613. - (void)createFolderResponseFun:(NSDictionary *)dataDict
  614. {
  615. couldPhoneCommonModel *model = [[couldPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  616. if(model){
  617. NSNumber *curNum = [NSNumber numberWithInteger:model.status];
  618. [[NSNotificationCenter defaultCenter] postNotificationName:createFolderDoneNotification object:curNum];/*发送通知*/
  619. }
  620. }
  621. - (void)getFolderListResponseFun:(NSDictionary *)dataDict
  622. {
  623. [[NSNotificationCenter defaultCenter] postNotificationName:getFolderListDoneNotification object:dataDict];/*发送通知*/
  624. }
  625. - (void)searchFileListResponseFun:(NSDictionary *)dataDict
  626. {
  627. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListDoneNotification object:dataDict];/*发送通知*/
  628. }
  629. #pragma mark 获取云机已经外挂产品
  630. - (void)getExtraFilesResponseFun:(NSDictionary *)dataDict
  631. {
  632. cloudPhoneExtraFileListModel *model = [[cloudPhoneExtraFileListModel alloc] initWithDictionary:dataDict error:nil];
  633. ksharedAppDelegate.cloudPhoneExtraFileListMod = model;
  634. [[NSNotificationCenter defaultCenter] postNotificationName:getExtraFilesDoneNotification object:dataDict];/*发送通知*/
  635. }
  636. - (void)getExtraMediaEventResponseFun:(NSDictionary *)dataDict
  637. {
  638. extraMediaEventModel *model = [[extraMediaEventModel alloc] initWithDictionary:dataDict error:nil];
  639. NSString *tip = nil;
  640. if(model.data.event == 0){
  641. tip = NSLocalizedString(@"disk_insertion_tip",nil);
  642. [self showInsertPopViewFun:model.data.name];
  643. }
  644. else if(model.data.event == 1){
  645. tip = NSLocalizedString(@"disk_extract_tip",nil);
  646. }
  647. else if(model.data.event == 2){
  648. tip = NSLocalizedString(@"disk_save_extract_tip",nil);
  649. }
  650. NSString *totalTips = [[NSString alloc] initWithFormat:@"%@%@",model.data.name,tip];
  651. mainBlock(^{
  652. [[iToast makeText:totalTips] show];
  653. });
  654. }
  655. #pragma mark 显示插入UI弹框
  656. - (void)showInsertPopViewFun:(NSString*)name
  657. {
  658. HLog(@"hxd 待处理")
  659. // if(self->curUSBInsertPopV){
  660. // [self->curUSBInsertPopV removeFromSuperview];
  661. // self->curUSBInsertPopV = nil;
  662. // }
  663. //
  664. // self->curUSBInsertPopV = [[USBInsertPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) withName:name];
  665. //
  666. // UIViewController*lastVC = self.navigationController.viewControllers.lastObject;
  667. // //[[iTools getKeyWindow] addSubview:self->curUSBInsertPopV];
  668. // [lastVC.view addSubview:self->curUSBInsertPopV];
  669. }
  670. - (void)createBackupsFolderBy:(NSString*)backupsDefaultPath
  671. {
  672. NSString *folderName = backupsDefaultPath;
  673. if(folderName && folderName.length >0){
  674. NSString * commandStr = [RCCommandHelp applyForCreateFolderwithFolderName:folderName];
  675. [self.commandChannelManager rc_sendData:commandStr];
  676. }
  677. }
  678. - (void)getBackupFolderListFun
  679. {
  680. NSString * commandStr = [RCCommandHelp getCreateFolderList];
  681. [self.commandChannelManager rc_sendData:commandStr];
  682. }
  683. - (void)searchFileListBeginFun:(NSMutableDictionary *)dict
  684. {
  685. NSMutableDictionary *objectDict = dict;
  686. NSNumber *curNum = @1;
  687. if ([[objectDict allKeys] containsObject:@"type"]) {
  688. curNum = [objectDict objectForKey:@"type"];
  689. }
  690. NSString *pathStr = @"";
  691. if ([[objectDict allKeys] containsObject:@"path"]) {
  692. pathStr = [objectDict objectForKey:@"path"];
  693. }
  694. NSString *fileType = @"video";
  695. if(curNum.boolValue)
  696. {
  697. fileType = @"jpg";
  698. }
  699. NSString * commandStr = [RCCommandHelp searchCouldPhoneFilewithType:fileType withPath:pathStr];
  700. [self.commandChannelManager rc_sendData:commandStr];
  701. }
  702. #pragma mark 获取云机基本信息
  703. - (void)getBaseInfoFun
  704. {
  705. NSString *commondStr = @"{\"type\":\"getBaseInfo\"}";
  706. [self send_data:commondStr];
  707. }
  708. #pragma mark 获取云机系统镜像等信息
  709. - (void)getSysInfoFun
  710. {
  711. NSString *commondStr = @"{\"type\":\"getSysInfo\"}";
  712. [self send_data:commondStr];
  713. }
  714. @end