webSocketManager.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. }
  399. #pragma mark 盒子第一次连接成功 给ws发送信息 单点登录 把其他账号挤下去
  400. - (void)fristConnectNeedGiveAMsgFun{
  401. if(!_didSendfristMsg )
  402. {
  403. NSString *commondStr3 = @"{\"type\":\"getSysInfo\"}";
  404. [self send_data:commondStr3];
  405. // NSString *commondStr = @"{\"type\":\"forwardMsg\",\"data\":\"offline_notification\"}";
  406. // [self send_data:commondStr];
  407. // [self addCommandSendTaskFunWithType:@"offline_notification" WithCommandStr:commondStr];
  408. _didSendfristMsg = true;
  409. [self getPreferredLanguage];
  410. NSString *commondStr2 = @"{\"type\":\"TvStatus\"}";
  411. [self send_data:commondStr2];
  412. }
  413. }
  414. #pragma mark 语言和市区 同步云机
  415. -(void)getPreferredLanguage
  416. {//{"data":{"language":"zh-CN","timeZone":"Etc/GMT+8"},"type":"setLanguages"}
  417. // iOS 获取设备当前语言的代码
  418. NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
  419. HLog(@"当前语言:%@", preferredLanguage);
  420. //en-US 英文 ja-JP 日文
  421. NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  422. NSLog(@"arLanguages:%@",arLanguages);
  423. ///获取设备当前地区的代码和APP语言环境
  424. NSString *languageCode = [NSLocale preferredLanguages][0];
  425. //目前支持 中文(简体 繁体) 英文 日语
  426. if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
  427. {
  428. preferredLanguage = @"zh-CN";
  429. }
  430. else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
  431. {
  432. preferredLanguage = @"zh-HK";
  433. }
  434. else if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  435. {
  436. preferredLanguage = @"ja-JP";
  437. }
  438. else{
  439. preferredLanguage = @"en-US";
  440. }
  441. // if([languageCode rangeOfString:preferredLanguage].location != NSNotFound){
  442. // preferredLanguage = languageCode;
  443. // }
  444. // else{
  445. // preferredLanguage = @"en-US";
  446. // }
  447. NSString*gmtStr = [self UTCOffset];
  448. HLog(@"%@",gmtStr);
  449. // //获取名字,如“GMT+08:00
  450. NSString *commondStr = [NSString stringWithFormat:@"{\"type\":\"setLanguages\",\"data\":{\"language\":\"%@\",\"timeZone\":\"%@\"}}",preferredLanguage,gmtStr];
  451. [self send_data:commondStr];
  452. }
  453. -(NSString *)UTCOffset {
  454. NSTimeZone *localTZ = [NSTimeZone localTimeZone];
  455. float offset = localTZ.secondsFromGMT/3600.0;
  456. if(offset > 0){
  457. return [NSString stringWithFormat:@"Etc/GMT+%g",offset];
  458. }
  459. return [NSString stringWithFormat:@"Etc/GMT%g",offset];
  460. }
  461. - (void)updateCopydata{
  462. UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  463. NSString *str = [pasteboard string];
  464. HLog(@"__________%s______%@____",__func__,str);
  465. if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound)
  466. {
  467. str = nil;
  468. }
  469. if (str && str.length >0)
  470. {
  471. //HLog(@"hxd111 cutting %@",str);
  472. /*发送数据*/
  473. NSString *dataStr = [RCCommandHelp commandCuttingWithContent:str];
  474. [self.commandChannelManager rc_sendData:dataStr];
  475. //pasteboard.string = @"";
  476. }
  477. }
  478. #pragma mark 获取外挂产品
  479. - (void)getExtraFilesListFun
  480. {
  481. NSString *ExtraCommondStr = [RCCommandHelp getExtraFilesList];
  482. [self send_data:ExtraCommondStr];
  483. }
  484. -(void)addCommandSendTaskFunWithType:(NSString*)type WithCommandStr:(NSString*)commandStr
  485. {
  486. if(!commandSendCheckArr){
  487. commandSendCheckArr = [NSMutableArray new];
  488. }
  489. BOOL didAddType = NO;
  490. for (commandSendCheckModel *model in commandSendCheckArr) {
  491. if([model.type isEqualToString:type]){
  492. didAddType = YES;
  493. model.reSendNum = 0;
  494. model.sendTimerStamp = [iTools getNowTimeStamp];
  495. break;
  496. }
  497. }
  498. if(!didAddType){
  499. commandSendCheckModel *model = [commandSendCheckModel new];
  500. model.commandStr = commandStr;
  501. model.type = type;
  502. model.reSendNum = 0;
  503. model.sendTimerStamp = [iTools getNowTimeStamp];
  504. [commandSendCheckArr addObject:model];
  505. }
  506. }
  507. -(void)deleteCommandSendTaskFunWith:(NSString*)type
  508. {
  509. if(commandSendCheckArr && commandSendCheckArr.count >0){
  510. NSArray *taskArr = [NSArray arrayWithArray:commandSendCheckArr];
  511. for (commandSendCheckModel *model in taskArr) {
  512. if([type isEqualToString:model.type]){
  513. [commandSendCheckArr removeObject:model];
  514. }
  515. }
  516. }
  517. }
  518. #pragma mark wifi handle
  519. - (void)sync_wifiBackHandleFun
  520. {
  521. [self.commandChannelManager rc_sendData:[RCCommandHelp noSyncWifiBack]];
  522. [[iToast makeText:NSLocalizedString(@"player_Tip_ios_no_wifi_Sync",nil)] show];
  523. }
  524. - (void)getCouldPhoneBaseInfoResponseFun:(NSDictionary *)dataDict
  525. {
  526. couldPhoneBaseInfoModel *model = [[couldPhoneBaseInfoModel alloc] initWithDictionary:dataDict error:nil];
  527. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneBaseInfoNotification object:model];
  528. }
  529. - (void)getCouldPhoneSysInfoResponseFun:(NSDictionary *)dataDict{
  530. couldphoneSysInfoModel *model = [[couldphoneSysInfoModel alloc] initWithDictionary:dataDict error:nil];
  531. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
  532. NSString *hostImgVer = model.data.data.hostImgVer;
  533. NSString *MyNewVersion = model.data.data.MyNewVersion;
  534. //test code
  535. // hostImgVer = @"1.2.3";
  536. // MyNewVersion = @"1.2.0";
  537. //判断当前版本号 待更新版本
  538. if (!hostImgVer || hostImgVer.length < 3
  539. ||!MyNewVersion || MyNewVersion.length < 3) {
  540. //[self showImageViewRenewTipViewFun];
  541. return;
  542. }
  543. NSArray *versionArr = [hostImgVer componentsSeparatedByString:@"."];
  544. NSArray *MyNewVersionArr = [MyNewVersion componentsSeparatedByString:@"."];
  545. NSInteger versionArrCount = versionArr.count;
  546. NSInteger MyNewVersionArrCount = MyNewVersionArr.count;
  547. NSInteger maxCount = versionArrCount < MyNewVersionArrCount ? versionArrCount:MyNewVersionArrCount;
  548. BOOL isNeedShowType = NO;
  549. //判断是否要更新镜像框
  550. if(maxCount > 0){
  551. for (int i=0; i<maxCount; i++) {
  552. NSString * numberStr1 = versionArr[i];
  553. NSString * numberStr2 = MyNewVersionArr[i];
  554. if(numberStr2.intValue > numberStr1.intValue){
  555. isNeedShowType =YES;
  556. break;
  557. }
  558. }
  559. }
  560. if(isNeedShowType){
  561. HLog(@"hxd 镜像弹框 待处理")
  562. //[self showImageViewRenewTipViewFun];
  563. }
  564. //是否禁用文件传输 (1.3以及以上的镜像可以使用文件传输)
  565. if(versionArr.count >= 3)
  566. {
  567. NSString * oneStr = versionArr[0];
  568. NSString * twoStr = versionArr[1];
  569. NSString * threeStr = versionArr[2];
  570. if(oneStr.integerValue <=1 && twoStr.integerValue <=3 && threeStr.integerValue <=0){//禁用
  571. ksharedAppDelegate.DisabledFileTransferType = YES;
  572. if(MyNewVersionArr.count >= 3)
  573. {
  574. NSString * newOneStr = MyNewVersionArr[0];
  575. NSString * newTwoStr = MyNewVersionArr[1];
  576. NSString * newThreeStr = MyNewVersionArr[2];
  577. if(newOneStr.integerValue >=1 && newTwoStr.integerValue >=3 && newThreeStr.integerValue >= 1){
  578. ksharedAppDelegate.isImageNewFor130 = YES;
  579. }
  580. else{
  581. ksharedAppDelegate.isImageNewFor130 = NO;
  582. }
  583. }
  584. }
  585. else{
  586. ksharedAppDelegate.DisabledFileTransferType = NO;
  587. }
  588. }
  589. }
  590. - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
  591. {
  592. TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
  593. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
  594. if(![model.msg containsString:@"PushStreamBActivity"])
  595. {
  596. return;
  597. }
  598. HLog(@"hxd 待处理")
  599. // UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  600. // if([topVc isKindOfClass:[PlayerViewController class]]){
  601. // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  602. // }
  603. }
  604. - (void)stopForceStartTimerFun
  605. {
  606. HLog(@"hxd 待处理")
  607. // if(forceStartTimer){
  608. // [forceStartTimer invalidate];
  609. // forceStartTimer = nil;
  610. // }
  611. }
  612. - (void)createFolderResponseFun:(NSDictionary *)dataDict
  613. {
  614. couldPhoneCommonModel *model = [[couldPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  615. if(model){
  616. NSNumber *curNum = [NSNumber numberWithInteger:model.status];
  617. [[NSNotificationCenter defaultCenter] postNotificationName:createFolderDoneNotification object:curNum];/*发送通知*/
  618. }
  619. }
  620. - (void)getFolderListResponseFun:(NSDictionary *)dataDict
  621. {
  622. [[NSNotificationCenter defaultCenter] postNotificationName:getFolderListDoneNotification object:dataDict];/*发送通知*/
  623. }
  624. - (void)searchFileListResponseFun:(NSDictionary *)dataDict
  625. {
  626. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListDoneNotification object:dataDict];/*发送通知*/
  627. }
  628. - (void)getExtraFilesResponseFun:(NSDictionary *)dataDict
  629. {
  630. cloudPhoneExtraFileListModel *model = [[cloudPhoneExtraFileListModel alloc] initWithDictionary:dataDict error:nil];
  631. ksharedAppDelegate.cloudPhoneExtraFileListMod = model;
  632. }
  633. - (void)getExtraMediaEventResponseFun:(NSDictionary *)dataDict
  634. {
  635. extraMediaEventModel *model = [[extraMediaEventModel alloc] initWithDictionary:dataDict error:nil];
  636. NSString *tip = nil;
  637. if(model.data.event == 0){
  638. tip = NSLocalizedString(@"disk_insertion_tip",nil);
  639. [self showInsertPopViewFun:model.data.name];
  640. }
  641. else if(model.data.event == 1){
  642. tip = NSLocalizedString(@"disk_extract_tip",nil);
  643. }
  644. else if(model.data.event == 2){
  645. tip = NSLocalizedString(@"disk_save_extract_tip",nil);
  646. }
  647. NSString *totalTips = [[NSString alloc] initWithFormat:@"%@%@",model.data.name,tip];
  648. mainBlock(^{
  649. [[iToast makeText:totalTips] show];
  650. });
  651. }
  652. #pragma mark 显示插入UI弹框
  653. - (void)showInsertPopViewFun:(NSString*)name
  654. {
  655. HLog(@"hxd 待处理")
  656. // if(self->curUSBInsertPopV){
  657. // [self->curUSBInsertPopV removeFromSuperview];
  658. // self->curUSBInsertPopV = nil;
  659. // }
  660. //
  661. // self->curUSBInsertPopV = [[USBInsertPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) withName:name];
  662. //
  663. // UIViewController*lastVC = self.navigationController.viewControllers.lastObject;
  664. // //[[iTools getKeyWindow] addSubview:self->curUSBInsertPopV];
  665. // [lastVC.view addSubview:self->curUSBInsertPopV];
  666. }
  667. - (void)createBackupsFolderBy:(NSString*)backupsDefaultPath
  668. {
  669. NSString *folderName = backupsDefaultPath;
  670. if(folderName && folderName.length >0){
  671. NSString * commandStr = [RCCommandHelp applyForCreateFolderwithFolderName:folderName];
  672. [self.commandChannelManager rc_sendData:commandStr];
  673. }
  674. }
  675. - (void)getBackupFolderListFun
  676. {
  677. NSString * commandStr = [RCCommandHelp getCreateFolderList];
  678. [self.commandChannelManager rc_sendData:commandStr];
  679. }
  680. - (void)searchFileListBeginFun:(NSMutableDictionary *)dict
  681. {
  682. NSMutableDictionary *objectDict = dict;
  683. NSNumber *curNum = @1;
  684. if ([[objectDict allKeys] containsObject:@"type"]) {
  685. curNum = [objectDict objectForKey:@"type"];
  686. }
  687. NSString *pathStr = @"";
  688. if ([[objectDict allKeys] containsObject:@"path"]) {
  689. pathStr = [objectDict objectForKey:@"path"];
  690. }
  691. NSString *fileType = @"video";
  692. if(curNum.boolValue)
  693. {
  694. fileType = @"jpg";
  695. }
  696. NSString * commandStr = [RCCommandHelp searchCouldPhoneFilewithType:fileType withPath:pathStr];
  697. [self.commandChannelManager rc_sendData:commandStr];
  698. }
  699. #pragma mark 获取云机剩余空间
  700. - (void)getBaseInfoFun
  701. {
  702. NSString *commondStr = @"{\"type\":\"getBaseInfo\"}";
  703. [self send_data:commondStr];
  704. }
  705. @end