cloudPhoneViewController.m 16 KB

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