webSocketManager.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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:@"TvOff"]){/*关闭TV投屏*/
  255. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  256. [weakSelf getTvStatusFun];
  257. });
  258. }
  259. else if ([messageType isEqualToString:@"wakeupTV"]){/*开启TV投屏*/
  260. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  261. [weakSelf getTvStatusFun];
  262. });
  263. }
  264. else if ([messageType isEqualToString:@"reboot"]){/*重启*/
  265. [weakSelf stopForceStartTimerFun];
  266. }
  267. else if ([messageType isEqualToString:@"mkdir"]){/*创建文件夹*/
  268. [weakSelf createFolderResponseFun:dataDict];
  269. }
  270. else if ([messageType isEqualToString:@"getBackupPath"]){/*创建文件夹*/
  271. [weakSelf getFolderListResponseFun:dataDict];
  272. }
  273. else if ([messageType isEqualToString:@"search"]){/*创建文件夹*/
  274. [weakSelf searchFileListResponseFun:dataDict];
  275. }
  276. else if ([messageType isEqualToString:@"getExtraFiles"]){/*创建文件夹*/
  277. [weakSelf getExtraFilesResponseFun:dataDict];
  278. }
  279. else if ([messageType isEqualToString:@"extraMediaEvent"]){/*磁盘插拔*/
  280. [weakSelf getExtraMediaEventResponseFun:dataDict];
  281. [weakSelf getExtraFilesListFun];
  282. }
  283. else if ([messageType isEqualToString:@"reset"]){/**/
  284. [weakSelf deleteCommandSendTaskFunWith:@"reset"];
  285. }
  286. } failure:^(NSError *error) {
  287. ksharedAppDelegate.isWebSockLinkOKAginType = NO;
  288. // [self showNetErrorAlertFun:2];
  289. // [self WebSocketNeedRelinkFun];
  290. }];
  291. }
  292. }
  293. - (void)keepWebSocketOKFun
  294. {
  295. self.webSocketTime = 0;
  296. }
  297. - (void)WebSocketNeedRelinkFun
  298. {
  299. self.webSocketTime = 0;
  300. if(self.commandChannelManager){
  301. [self opencommandChannelManagerrc_openURL];
  302. }
  303. }
  304. - (void)timerChange {
  305. //处理websockt是否断开
  306. self.webSocketTime += 2;
  307. //处理其他任务
  308. self.webSocketTaskTime += 2;
  309. if(self.webSocketTime > 8)
  310. {
  311. [self WebSocketNeedRelinkFun];
  312. }
  313. if(self.webSocketTaskTime > 10)
  314. {
  315. self.webSocketTaskTime = 0;
  316. [self checkAllTaskFun];
  317. }
  318. }
  319. - (void)checkAllTaskFun
  320. {
  321. if([self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusConnected
  322. ||[self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusReceived){
  323. HLog(@"WebSocket 链接正常");
  324. }
  325. else{
  326. HLog(@"WebSocket 链接异常:%ld",[self.commandChannelManager rc_socketStatus]);
  327. return;
  328. }
  329. //处理相册备份
  330. [[backupsFileManager shareInstance] checkReBackupsFileFun];
  331. [[uploadFileManager shareInstance] checkReUploadFileFun];
  332. [[downloadManager shareInstance] checkReDownloadFileFun];
  333. [[downloadThumbnailManager shareInstance] checkReDownloadThumbnailFileFun];
  334. [self checkCommandSendTaskFun];
  335. if([AudioSessionObject shareManager].isBackgroundType){
  336. [self checkFileTransfeTaskFun];
  337. }
  338. HLog(@"checkAllTaskFun");
  339. }
  340. //检测是否正在进行的文件传输任务
  341. - (void)checkFileTransfeTaskFun
  342. {
  343. BOOL isBackupsingType = [[backupsFileManager shareInstance] checkBackupsingFun];
  344. BOOL isUploadingType = [[uploadFileManager shareInstance] checkUploadingFun];
  345. BOOL isDownloadingType = [[downloadManager shareInstance] checkDownloadingFun];
  346. BOOL isBackground = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_working_background)];
  347. BOOL isNasDownloadingType = [customDownloadManager shareManager].isDownLoadIngType;
  348. if ((isBackupsingType || isUploadingType || isDownloadingType ||isNasDownloadingType) && isBackground) {
  349. HLog(@"后台保活中");
  350. [cachesFileManager writeLogsWithMsg:@"Background working"];
  351. }
  352. else{
  353. HLog(@"停止后台保活");
  354. [cachesFileManager writeLogsWithMsg:@"stop Background working"];
  355. [[AudioSessionObject shareManager] stopBackgroundActiveFun];
  356. }
  357. }
  358. -(void)checkCommandSendTaskFun
  359. {
  360. if(commandSendCheckArr && commandSendCheckArr.count >0){
  361. for (commandSendCheckModel *model in commandSendCheckArr) {
  362. if(model.reSendNum < 3){
  363. model.reSendNum ++;
  364. if(model.commandStr){
  365. [self send_data:model.commandStr];
  366. HLog(@"\n\n\n任务重发 重发次数:%ld 指令:%@\n\n\n",model.reSendNum,model.commandStr);
  367. }
  368. // if([model.type isEqualToString:@"offline_notification"]){
  369. // model.reSendNum = 1;//只要不收到
  370. // }
  371. }
  372. }
  373. }
  374. }
  375. - (void)send_data:(NSString *)dataStr
  376. {
  377. [self.commandChannelManager rc_sendData:dataStr];
  378. }
  379. #pragma mark 盒子链接成功后需要处理的各种各样事情
  380. - (void)handlAllMsgAfterDidLinkFun
  381. {
  382. ksharedAppDelegate.isWebSockLinkOKAginType = YES;
  383. //获取云机尺寸 兼容 720*1080 &1080*1920 不同分辨率的展示和触控
  384. NSString *getPhoneSizeStr = [RCCommandHelp getPhoneSizecommand];
  385. [self send_data:getPhoneSizeStr];
  386. //判断是否为需要改机
  387. BOOL isNeedRandomChangeParams = [HWDataManager getBoolWithKey:Const_need_random_Change_Params];
  388. if(isNeedRandomChangeParams)
  389. {
  390. NSString *commondStr = @"{\"type\":\"randomChangeParams\"}";
  391. [self send_data:commondStr];
  392. [HWDataManager setBoolWithKey:Const_need_random_Change_Params value:NO];
  393. }
  394. [self fristConnectNeedGiveAMsgFun];
  395. [self updateCopydata];
  396. // 报链接失败 后面又连接上了
  397. // if(linkFailAlretVC && linkFailAlretVC.view.tag == 2){
  398. // mainBlock(^{
  399. // [self->linkFailAlretVC dismissViewControllerAnimated:YES completion:^{
  400. //
  401. // }];
  402. // self->linkFailAlretVC = nil;
  403. // });
  404. // }
  405. //处理相册备份
  406. [[backupsFileManager shareInstance] AutohandlePhotosBackupsFun];
  407. //获取磁盘外挂
  408. [self getExtraFilesListFun];
  409. [self getBaseInfoFun];
  410. [self getTvStatusFun];
  411. }
  412. #pragma mark 盒子第一次连接成功 给ws发送信息 单点登录 把其他账号挤下去
  413. - (void)fristConnectNeedGiveAMsgFun{
  414. if(!_didSendfristMsg )
  415. {
  416. NSString *commondStr3 = @"{\"type\":\"getSysInfo\"}";
  417. [self send_data:commondStr3];
  418. // NSString *commondStr = @"{\"type\":\"forwardMsg\",\"data\":\"offline_notification\"}";
  419. // [self send_data:commondStr];
  420. // [self addCommandSendTaskFunWithType:@"offline_notification" WithCommandStr:commondStr];
  421. _didSendfristMsg = true;
  422. [self getPreferredLanguage];
  423. NSString *commondStr2 = @"{\"type\":\"TvStatus\"}";
  424. [self send_data:commondStr2];
  425. }
  426. }
  427. #pragma mark 语言和市区 同步云机
  428. -(void)getPreferredLanguage
  429. {//{"data":{"language":"zh-CN","timeZone":"Etc/GMT+8"},"type":"setLanguages"}
  430. // iOS 获取设备当前语言的代码
  431. NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
  432. HLog(@"当前语言:%@", preferredLanguage);
  433. //en-US 英文 ja-JP 日文
  434. NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  435. NSLog(@"arLanguages:%@",arLanguages);
  436. ///获取设备当前地区的代码和APP语言环境
  437. NSString *languageCode = [NSLocale preferredLanguages][0];
  438. //目前支持 中文(简体 繁体) 英文 日语
  439. if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
  440. {
  441. preferredLanguage = @"zh-CN";
  442. }
  443. else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
  444. {
  445. preferredLanguage = @"zh-HK";
  446. }
  447. else if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  448. {
  449. preferredLanguage = @"ja-JP";
  450. }
  451. else{
  452. preferredLanguage = @"en-US";
  453. }
  454. // if([languageCode rangeOfString:preferredLanguage].location != NSNotFound){
  455. // preferredLanguage = languageCode;
  456. // }
  457. // else{
  458. // preferredLanguage = @"en-US";
  459. // }
  460. NSString*gmtStr = [self UTCOffset];
  461. HLog(@"%@",gmtStr);
  462. // //获取名字,如“GMT+08:00
  463. NSString *commondStr = [NSString stringWithFormat:@"{\"type\":\"setLanguages\",\"data\":{\"language\":\"%@\",\"timeZone\":\"%@\"}}",preferredLanguage,gmtStr];
  464. [self send_data:commondStr];
  465. }
  466. -(NSString *)UTCOffset {
  467. NSTimeZone *localTZ = [NSTimeZone localTimeZone];
  468. float offset = localTZ.secondsFromGMT/3600.0;
  469. if(offset > 0){
  470. return [NSString stringWithFormat:@"Etc/GMT+%g",offset];
  471. }
  472. return [NSString stringWithFormat:@"Etc/GMT%g",offset];
  473. }
  474. #pragma mark 重启云机
  475. - (void)needToRebootFun
  476. {
  477. NSString *commondStr = @"{\"type\":\"reboot\"}";
  478. [self send_data:commondStr];
  479. //添加到任务监听
  480. [self addCommandSendTaskFunWithType:@"reboot" WithCommandStr:commondStr];
  481. //数据埋点
  482. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Cloud_restart"];
  483. }
  484. - (void)needToResetFun
  485. {
  486. NSString *commondStr = @"{\"type\":\"reset\"}";
  487. [self send_data:commondStr];
  488. //添加到任务监听
  489. [self addCommandSendTaskFunWithType:@"reset" WithCommandStr:commondStr];
  490. //数据埋点
  491. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Cloud_restore_factory"];
  492. }
  493. - (void)updateCopydata{
  494. UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  495. NSString *str = [pasteboard string];
  496. HLog(@"__________%s______%@____",__func__,str);
  497. if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound)
  498. {
  499. str = nil;
  500. }
  501. if (str && str.length >0)
  502. {
  503. //HLog(@"hxd111 cutting %@",str);
  504. /*发送数据*/
  505. NSString *dataStr = [RCCommandHelp commandCuttingWithContent:str];
  506. [self.commandChannelManager rc_sendData:dataStr];
  507. //pasteboard.string = @"";
  508. }
  509. }
  510. #pragma mark 获取云机以及外挂磁盘
  511. - (void)getExtraFilesListFun
  512. {
  513. NSString *ExtraCommondStr = [RCCommandHelp getExtraFilesList];
  514. [self send_data:ExtraCommondStr];
  515. }
  516. -(void)addCommandSendTaskFunWithType:(NSString*)type WithCommandStr:(NSString*)commandStr
  517. {
  518. if(!commandSendCheckArr){
  519. commandSendCheckArr = [NSMutableArray new];
  520. }
  521. BOOL didAddType = NO;
  522. for (commandSendCheckModel *model in commandSendCheckArr) {
  523. if([model.type isEqualToString:type]){
  524. didAddType = YES;
  525. model.reSendNum = 0;
  526. model.sendTimerStamp = [iTools getNowTimeStamp];
  527. break;
  528. }
  529. }
  530. if(!didAddType){
  531. commandSendCheckModel *model = [commandSendCheckModel new];
  532. model.commandStr = commandStr;
  533. model.type = type;
  534. model.reSendNum = 0;
  535. model.sendTimerStamp = [iTools getNowTimeStamp];
  536. [commandSendCheckArr addObject:model];
  537. }
  538. }
  539. -(void)deleteCommandSendTaskFunWith:(NSString*)type
  540. {
  541. if(commandSendCheckArr && commandSendCheckArr.count >0){
  542. NSArray *taskArr = [NSArray arrayWithArray:commandSendCheckArr];
  543. for (commandSendCheckModel *model in taskArr) {
  544. if([type isEqualToString:model.type]){
  545. [commandSendCheckArr removeObject:model];
  546. }
  547. }
  548. }
  549. }
  550. #pragma mark wifi handle
  551. - (void)sync_wifiBackHandleFun
  552. {
  553. [self.commandChannelManager rc_sendData:[RCCommandHelp noSyncWifiBack]];
  554. [[iToast makeText:NSLocalizedString(@"player_Tip_ios_no_wifi_Sync",nil)] show];
  555. }
  556. - (void)getCouldPhoneBaseInfoResponseFun:(NSDictionary *)dataDict
  557. {
  558. couldPhoneBaseInfoModel *model = [[couldPhoneBaseInfoModel alloc] initWithDictionary:dataDict error:nil];
  559. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneBaseInfoNotification object:model];
  560. }
  561. - (void)getCouldPhoneSysInfoResponseFun:(NSDictionary *)dataDict{
  562. couldphoneSysInfoModel *model = [[couldphoneSysInfoModel alloc] initWithDictionary:dataDict error:nil];
  563. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
  564. NSString *hostImgVer = model.data.data.hostImgVer;
  565. NSString *MyNewVersion = model.data.data.MyNewVersion;
  566. //test code
  567. // hostImgVer = @"1.2.3";
  568. // MyNewVersion = @"1.2.0";
  569. //判断当前版本号 待更新版本
  570. if (!hostImgVer || hostImgVer.length < 3
  571. ||!MyNewVersion || MyNewVersion.length < 3) {
  572. //[self showImageViewRenewTipViewFun];
  573. return;
  574. }
  575. NSArray *versionArr = [hostImgVer componentsSeparatedByString:@"."];
  576. NSArray *MyNewVersionArr = [MyNewVersion componentsSeparatedByString:@"."];
  577. NSInteger versionArrCount = versionArr.count;
  578. NSInteger MyNewVersionArrCount = MyNewVersionArr.count;
  579. NSInteger maxCount = versionArrCount < MyNewVersionArrCount ? versionArrCount:MyNewVersionArrCount;
  580. BOOL isNeedShowType = NO;
  581. //判断是否要更新镜像框
  582. if(maxCount > 0){
  583. for (int i=0; i<maxCount; i++) {
  584. NSString * numberStr1 = versionArr[i];
  585. NSString * numberStr2 = MyNewVersionArr[i];
  586. if(numberStr2.intValue > numberStr1.intValue){
  587. isNeedShowType =YES;
  588. break;
  589. }
  590. }
  591. }
  592. if(isNeedShowType){
  593. HLog(@"hxd 镜像弹框 待处理")
  594. //[self showImageViewRenewTipViewFun];
  595. }
  596. //是否禁用文件传输 (1.3以及以上的镜像可以使用文件传输)
  597. if(versionArr.count >= 3)
  598. {
  599. NSString * oneStr = versionArr[0];
  600. NSString * twoStr = versionArr[1];
  601. NSString * threeStr = versionArr[2];
  602. if(oneStr.integerValue <=1 && twoStr.integerValue <=3 && threeStr.integerValue <=0){//禁用
  603. ksharedAppDelegate.DisabledFileTransferType = YES;
  604. if(MyNewVersionArr.count >= 3)
  605. {
  606. NSString * newOneStr = MyNewVersionArr[0];
  607. NSString * newTwoStr = MyNewVersionArr[1];
  608. NSString * newThreeStr = MyNewVersionArr[2];
  609. if(newOneStr.integerValue >=1 && newTwoStr.integerValue >=3 && newThreeStr.integerValue >= 1){
  610. ksharedAppDelegate.isImageNewFor130 = YES;
  611. }
  612. else{
  613. ksharedAppDelegate.isImageNewFor130 = NO;
  614. }
  615. }
  616. }
  617. else{
  618. ksharedAppDelegate.DisabledFileTransferType = NO;
  619. }
  620. }
  621. }
  622. - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
  623. {
  624. TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
  625. ksharedAppDelegate.TvStatusMod = model;
  626. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
  627. // if(![model.msg containsString:@"PushStreamBActivity"])
  628. // {
  629. // return;
  630. // }
  631. //
  632. // UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  633. // if([topVc isKindOfClass:[PlayerViewController class]]){
  634. // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  635. // }
  636. }
  637. - (void)stopForceStartTimerFun
  638. {
  639. HLog(@"hxd 待处理")
  640. // if(forceStartTimer){
  641. // [forceStartTimer invalidate];
  642. // forceStartTimer = nil;
  643. // }
  644. }
  645. - (void)createFolderResponseFun:(NSDictionary *)dataDict
  646. {
  647. couldPhoneCommonModel *model = [[couldPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  648. if(model){
  649. NSNumber *curNum = [NSNumber numberWithInteger:model.status];
  650. [[NSNotificationCenter defaultCenter] postNotificationName:createFolderDoneNotification object:curNum];/*发送通知*/
  651. }
  652. }
  653. - (void)getFolderListResponseFun:(NSDictionary *)dataDict
  654. {
  655. [[NSNotificationCenter defaultCenter] postNotificationName:getFolderListDoneNotification object:dataDict];/*发送通知*/
  656. }
  657. - (void)searchFileListResponseFun:(NSDictionary *)dataDict
  658. {
  659. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListDoneNotification object:dataDict];/*发送通知*/
  660. }
  661. #pragma mark 获取云机已经外挂产品
  662. - (void)getExtraFilesResponseFun:(NSDictionary *)dataDict
  663. {
  664. cloudPhoneExtraFileListModel *model = [[cloudPhoneExtraFileListModel alloc] initWithDictionary:dataDict error:nil];
  665. ksharedAppDelegate.cloudPhoneExtraFileListMod = model;
  666. [[NSNotificationCenter defaultCenter] postNotificationName:getExtraFilesDoneNotification object:dataDict];/*发送通知*/
  667. }
  668. - (void)getExtraMediaEventResponseFun:(NSDictionary *)dataDict
  669. {
  670. extraMediaEventModel *model = [[extraMediaEventModel alloc] initWithDictionary:dataDict error:nil];
  671. NSString *tip = nil;
  672. if(model.data.event == 0){
  673. tip = NSLocalizedString(@"disk_insertion_tip",nil);
  674. [self showInsertPopViewFun:model.data.name];
  675. }
  676. else if(model.data.event == 1){
  677. tip = NSLocalizedString(@"disk_extract_tip",nil);
  678. }
  679. else if(model.data.event == 2){
  680. tip = NSLocalizedString(@"disk_save_extract_tip",nil);
  681. }
  682. NSString *totalTips = [[NSString alloc] initWithFormat:@"%@%@",model.data.name,tip];
  683. mainBlock(^{
  684. [[iToast makeText:totalTips] show];
  685. });
  686. }
  687. #pragma mark 显示插入UI弹框
  688. - (void)showInsertPopViewFun:(NSString*)name
  689. {
  690. HLog(@"hxd 待处理")
  691. // if(self->curUSBInsertPopV){
  692. // [self->curUSBInsertPopV removeFromSuperview];
  693. // self->curUSBInsertPopV = nil;
  694. // }
  695. //
  696. // self->curUSBInsertPopV = [[USBInsertPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) withName:name];
  697. //
  698. // UIViewController*lastVC = self.navigationController.viewControllers.lastObject;
  699. // //[[iTools getKeyWindow] addSubview:self->curUSBInsertPopV];
  700. // [lastVC.view addSubview:self->curUSBInsertPopV];
  701. }
  702. - (void)createBackupsFolderBy:(NSString*)backupsDefaultPath
  703. {
  704. NSString *folderName = backupsDefaultPath;
  705. if(folderName && folderName.length >0){
  706. NSString * commandStr = [RCCommandHelp applyForCreateFolderwithFolderName:folderName];
  707. [self.commandChannelManager rc_sendData:commandStr];
  708. }
  709. }
  710. - (void)getBackupFolderListFun
  711. {
  712. NSString * commandStr = [RCCommandHelp getCreateFolderList];
  713. [self.commandChannelManager rc_sendData:commandStr];
  714. }
  715. - (void)searchFileListBeginFun:(NSMutableDictionary *)dict
  716. {
  717. NSMutableDictionary *objectDict = dict;
  718. NSNumber *curNum = @1;
  719. if ([[objectDict allKeys] containsObject:@"type"]) {
  720. curNum = [objectDict objectForKey:@"type"];
  721. }
  722. NSString *pathStr = @"";
  723. if ([[objectDict allKeys] containsObject:@"path"]) {
  724. pathStr = [objectDict objectForKey:@"path"];
  725. }
  726. NSString *fileType = @"video";
  727. if(curNum.boolValue)
  728. {
  729. fileType = @"jpg";
  730. }
  731. NSString * commandStr = [RCCommandHelp searchCouldPhoneFilewithType:fileType withPath:pathStr];
  732. [self.commandChannelManager rc_sendData:commandStr];
  733. }
  734. #pragma mark 获取云机基本信息
  735. - (void)getBaseInfoFun
  736. {
  737. NSString *commondStr = @"{\"type\":\"getBaseInfo\"}";
  738. [self send_data:commondStr];
  739. }
  740. #pragma mark 获取云机系统镜像等信息
  741. - (void)getSysInfoFun
  742. {
  743. NSString *commondStr = @"{\"type\":\"getSysInfo\"}";
  744. [self send_data:commondStr];
  745. }
  746. #pragma mark 云机截图保存到云机图库
  747. - (void)screenshotInCloudPhoneFun{
  748. NSString*taskUid = [iTools getTaskUidStr];
  749. NSString *commondStr = [RCCommandHelp commandCloudPhoneScreenshotWithTaskUid:taskUid];
  750. [self send_data:commondStr];
  751. }
  752. #pragma mark 获取TV投屏状态
  753. - (void)getTvStatusFun
  754. {
  755. NSString *commondStr = @"{\"type\":\"TvStatus\"}";
  756. [self send_data:commondStr];
  757. }
  758. #pragma mark 关闭TV投屏状态
  759. - (void)offTvFun
  760. {
  761. NSString *commondStr = @"{\"type\":\"TvOff\"}";
  762. [self send_data:commondStr];
  763. }
  764. #pragma mark 开启TV投屏状态
  765. - (void)onTvFun
  766. {
  767. NSString *commondStr = @"{\"type\":\"wakeupTV\"}";
  768. [self send_data:commondStr];
  769. }
  770. @end