123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //
- // YMAudioVideoMatchingViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/20.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMAudioVideoMatchingViewModel.h"
- #import "YOUPAIBBVideoRequestVC.h"
- #import "YOUPAILCVideoRequestVC.h"
- @interface YMAudioVideoMatchingViewModel ()
- /// 音视频匹配类型
- @property (nonatomic, assign, readwrite) YMAudioVideoMatchingType audioVideoMatchingType;
- /// 音视频匹配过渡动画文件名
- @property (nonatomic, copy, readwrite) NSString *audioVideoMatchingTransitionFileName;
- /// 用户头像
- @property (nonatomic, copy, readwrite) NSString *userAvatar;
- /// 匹配类型图标
- @property (nonatomic, strong, readwrite) UIImage *matchingTypeIcon;
- /// 音视频匹配过渡动画文件名
- @property (nonatomic, copy) NSString *matchingType;
- @end
- @implementation YMAudioVideoMatchingViewModel
- - (void)ym_initialize{
- [super ym_initialize];
- self.audioVideoMatchingType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMAudioVideoMatchingTypeVideo];
-
- switch (self.audioVideoMatchingType) {
- case YMAudioVideoMatchingTypeVideo:
- {
- self.customNavTitle = @"视频匹配";
- self.matchingTypeIcon = ImageByName(@"ym_audio_video_matching_type_video");
- self.matchingType = @"video";
- }
- break;
- case YMAudioVideoMatchingTypeAudio:
- {
- self.customNavTitle = @"语音匹配";
- self.matchingTypeIcon = ImageByName(@"ym_audio_video_matching_type_voice");
- self.matchingType = @"voice";
- }
- break;
- default:
- break;
- }
-
- self.audioVideoMatchingTransitionFileName = @"audio_video_matching_animation";
- self.userAvatar = [LCSaveModel getUserModel].youpaipuserinfo.youpaipavatar;
- }
- - (void)openAudioVideoMatchingCompletion:(void (^)(BOOL))completion{
- [LCHttpHelper requestWithURLString:OpenMatching parameters:@{
- @"type":self.matchingType,
- } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- completion(YES);
- }else{
- completion(NO);
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
-
- } failure:^(NSError *error) {
- completion(NO);
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)closeAudioVideoMatchingCompletion:(void (^)(BOOL))completion{
- [LCHttpHelper requestWithURLString:CloseMatching parameters:@{
- @"type":self.matchingType,
- } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- completion(YES);
- }else{
- completion(NO);
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
-
- } failure:^(NSError *error) {
- completion(NO);
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)receiveAudioVideoMatchingWithMatchId:(NSString*)matchId OfUserId:(NSInteger)userId{
- [LCHttpHelper requestWithURLString:ReceiveMatching parameters:@{
- @"type":@"receive",
- @"match_id":matchId
- } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- if ([YOUPAILZChatRoomManager shareManager].chatroomWindow != nil && [YOUPAILZChatRoomManager shareManager].chatroomWindow.hidden == NO) {
- [ZCHUDHelper showTitle:@"你正在房间中,暂不可拨打视频"];
- return;
- }
-
- [UMengRecordTool umengEventCountWithId:StartVideoPersonal];
- [UCAuthorityManager cameraAuthority:^{
- if ([LCSaveData getWhiteVersion]) {//1
- [LCHttpHelper requestWithURLString:UserShowPage parameters:@{
- @"user_id":@(userId)
- } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
-
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSDictionary *data = [dict objectForKey:@"data"];
- YOUPAILCUserShowInfo *info = [YOUPAILCUserShowInfo mj_objectWithKeyValues:[data objectForKey:@"info"]];
-
- YOUPAIBBVideoRequestVC* chatRequest = [[YOUPAIBBVideoRequestVC alloc]init];
- YOUPAILCVideoChatModel *videoModel = [[YOUPAILCVideoChatModel alloc] init];
- videoModel.youpaiproom_id = [NSString stringWithFormat:@"C%@",[LCTools randomNumberWithLength:6]];
- videoModel.youpaipauditState = 1;
- videoModel.youpaipfrom_uid = [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id;
- videoModel.youpaipfrom_nickname = [LCSaveModel getUserModel].youpaipuserinfo.youpaipnickname;
- videoModel.youpaipfrom_avatar = [LCSaveModel getUserModel].youpaipuserinfo.youpaipavatar;
-
- videoModel.youpaipto_uid = stringFormat(@"%ld",userId);
- videoModel.youpaipto_nickname = info.youpaipnickname;
- videoModel.youpaipto_avatar = info.youpaipavatar;
- chatRequest.youpaipvideoModel = videoModel;
- ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc]initWithRootViewController:chatRequest];
- //modify by leo fix bug ios13
- nav.modalPresentationStyle =0;
- [[YMGlobalUtils getCurrentVC].navigationController presentViewController:nav animated:YES completion:^{
- }];
-
- }
- } failure:^(NSError *error) {
-
- }];
- }else{//0
- YOUPAILCVideoChatModel* videoModel = [YOUPAILCVideoChatModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
- [[YOUPAILZChatRoomManager shareManager] youpaifcloseChatRoom];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"MeCallVideo" object:nil userInfo:nil];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- YOUPAILCVideoRequestVC* chatRequest = [[YOUPAILCVideoRequestVC alloc]init];
- chatRequest.youpaipvideoModel = videoModel;
- //modify by leo fix bug ios13
- ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc]initWithRootViewController:chatRequest];
- chatRequest.definesPresentationContext = YES;
- nav.modalPresentationStyle = UIModalPresentationOverCurrentContext&UIModalPresentationOverFullScreen;
- chatRequest.view.backgroundColor=HexColorFromRGBA(0x000000, 0.55);
- [[YMGlobalUtils getCurrentVC].navigationController presentViewController:nav animated:YES completion:^{
- }];
- });
- }
-
- } denied:^{
-
- dispatch_async(dispatch_get_main_queue(), ^{
- UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" message:nil preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"现在去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
- if ([[UIDevice currentDevice].systemVersion floatValue] < 10.0)
- {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
-
- }
- else
- {
- // 去系统设置页面
- if (@available(iOS 10.0, *)) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- } else {
- // Fallback on earlier versions
- }
- }
- }];
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
- [systemAlert addAction:cancelAction];
- [systemAlert addAction:action];
- [[YMGlobalUtils getCurrentVC] presentViewController: systemAlert animated: YES completion: nil];
- });
-
- }];
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
-
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- @end
|