cloudPhoneViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. //
  2. // cloudPhoneViewController.m
  3. // Private-X
  4. //
  5. // Created by xd h on 2024/6/20.
  6. //
  7. #import "cloudPhoneViewController.h"
  8. #import "cloudPhoneSetView.h"
  9. #import "audioPlayingView.h"
  10. #import "DFPlayer.h"
  11. #import "audioPlayerViewController.h"
  12. #import "webRtcMsgModel.h"
  13. #import "webRtcPlayerViewController.h"
  14. @interface cloudPhoneViewController ()
  15. @property (nonatomic,strong) cloudPhoneSetView *cloudPhoneSetV;
  16. @property (nonatomic,strong) webRtcMsgModel *webRtcMsgMod;
  17. @end
  18. @implementation cloudPhoneViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. //输入密码完成
  23. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didInpuPwdOkFun) name:didInputPWDNotification object:nil];
  24. [self.view setBackgroundColor:HWF5F7FAColor];
  25. [self.toolBar setHidden:YES];
  26. [self.navigationBar setHidden:YES];
  27. [self.navBarBGView setHidden:YES];
  28. [self drawAnyView];
  29. }
  30. - (void)drawAnyView{
  31. //顶底底部图片
  32. UIImageView *topImageV = [UIImageView new];
  33. topImageV.userInteractionEnabled = YES;
  34. topImageV.image = [UIImage imageNamed:@"cloudPhone_bg"];
  35. [self.view addSubview:topImageV];
  36. [topImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.mas_equalTo(0);
  38. make.left.mas_equalTo(0);
  39. make.right.mas_equalTo(0);
  40. make.bottom.mas_equalTo(0);
  41. }];
  42. CGFloat width = SCREEN_W;
  43. CGFloat height = SCREEN_H;
  44. BOOL isSmallPhoneType = NO;
  45. if(width == 375 && height == 667){
  46. isSmallPhoneType = YES;
  47. }
  48. CGFloat adjustSmallScale = 1.0;
  49. if(isSmallPhoneType){
  50. adjustSmallScale = 0.9;
  51. }
  52. CGFloat imageTopY = 54.0;
  53. if(isSmallPhoneType){
  54. imageTopY = 20.0;
  55. }
  56. //设置按钮
  57. UIButton *setButton = [[UIButton alloc] init];
  58. //[setButton setBackgroundImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal];
  59. [setButton setImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal];
  60. setButton.tag = 1;
  61. [setButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  62. [self.view addSubview:setButton];
  63. //setButton.backgroundColor = [UIColor greenColor];
  64. [setButton mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.mas_equalTo(imageTopY);
  66. if(isSmallPhoneType){
  67. make.right.mas_equalTo(-5);
  68. }
  69. else{
  70. make.right.mas_equalTo(-16);
  71. }
  72. make.width.mas_equalTo(50);
  73. make.height.mas_equalTo(50);
  74. // make.top.mas_equalTo(imageTopY);
  75. // make.right.mas_equalTo(-16);
  76. // make.width.mas_equalTo(24);
  77. // make.height.mas_equalTo(24);
  78. }];
  79. //中间图片
  80. UIImageView *midImageV = [UIImageView new];
  81. midImageV.userInteractionEnabled = YES;
  82. midImageV.image = [UIImage imageNamed:@"cloudPhone_mid_img"];
  83. [self.view addSubview:midImageV];
  84. [midImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.width.mas_equalTo(326*WAUTOSCALE*adjustSmallScale);
  86. make.height.mas_equalTo(608*WAUTOSCALE*adjustSmallScale);
  87. make.centerX.mas_equalTo(0);
  88. make.centerY.mas_equalTo(-10);
  89. }];
  90. NSString *midTopTipImageStr = @"cloudPhone_topTip_img_cs";
  91. //欢迎
  92. //en-US 英文 ja-JP 日文
  93. NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  94. NSLog(@"arLanguages:%@",arLanguages);
  95. ///获取设备当前地区的代码和APP语言环境
  96. NSString *languageCode = [NSLocale preferredLanguages][0];
  97. //目前支持 中文(简体 繁体) 英文 日语
  98. if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
  99. {
  100. midTopTipImageStr = @"cloudPhone_topTip_img_cs";
  101. }
  102. else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
  103. {
  104. midTopTipImageStr = @"cloudPhone_topTip_img_ct";
  105. }
  106. else{
  107. midTopTipImageStr = @"cloudPhone_topTip_img_en";
  108. }
  109. //提示文字图片
  110. UIImageView *midTopTipImageV = [UIImageView new];
  111. midTopTipImageV.image = [UIImage imageNamed:midTopTipImageStr];
  112. [midImageV addSubview:midTopTipImageV];
  113. [midTopTipImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.width.mas_equalTo(282*WAUTOSCALE*adjustSmallScale);
  115. make.height.mas_equalTo(84*WAUTOSCALE*adjustSmallScale);
  116. make.centerX.mas_equalTo(0);
  117. make.top.equalTo(midImageV.mas_top).offset(64);
  118. }];
  119. //进入云机
  120. UIButton*enterCloudPhoneButton = [[UIButton alloc] init];
  121. CGFloat w_btn = SCREEN_W - 15*2 - 50*2;
  122. // gradient
  123. CAGradientLayer *gl = [CAGradientLayer layer];
  124. gl.frame = CGRectMake(0,0,w_btn,44.f);
  125. gl.startPoint = CGPointMake(0, 0.5);
  126. gl.endPoint = CGPointMake(0.97, 0.5);
  127. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  128. gl.locations = @[@(0), @(1.0f)];
  129. [enterCloudPhoneButton.layer addSublayer:gl];
  130. [enterCloudPhoneButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  131. //[enterCloudPhoneButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:(UIControlEventTouchUpInside)];
  132. [enterCloudPhoneButton setTitle:NSLocalizedString(@"cloudPhone_enter_tip",nil) forState:(UIControlStateNormal)];
  133. [enterCloudPhoneButton.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  134. [enterCloudPhoneButton.layer setCornerRadius:21.f];
  135. enterCloudPhoneButton.layer.borderWidth = 1.5;
  136. enterCloudPhoneButton.layer.borderColor = [UIColor whiteColor].CGColor;
  137. enterCloudPhoneButton.clipsToBounds = YES;
  138. //enterCloudPhoneButton.tag = 2;
  139. [midImageV addSubview:enterCloudPhoneButton];
  140. [enterCloudPhoneButton mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.width.mas_equalTo(w_btn);
  142. make.height.mas_equalTo(42);
  143. make.centerX.mas_equalTo(0);
  144. make.bottom.equalTo(midImageV.mas_bottom).offset(-60);
  145. }];
  146. //扩大金融云机范围按钮
  147. UIButton *bigButton = [[UIButton alloc] init];
  148. bigButton.tag = 2;
  149. [bigButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  150. [self.view addSubview:bigButton];
  151. //bigButton.backgroundColor = [UIColor greenColor];
  152. [bigButton mas_makeConstraints:^(MASConstraintMaker *make) {
  153. make.top.equalTo(midImageV.mas_top).offset(0);
  154. make.right.equalTo(midImageV.mas_right).offset(0);
  155. make.left.equalTo(midImageV.mas_left).offset(0);
  156. make.bottom.equalTo(midImageV.mas_bottom).offset(0);
  157. }];
  158. }
  159. #pragma mark 点击按钮
  160. - (void)didClickButtonFun:(UIButton*)but
  161. {
  162. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  163. {
  164. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  165. return;
  166. }
  167. // if (!ksharedAppDelegate.isWebSockLinkOKAginType) {//未链接
  168. // [[iToast makeText:NSLocalizedString(@"box_link_error_show_tip",nil)] show];
  169. // return;
  170. // }
  171. NSInteger tag = but.tag;
  172. HLog(@"%ld",tag);
  173. switch (tag) {
  174. case 1:
  175. {
  176. //数据埋点
  177. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_settings"];
  178. _cloudPhoneSetV = [cloudPhoneSetView new];
  179. [ksharedAppDelegate.window addSubview:_cloudPhoneSetV];
  180. [_cloudPhoneSetV mas_makeConstraints:^(MASConstraintMaker *make) {
  181. make.left.mas_equalTo(0);
  182. make.right.mas_equalTo(0);
  183. make.top.mas_equalTo(0);
  184. make.bottom.mas_equalTo(0);
  185. }];
  186. KWeakSelf
  187. _cloudPhoneSetV.didClickButtonFun = ^(NSInteger tag) {
  188. if (tag == 10) {//重启
  189. [weakSelf didClickRestartFun];
  190. }
  191. else if (tag == 11){//恢复出厂
  192. [weakSelf RestoreFactoryAleartFun];
  193. }
  194. };
  195. }
  196. break;
  197. case 2:
  198. {
  199. //[self checkFullScreenWithTVShowStateFun];
  200. // PlayerViewController *vc = [PlayerViewController new];
  201. // [self pushViewController:vc animated:YES];
  202. //
  203. // if(ksharedAppDelegate.TvStatusMod.isTVShowType){
  204. // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  205. // }
  206. [self queryWebRtcMsgFun:YES];
  207. //数据埋点
  208. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_enter"];
  209. }
  210. break;
  211. default:
  212. break;
  213. }
  214. }
  215. #pragma mark 点击了重启空间
  216. - (void)didClickRestartFun
  217. {
  218. KWeakSelf
  219. /*弹窗提示重启*/
  220. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_restart_phone_tips",nil)
  221. msg:@""
  222. imageStr:@""
  223. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  224. okTitle:NSLocalizedString(@"my_set_no_restart_phone_btn_ok",nil) isOkBtnHighlight:NO
  225. didClickOk:^{
  226. [weakSelf sureToRestartCloudPhoneFun];
  227. } didClickCancel:^{
  228. }];
  229. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  230. [self presentViewController:nextVC animated:YES completion:^{
  231. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  232. }];
  233. }
  234. #pragma mark 确认重启云机
  235. - (void)sureToRestartCloudPhoneFun{
  236. // /*重启云手机*/
  237. // 通过指令通道发送 {"type":"reboot"}
  238. [[webRtcManager shareManager] needToRebootFun];
  239. //提示语
  240. [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  241. }
  242. #pragma mark 点击恢复出厂
  243. - (void)RestoreFactoryAleartFun
  244. {
  245. KWeakSelf
  246. /*弹窗提示恢复出厂*/
  247. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_tips",nil)
  248. msg:NSLocalizedString(@"my_set_no_Restore_Factory_msg",nil)
  249. imageStr:@"icon_Restore_Factory_big"
  250. cancelTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil)
  251. okTitle:NSLocalizedString(@"other_cancel",nil) isOkBtnHighlight:YES
  252. didClickOk:^{
  253. } didClickCancel:^{
  254. //点击确定
  255. [weakSelf gotoResetFun];
  256. }];
  257. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  258. [self presentViewController:nextVC animated:YES completion:^{
  259. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  260. }];
  261. }
  262. #pragma mark 点击了恢复出厂
  263. - (void)gotoResetFun
  264. {
  265. [[webRtcManager shareManager] needToResetFun];
  266. [self RestoreFactoryingFun];
  267. }
  268. #pragma mark 恢复出厂中
  269. - (void)RestoreFactoryingFun
  270. {
  271. KWeakSelf
  272. /*弹窗提示恢复出厂*/
  273. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil)
  274. msg:NSLocalizedString(@"my_set_no_Restore_Factorying_msg",nil)
  275. imageStr:@""
  276. cancelTitle:NSLocalizedString(@"my_set_no_Restore_Factorying",nil)
  277. okTitle:@""
  278. isOkBtnHighlight:NO
  279. didClickOk:^{
  280. [weakSelf RestoreFactoryCompleteFun];
  281. } didClickCancel:^{
  282. }];
  283. [nextVC setButtonCountdownFun:180];//90
  284. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  285. [self presentViewController:nextVC animated:YES completion:^{
  286. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  287. }];
  288. }
  289. #pragma mark 恢复出厂倒计时结束
  290. - (void)RestoreFactoryCompleteFun
  291. {
  292. //KWeakSelf
  293. //瑞云发起重连
  294. //[[connectDeviceManager shareInstance] onConnectFun];
  295. /*弹窗提示恢复出厂*/
  296. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_ok_tips",nil)
  297. msg:@""
  298. imageStr:@""
  299. cancelTitle:NSLocalizedString(@"my_set_no_Restore_FactoryOK",nil)
  300. okTitle:@""
  301. isOkBtnHighlight:NO
  302. didClickOk:^{
  303. } didClickCancel:^{
  304. }];
  305. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  306. [self presentViewController:nextVC animated:YES completion:^{
  307. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  308. }];
  309. }
  310. - (void)viewWillAppear:(BOOL)animated{
  311. [super viewWillAppear:animated];
  312. [self handelAudioPlayingViewFun];
  313. }
  314. - (void)viewWillDisappear:(BOOL)animated{
  315. [super viewWillDisappear:animated];
  316. }
  317. - (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated
  318. {
  319. [self.navigationController pushViewController:vc animated:animated];
  320. }
  321. #pragma mark 处理音频播放中的视图状态
  322. - (void)handelAudioPlayingViewFun
  323. {
  324. audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  325. if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering
  326. ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying
  327. ||[DFPlayer sharedPlayer].state == DFPlayerStatePause){//播放中
  328. [self showAudioPlayingViewFun];
  329. }
  330. else{
  331. [self hideAudioPlayingViewFun];
  332. }
  333. KWeakSelf
  334. audioPlayingV.didClickButtonFun = ^(NSInteger tag) {
  335. if(tag == 1){
  336. [weakSelf hideAudioPlayingViewFun];
  337. }
  338. else if(tag == 5){
  339. [weakSelf AudioPlayingGotoAudioPlayerVCFun];
  340. }
  341. };
  342. }
  343. - (void)AudioPlayingGotoAudioPlayerVCFun{
  344. audioPlayerViewController *vc = [audioPlayerViewController new];
  345. vc.isfirstEnterType = NO;
  346. [self.navigationController pushViewController:vc animated:YES];
  347. }
  348. #pragma mark 显示音频播放中的视图
  349. - (void)showAudioPlayingViewFun
  350. {
  351. audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  352. [self.view addSubview:audioPlayingV];
  353. if([DFPlayer sharedPlayer].state == DFPlayerStatePlaying){
  354. [audioPlayingV startRotatingImage];
  355. }
  356. else if ([DFPlayer sharedPlayer].state == DFPlayerStatePause){
  357. [audioPlayingV stopRotatingImage];
  358. }
  359. [audioPlayingV mas_makeConstraints:^(MASConstraintMaker *make) {
  360. make.height.mas_equalTo(49);
  361. make.left.mas_equalTo(0);
  362. make.right.mas_equalTo(0);
  363. make.bottom.mas_equalTo(-TABBARHEIGHT);
  364. }];
  365. }
  366. #pragma mark 隐藏音频播放中的视图
  367. - (void)hideAudioPlayingViewFun
  368. {
  369. // audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  370. // [audioPlayingV removeFromSuperview];
  371. }
  372. #pragma mark 获取webrct 的链接信息
  373. -(void)queryWebRtcMsgFun:(BOOL)isPlayerType
  374. {
  375. if(isPlayerType){
  376. if(ksharedAppDelegate.DeviceWebRtcMsgMod && ksharedAppDelegate.DeviceWebRtcMsgMod.data.sn){
  377. [self gotoWebRtcVcBy:ksharedAppDelegate.DeviceWebRtcMsgMod];
  378. return;
  379. }
  380. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  381. }
  382. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  383. KWeakSelf
  384. [[netWorkManager shareInstance] CommonPostCallBackCode:webrctQueryByClient Parameters:paraDict success:^(id _Nonnull responseObject){
  385. if(isPlayerType){
  386. [weakSelf removeNewIndicator];
  387. }
  388. webRtcMsgModel *curModel = [[webRtcMsgModel alloc] initWithDictionary:responseObject error:nil];
  389. if(curModel && curModel.status == 0){
  390. ksharedAppDelegate.DeviceWebRtcMsgMod = curModel;
  391. if(isPlayerType){
  392. [weakSelf gotoWebRtcVcBy:curModel];
  393. }
  394. }
  395. else
  396. {
  397. if(isPlayerType && curModel.msg){
  398. [[iToast makeText:curModel.msg] show];
  399. }
  400. }
  401. } failure:^(NSError * _Nonnull error) {
  402. if(isPlayerType){
  403. [weakSelf removeNewIndicator];
  404. [[iToast makeText:NSLocalizedString(@"get_webrtcMsg_fail_tip",nil)] show];
  405. }
  406. }];
  407. }
  408. #pragma mark 跳转webrtc 页面
  409. - (void)gotoWebRtcVcBy:(webRtcMsgModel*)webRtcMsgMod
  410. {
  411. NSArray * vcArrs = self.navigationController.viewControllers;
  412. if(vcArrs.count != 1){
  413. return;
  414. }
  415. [cachesFileManager writeLogsWithMsg:@"webRtcPlayer push webRtcPlayerVC"];
  416. webRtcPlayerViewController *vc = [webRtcPlayerViewController new];
  417. vc.webRtcMsgMod = webRtcMsgMod;
  418. [self.navigationController pushViewController:vc animated:YES];
  419. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  420. ksharedAppDelegate.isCloudPhoneModeNotPrivacyModeOpenType = NO;
  421. ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType = NO;
  422. ksharedAppDelegate.needToPushWebRtcVCType = NO;
  423. });
  424. }
  425. #pragma mark 输入密码完成
  426. - (void)didInpuPwdOkFun
  427. {
  428. KWeakSelf
  429. mainBlock(^{
  430. if(ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType
  431. || ksharedAppDelegate.needToPushWebRtcVCType){
  432. [weakSelf queryWebRtcMsgFun:YES];
  433. }
  434. });
  435. }
  436. @end