|
|
|
//
|
|
|
|
// TihuVideoCallViewController.m
|
|
|
|
// tongxin
|
|
|
|
//
|
|
|
|
// Created by ecell on 2021/7/29.
|
|
|
|
// Copyright © 2021 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "TihuVideoCallViewController.h"
|
|
|
|
#import "Masonry.h"
|
|
|
|
#import "QMUIKit.h"
|
|
|
|
#import <AVFoundation/AVFoundation.h>
|
|
|
|
#import <JLAuthorizationManager.h>
|
|
|
|
#import "MZTimerLabel.h"
|
|
|
|
#import "TihuManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define IPHONEXLater \
|
|
|
|
({BOOL isPhoneX = NO;\
|
|
|
|
if (@available(iOS 11.0, *)) {\
|
|
|
|
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
|
|
|
|
}\
|
|
|
|
(isPhoneX);})
|
|
|
|
|
|
|
|
#define KKStatusBarHeight (IPHONEXLater ? 44 : 20)
|
|
|
|
#define KKSafeAreaBottomHeight (IPHONEXLater ? 34 : 0)
|
|
|
|
//#define ScreenWidth [[UIScreen mainScreen] bounds].size.width
|
|
|
|
//#define ScreenHeight [[UIScreen mainScreen] bounds].size.height
|
|
|
|
|
|
|
|
|
|
|
|
#define kRTCRate ([UIScreen mainScreen].bounds.size.width / 320.0)
|
|
|
|
// 视频聊天时,小窗口的宽
|
|
|
|
#define kMicVideoW (110 * kRTCRate)
|
|
|
|
// 视频聊天时,小窗口的高
|
|
|
|
#define kMicVideoH (110 * kRTCRate)
|
|
|
|
// 头像的大小
|
|
|
|
#define kAvatarWH (70 * kRTCRate)
|
|
|
|
|
|
|
|
|
|
|
|
static CGFloat const kTitleSpace = 12;
|
|
|
|
static CGFloat const kBtnHeitht = 106;
|
|
|
|
|
|
|
|
@interface TihuVideoCallViewController (){
|
|
|
|
CGFloat _kBottomSide;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property(nonatomic, strong) UIView *localImage;
|
|
|
|
@property (nonatomic,strong)AVCaptureVideoPreviewLayer *previewLayer; //摄像头预览layer
|
|
|
|
@property(nonatomic, strong) UIImageView *playImage;
|
|
|
|
|
|
|
|
// view 相关
|
|
|
|
@property(nonatomic, strong) UIImageView *iconImage;
|
|
|
|
@property(nonatomic, strong) UILabel *nameLabel;
|
|
|
|
@property(nonatomic, strong) QMUIButton *acceptBtn;
|
|
|
|
@property(nonatomic, strong) QMUIButton *cancelBtn;
|
|
|
|
@property(nonatomic, strong) QMUIButton *closeBtn;
|
|
|
|
@property(nonatomic, strong) QMUIButton *refuseBtn;
|
|
|
|
@property(nonatomic, strong) QMUIButton *swVABtn; //音视频
|
|
|
|
@property(nonatomic, strong) QMUIButton *swFBBtn;//摄像头
|
|
|
|
@property(nonatomic, strong) QMUIButton *swVAAcceptBtn;//切语音接听
|
|
|
|
@property(nonatomic, strong) UILabel *tipsLabel;
|
|
|
|
@property(nonatomic, strong) MZTimerLabel *timeLabel;
|
|
|
|
@property(nonatomic, strong) QMUIButton *swSilenceBtn;//静音
|
|
|
|
@property(nonatomic, strong) QMUIButton *swSpeakerBtn;//免提
|
|
|
|
|
|
|
|
|
|
|
|
@property(nonatomic, strong) QMUIButton *exchangeBtn;
|
|
|
|
@property(nonatomic, assign) BOOL isBigMine;
|
|
|
|
|
|
|
|
|
|
|
|
/// 是否未打开麦克风
|
|
|
|
@property (nonatomic) BOOL isUNAuthorizationTypeAudio;
|
|
|
|
|
|
|
|
/// 是否未打开相机
|
|
|
|
@property (nonatomic) BOOL isUNAuthorizationTypeCamera;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TihuVideoCallViewController
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[MoonChatPlatform getInstance].avChatingDelegate = nil;
|
|
|
|
[TihuManager shared].callViewController = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)chatAVCloseEventCallBack:(int)type {
|
|
|
|
NSString *str = @"end";
|
|
|
|
if (type == 0) {
|
|
|
|
str = GJText(@"通话结束");
|
|
|
|
} else if (type == 1) {
|
|
|
|
str = GJText(@"通话忙");
|
|
|
|
} else if (type == 2) {
|
|
|
|
str = GJText(@"对方拒绝");
|
|
|
|
}
|
|
|
|
[self p_delayDismissWithTips:str];
|
|
|
|
[[TihuManager shared] stopRing];
|
|
|
|
[TihuManager shared].callViewController = nil;
|
|
|
|
NSLog(@"2.0 chatAVCloseEventCallBack===%d", type);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)chatVideoPreviewInit:(AVCaptureSession *)session {
|
|
|
|
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
|
|
|
|
[self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
|
|
|
|
self.previewLayer.frame = self.localImage.bounds;
|
|
|
|
[self.localImage.layer addSublayer:self.previewLayer];
|
|
|
|
[MoonChatPlatform setVideoSurface:self.previewLayer isMine:YES];
|
|
|
|
|
|
|
|
[[TihuManager shared] dismissPopView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)chatVideoSessionInit:(AVCaptureSession *)session {
|
|
|
|
self.playImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, KKStatusBarHeight + kMicVideoH + 10, SCREEN_WIDTH, SCREEN_WIDTH)];
|
|
|
|
[self.view addSubview:self.playImage];
|
|
|
|
[MoonChatPlatform setVideoSurface:self.playImage isMine:NO];
|
|
|
|
|
|
|
|
CGFloat width = kMicVideoW;
|
|
|
|
CGFloat height = kMicVideoH;
|
|
|
|
CGRect preFrame = CGRectMake(SCREEN_WIDTH - width, KKStatusBarHeight,width,height);
|
|
|
|
self.localImage.frame = preFrame;
|
|
|
|
self.previewLayer.frame = self.localImage.bounds;
|
|
|
|
|
|
|
|
[self comeToVideoChatUI];
|
|
|
|
|
|
|
|
[self.view addSubview:self.exchangeBtn];
|
|
|
|
|
|
|
|
[[TihuManager shared] stopRing];
|
|
|
|
NSLog(@"===chatVideoSessionInit===");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)chatAudioInit:(BOOL)isCalling {
|
|
|
|
if (!isCalling) {
|
|
|
|
[self.swVAAcceptBtn removeFromSuperview];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[self removeView];
|
|
|
|
[self initCenterView];
|
|
|
|
[self comeToAudioChatUI];
|
|
|
|
|
|
|
|
[[TihuManager shared] stopRing];
|
|
|
|
NSLog(@"===chatAudioInit===");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)chatVideoDataReceived {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
[self.navigationController setNavigationBarHidden:YES animated:NO];
|
|
|
|
//强制亮屏
|
|
|
|
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive){
|
|
|
|
[self judgeAuthorization];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)judgeAuthorization{
|
|
|
|
if(self.isUNAuthorizationTypeCamera == YES){
|
|
|
|
[self showAlertAuthorizationTypeCamera];
|
|
|
|
//if(self.isReceiveCall){[self activeHangUpBtnAction:nil];}else{[self hangUpButton:nil];}
|
|
|
|
}else if(self.isUNAuthorizationTypeAudio == YES){
|
|
|
|
[self showAlertAuthorizationTypeVideo];
|
|
|
|
//if(self.isReceiveCall){[self activeHangUpBtnAction:nil];}else{[self hangUpButton:nil];}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showAlertAuthorizationTypeVideo
|
|
|
|
{
|
|
|
|
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"请在iPhone的\"设置-隐私-麦克风\"选项中,允许守护星访问你的麦克风") subtitle:nil AlertViewType:AlertViewTypeSystemAlert config:nil];
|
|
|
|
[alertV addAlertItem:^EasyAlertItem *{
|
|
|
|
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) {
|
|
|
|
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[alertV showAlertView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showAlertAuthorizationTypeCamera
|
|
|
|
{
|
|
|
|
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"在iPhone的\"设置-隐私-相机\"选项中,允许守护星访问你的相机") subtitle:nil AlertViewType:AlertViewTypeSystemAlert config:nil];
|
|
|
|
[alertV addAlertItem:^EasyAlertItem *{
|
|
|
|
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) {
|
|
|
|
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[alertV showAlertView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
[self.navigationController setNavigationBarHidden:NO animated:NO];
|
|
|
|
[[TihuManager shared] stopRing];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
//保持屏幕常亮
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
|
|
|
|
|
|
|
|
kWeakSelf(self)
|
|
|
|
JLAuthorizationManager *jlManager = [JLAuthorizationManager defaultManager];
|
|
|
|
[jlManager JL_requestAuthorizationWithAuthorizationType:JLAuthorizationTypeMicrophone
|
|
|
|
authorizedHandler:nil
|
|
|
|
unAuthorizedHandler:^{
|
|
|
|
weakself.isUNAuthorizationTypeAudio = YES;
|
|
|
|
|
|
|
|
}];
|
|
|
|
[jlManager JL_requestAuthorizationWithAuthorizationType:JLAuthorizationTypeCamera
|
|
|
|
authorizedHandler:nil
|
|
|
|
unAuthorizedHandler:^{
|
|
|
|
weakself.isUNAuthorizationTypeCamera = YES;
|
|
|
|
}];
|
|
|
|
|
|
|
|
//初始化UI和参数
|
|
|
|
_kBottomSide = -KKSafeAreaBottomHeight-20; //- 60;
|
|
|
|
|
|
|
|
self.view.backgroundColor = UIColor.blackColor;
|
|
|
|
|
|
|
|
[MoonChatPlatform getInstance].avChatingDelegate = self;
|
|
|
|
|
|
|
|
[self initPreview];
|
|
|
|
[self initTipView];
|
|
|
|
[self initCenterView];
|
|
|
|
|
|
|
|
[self initUIAndRing];
|
|
|
|
|
|
|
|
if (_isFromBackground) {
|
|
|
|
//[self chatVideoPreviewInit:[AVCaptureSession new]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initUIAndRing {
|
|
|
|
switch (self.vType) {
|
|
|
|
case MoonChatViewTypeSendAudio:
|
|
|
|
[[TihuManager shared] playRing:@"tones"];
|
|
|
|
[self initSendAudioUI];
|
|
|
|
break;
|
|
|
|
case MoonChatViewTypeSendVideo:
|
|
|
|
[[TihuManager shared] playRing:@"tones"];
|
|
|
|
[self initSendVideoUI];
|
|
|
|
break;
|
|
|
|
case MoonChatViewTypeReceiveAudio:
|
|
|
|
[[TihuManager shared] playRing:@"ring"];
|
|
|
|
[self initReceiceAudioUI];
|
|
|
|
break;
|
|
|
|
case MoonChatViewTypeReceiveVideo:
|
|
|
|
[[TihuManager shared] playRing:@"ring"];
|
|
|
|
[self initReceiceVideoUI];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - EventHandle
|
|
|
|
- (void)handleAcceptBtnEvent {
|
|
|
|
[MoonChatPlatform answerChat];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleSWVABtnEvent {
|
|
|
|
[MoonChatPlatform changetoVoice];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleSWVAAcceptBtnEvent {
|
|
|
|
[MoonChatPlatform changetoVoicePickUp];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleSWFBBtnEvent {
|
|
|
|
[MoonChatPlatform switchCamera];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleSWSilenceBtnEvent:(QMUIButton *)sender {
|
|
|
|
sender.selected = !sender.selected;
|
|
|
|
[MoonChatPlatform setMute:sender.selected];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleSWSpeakerBtnEvent:(QMUIButton *)sender {
|
|
|
|
sender.selected = !sender.selected;
|
|
|
|
[MoonChatPlatform changeSoundType:sender.selected];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleCancelBtnEvent {
|
|
|
|
[MoonChatPlatform cancelChat];
|
|
|
|
[TihuManager shared].callViewController = nil;
|
|
|
|
[self p_delayDismissWithTips:GJText(@"通话已取消")];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleCloseBtnEvent {
|
|
|
|
[MoonChatPlatform closeChat];
|
|
|
|
[TihuManager shared].callViewController = nil;
|
|
|
|
[self p_delayDismissWithTips:GJText(@"通话结束")];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleRefuseBtnEvent {
|
|
|
|
[MoonChatPlatform refuseChat];
|
|
|
|
[TihuManager shared].callViewController = nil;
|
|
|
|
[self p_delayDismissWithTips:GJText(@"已拒绝,通话结束")];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)p_delayDismissWithTips:(NSString *)tips {
|
|
|
|
[self p_showTips:tips];
|
|
|
|
[self performSelector:@selector(p_dismissVC) withObject:nil afterDelay:1.5];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)p_showTips:(NSString *)tipStr {
|
|
|
|
[self.view bringSubviewToFront:self.tipsLabel];
|
|
|
|
self.tipsLabel.text = tipStr;
|
|
|
|
self.tipsLabel.hidden = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)p_dismissVC {
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - 界面相关 *** 可不看 ***
|
|
|
|
- (void)initPreview {
|
|
|
|
CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
|
self.localImage = [[UIView alloc] initWithFrame:rect];
|
|
|
|
self.localImage.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.view addSubview:self.localImage];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initCenterView {
|
|
|
|
[self.view addSubview:self.nameLabel];
|
|
|
|
self.nameLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.width.mas_equalTo(SCREEN_WIDTH - 50);
|
|
|
|
make.height.mas_equalTo(30);
|
|
|
|
make.bottom.mas_equalTo(self.tipsLabel.mas_top).offset(-60);
|
|
|
|
make.centerX.mas_equalTo(self.view);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.view addSubview:self.iconImage];
|
|
|
|
[self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.size.mas_equalTo(kAvatarWH);
|
|
|
|
make.centerX.mas_equalTo(self.view);
|
|
|
|
make.bottom.mas_equalTo(self.nameLabel.mas_top).offset(-15);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initTipView {
|
|
|
|
[self.view addSubview:self.tipsLabel];
|
|
|
|
[self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.width.mas_equalTo(SCREEN_WIDTH - 50);
|
|
|
|
make.height.mas_equalTo(30);
|
|
|
|
make.centerY.mas_equalTo(self.view).offset(-50);
|
|
|
|
make.centerX.mas_equalTo(self.view);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeView {
|
|
|
|
[self.iconImage removeFromSuperview];
|
|
|
|
[self.nameLabel removeFromSuperview];
|
|
|
|
[self.acceptBtn removeFromSuperview];
|
|
|
|
[self.cancelBtn removeFromSuperview];
|
|
|
|
[self.closeBtn removeFromSuperview];
|
|
|
|
[self.refuseBtn removeFromSuperview];
|
|
|
|
[self.swVABtn removeFromSuperview];
|
|
|
|
[self.swFBBtn removeFromSuperview];
|
|
|
|
[self.swVAAcceptBtn removeFromSuperview];
|
|
|
|
[self.exchangeBtn removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**视频来电*/
|
|
|
|
- (void)initReceiceVideoUI {
|
|
|
|
[self p_initReceiveTalkUI];
|
|
|
|
//[self initSwitchAcceptBtn];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**语音来电*/
|
|
|
|
- (void)initReceiceAudioUI {
|
|
|
|
[self p_initReceiveTalkUI];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initSwitchAcceptBtn {
|
|
|
|
[self.view addSubview:self.swVAAcceptBtn];
|
|
|
|
[self.swVAAcceptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.width.mas_equalTo(self.swVAAcceptBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
make.bottom.mas_equalTo(self.acceptBtn.mas_top).offset(-20);
|
|
|
|
make.centerX.mas_equalTo(self.acceptBtn);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)p_initReceiveTalkUI {
|
|
|
|
[self.view addSubview:self.acceptBtn];
|
|
|
|
[self.acceptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide);
|
|
|
|
make.width.mas_equalTo(self.acceptBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
make.left.mas_equalTo(self.view.mas_centerX).offset(40);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.view addSubview:self.refuseBtn];
|
|
|
|
[self.refuseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.acceptBtn);
|
|
|
|
make.width.mas_equalTo(self.refuseBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
make.right.mas_equalTo(self.view.mas_centerX).offset(-40);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**发起视频聊天*/
|
|
|
|
- (void)initSendVideoUI {
|
|
|
|
|
|
|
|
[self.view addSubview:self.cancelBtn];
|
|
|
|
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide);
|
|
|
|
make.centerX.mas_equalTo(self.view);//.offset(-80);
|
|
|
|
make.width.mas_equalTo(self.cancelBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
|
|
|
|
/*
|
|
|
|
[self.view addSubview:self.swVABtn];
|
|
|
|
[self.swVABtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.cancelBtn);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(80);
|
|
|
|
make.width.mas_equalTo(self.swVABtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**发起语音聊天*/
|
|
|
|
- (void)initSendAudioUI {
|
|
|
|
[self.view addSubview:self.cancelBtn];
|
|
|
|
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide);
|
|
|
|
make.centerX.mas_equalTo(self.view);
|
|
|
|
make.width.mas_equalTo(self.cancelBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.view addSubview:self.swSilenceBtn];
|
|
|
|
[self.swSilenceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.cancelBtn);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(-120);
|
|
|
|
make.width.mas_equalTo(self.swSilenceBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.view addSubview:self.swSpeakerBtn];
|
|
|
|
[self.swSpeakerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.cancelBtn);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(120);
|
|
|
|
make.width.mas_equalTo(self.swSpeakerBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**接听视频来电*/
|
|
|
|
- (void)comeToVideoChatUI {
|
|
|
|
self.tipsLabel.hidden = YES;
|
|
|
|
[self.cancelBtn removeFromSuperview];
|
|
|
|
[self.acceptBtn removeFromSuperview];
|
|
|
|
[self.refuseBtn removeFromSuperview];
|
|
|
|
[self.swVAAcceptBtn removeFromSuperview];
|
|
|
|
|
|
|
|
[self.iconImage mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.size.mas_equalTo(kAvatarWH);
|
|
|
|
make.left.mas_equalTo(10);
|
|
|
|
make.top.mas_equalTo(KKStatusBarHeight);
|
|
|
|
}];
|
|
|
|
|
|
|
|
self.nameLabel.textAlignment = NSTextAlignmentLeft;
|
|
|
|
[self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.width.mas_equalTo(SCREEN_WIDTH - 20 - kMicVideoW);
|
|
|
|
make.height.mas_equalTo(30);
|
|
|
|
make.top.mas_equalTo(self.iconImage.mas_bottom).offset(10);
|
|
|
|
make.left.mas_equalTo(self.iconImage);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self p_addTimeLabel];
|
|
|
|
[_timeLabel start];
|
|
|
|
|
|
|
|
//[self p_addCloseBtn];
|
|
|
|
|
|
|
|
[self.view addSubview:self.closeBtn];
|
|
|
|
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(-120);
|
|
|
|
make.width.mas_equalTo(self.closeBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
|
|
|
|
/*
|
|
|
|
[self.view addSubview:self.swVABtn];
|
|
|
|
[self.swVABtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.closeBtn);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(-120);
|
|
|
|
make.width.mas_equalTo(self.swVABtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
*/
|
|
|
|
|
|
|
|
[self.view addSubview:self.swFBBtn];
|
|
|
|
[self.swFBBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.closeBtn);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(120);
|
|
|
|
make.width.mas_equalTo(self.swFBBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)p_addTimeLabel {
|
|
|
|
[self.view addSubview:self.timeLabel];
|
|
|
|
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide - 80 - 5 - 30 - 40);
|
|
|
|
make.width.mas_equalTo(SCREEN_WIDTH - 50);
|
|
|
|
make.height.mas_equalTo(30);
|
|
|
|
make.centerX.mas_equalTo(self.view);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)p_addCloseBtn {
|
|
|
|
[self.view addSubview:self.closeBtn];
|
|
|
|
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide);
|
|
|
|
make.centerX.mas_equalTo(self.view);
|
|
|
|
make.width.mas_equalTo(self.closeBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**接听音频来电*/
|
|
|
|
- (void)comeToAudioChatUI {
|
|
|
|
self.tipsLabel.hidden = YES;
|
|
|
|
[self.cancelBtn removeFromSuperview];
|
|
|
|
[self.acceptBtn removeFromSuperview];
|
|
|
|
[self.refuseBtn removeFromSuperview];
|
|
|
|
[self.swVABtn removeFromSuperview];
|
|
|
|
[self.swVAAcceptBtn removeFromSuperview];
|
|
|
|
|
|
|
|
[self p_addTimeLabel];
|
|
|
|
|
|
|
|
[self p_addCloseBtn];
|
|
|
|
|
|
|
|
if (!_swSilenceBtn) {
|
|
|
|
[self.view addSubview:self.swSilenceBtn];
|
|
|
|
}
|
|
|
|
[self.swSilenceBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.closeBtn);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(-120);
|
|
|
|
make.width.mas_equalTo(self.swSilenceBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (!_swSpeakerBtn) {
|
|
|
|
[self.view addSubview:self.swSpeakerBtn];
|
|
|
|
}
|
|
|
|
[self.swSpeakerBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.closeBtn);
|
|
|
|
make.centerX.mas_equalTo(self.view).offset(120);
|
|
|
|
make.width.mas_equalTo(self.swSpeakerBtn.mas_width);
|
|
|
|
make.height.mas_equalTo(kBtnHeitht);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
//交换两个视图
|
|
|
|
- (void)exchangeView {
|
|
|
|
self.isBigMine = !self.isBigMine;
|
|
|
|
if (self.isBigMine) {
|
|
|
|
CGFloat width = kMicVideoW;
|
|
|
|
CGFloat height = kMicVideoH;
|
|
|
|
self.localImage.frame = CGRectMake(0, KKStatusBarHeight + kMicVideoH + 10, SCREEN_WIDTH, SCREEN_WIDTH);
|
|
|
|
self.previewLayer.frame = self.localImage.bounds;
|
|
|
|
self.playImage.frame = CGRectMake(SCREEN_WIDTH - width, KKStatusBarHeight,width,height);
|
|
|
|
} else {
|
|
|
|
CGFloat width = kMicVideoW;
|
|
|
|
CGFloat height = kMicVideoH;
|
|
|
|
self.localImage.frame = CGRectMake(SCREEN_WIDTH - width, KKStatusBarHeight,width,height);
|
|
|
|
self.previewLayer.frame = self.localImage.bounds;
|
|
|
|
self.playImage.frame = CGRectMake(0, KKStatusBarHeight + kMicVideoH + 10, SCREEN_WIDTH, SCREEN_WIDTH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Getters
|
|
|
|
- (UIImageView *)iconImage {
|
|
|
|
if (!_iconImage) {
|
|
|
|
_iconImage = [[UIImageView alloc] init];
|
|
|
|
_iconImage.image = [UIImage imageNamed:@"DefaultHead"];
|
|
|
|
_iconImage.layer.cornerRadius = 16;
|
|
|
|
_iconImage.layer.masksToBounds = YES;
|
|
|
|
}
|
|
|
|
return _iconImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UILabel *)nameLabel {
|
|
|
|
if (!_nameLabel) {
|
|
|
|
_nameLabel = [[UILabel alloc] init];
|
|
|
|
_nameLabel.font = [UIFont systemFontOfSize:18];
|
|
|
|
_nameLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
if (self.iRemoteUserId) {
|
|
|
|
_nameLabel.text = [NSString stringWithFormat:@"%@%@%@", GJText(@"与"),self.iRemoteUserId,GJText(@"进行对话")];
|
|
|
|
} else{
|
|
|
|
_nameLabel.text = [NSString stringWithFormat:@"%@%@%@", GJText(@"与"),APIManager.sharedManager.deviceModel.name,GJText(@"进行对话")];
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK:不显示用户名称
|
|
|
|
_nameLabel.text = @"";
|
|
|
|
|
|
|
|
_nameLabel.textColor = UIColor.whiteColor;
|
|
|
|
}
|
|
|
|
return _nameLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)acceptBtn {
|
|
|
|
if (!_acceptBtn) {
|
|
|
|
_acceptBtn = [self generalBtn:GJText(@"接听") imageName:@"video_icon_pickup"];
|
|
|
|
_acceptBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_acceptBtn addTarget:self action:@selector(handleAcceptBtnEvent) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
//[_acceptBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
|
|
|
|
}
|
|
|
|
return _acceptBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)cancelBtn {
|
|
|
|
if (!_cancelBtn) {
|
|
|
|
_cancelBtn = [self generalBtn:GJText(@"取消") imageName:@"video_icon_cancle"];
|
|
|
|
_cancelBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_cancelBtn addTarget:self action:@selector(handleCancelBtnEvent) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _cancelBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)closeBtn {
|
|
|
|
if (!_closeBtn) {
|
|
|
|
_closeBtn = [self generalBtn:GJText(@"挂断") imageName:@"video_icon_hanup"];
|
|
|
|
_closeBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_closeBtn addTarget:self action:@selector(handleCloseBtnEvent) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _closeBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)refuseBtn {
|
|
|
|
if (!_refuseBtn) {
|
|
|
|
_refuseBtn = [self generalBtn:GJText(@"拒绝") imageName:@"video_icon_hanup"];
|
|
|
|
_refuseBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_refuseBtn addTarget:self action:@selector(handleRefuseBtnEvent) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _refuseBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)swVABtn {
|
|
|
|
if (!_swVABtn) {
|
|
|
|
_swVABtn = [self generalBtn:GJText(@"切换语音") imageName:@"video_icon_tovoice"];
|
|
|
|
_swVABtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_swVABtn addTarget:self action:@selector(handleSWVABtnEvent) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _swVABtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)swVAAcceptBtn {
|
|
|
|
if (!_swVAAcceptBtn) {
|
|
|
|
_swVAAcceptBtn = [self generalBtn:GJText(@"切换语音") imageName:@"video_icon_tovoice"];
|
|
|
|
_swVAAcceptBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_swVAAcceptBtn addTarget:self action:@selector(handleSWVAAcceptBtnEvent) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _swVAAcceptBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)swFBBtn {
|
|
|
|
if (!_swFBBtn) {
|
|
|
|
_swFBBtn = [self generalBtn:GJText(@"切换摄像头") imageName:@"video_icon_camera"];
|
|
|
|
_swFBBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_swFBBtn addTarget:self action:@selector(handleSWFBBtnEvent) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _swFBBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)exchangeBtn {
|
|
|
|
if (!_exchangeBtn) {
|
|
|
|
CGFloat width = kMicVideoW;
|
|
|
|
CGFloat height = kMicVideoH;
|
|
|
|
_exchangeBtn = [[QMUIButton alloc] init];
|
|
|
|
_exchangeBtn.frame = CGRectMake(SCREEN_WIDTH - width, KKStatusBarHeight,width,height);
|
|
|
|
//_exchangeBtn.spacingBetweenImageAndTitle = 10;
|
|
|
|
[_exchangeBtn addTarget:self action:@selector(exchangeView) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _exchangeBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UILabel *)tipsLabel {
|
|
|
|
if (!_tipsLabel) {
|
|
|
|
_tipsLabel = [[UILabel alloc] init];
|
|
|
|
_tipsLabel.font = [UIFont systemFontOfSize:14];//MSmallFont(14);
|
|
|
|
_tipsLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
_tipsLabel.textColor = UIColorWhite;
|
|
|
|
}
|
|
|
|
return _tipsLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MZTimerLabel *)timeLabel {
|
|
|
|
if (!_timeLabel) {
|
|
|
|
_timeLabel = [[MZTimerLabel alloc] init];
|
|
|
|
_timeLabel.font = [UIFont systemFontOfSize:22];//MSmallFont(22);
|
|
|
|
_timeLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
_timeLabel.textColor = UIColor.whiteColor;
|
|
|
|
_timeLabel.timeFormat = @"mm:ss";
|
|
|
|
|
|
|
|
}
|
|
|
|
return _timeLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)swSilenceBtn {
|
|
|
|
if (!_swSilenceBtn) {
|
|
|
|
_swSilenceBtn = [self generalBtn:GJText(@"静音") imageName:@"video_icon_muteon"];
|
|
|
|
_swSilenceBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_swSilenceBtn setImage:[UIImage imageNamed:@"video_icon_muteoff"] forState:UIControlStateSelected];
|
|
|
|
[_swSilenceBtn addTarget:self action:@selector(handleSWSilenceBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _swSilenceBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)swSpeakerBtn {
|
|
|
|
if (!_swSpeakerBtn) {
|
|
|
|
_swSpeakerBtn = [self generalBtn:GJText(@"免提") imageName:@"video_icon_speakeron"];
|
|
|
|
_swSilenceBtn.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[_swSpeakerBtn setImage:[UIImage imageNamed:@"video_icon_speaker"] forState:UIControlStateSelected];
|
|
|
|
[_swSpeakerBtn addTarget:self action:@selector(handleSWSpeakerBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
return _swSpeakerBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (QMUIButton *)generalBtn:(NSString *)title imageName:(NSString *)imageName {
|
|
|
|
QMUIButton *button = [[QMUIButton alloc] qmui_initWithImage:[UIImage imageNamed:imageName] title:title];
|
|
|
|
button.imagePosition = QMUIButtonImagePositionTop;
|
|
|
|
button.spacingBetweenImageAndTitle = kTitleSpace;
|
|
|
|
[button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
|
|
|
[button sizeToFit];
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=================================================================================================
|
|
|
|
|
|
|
|
-(void)uploadCallTime:(NSString *)callTime {
|
|
|
|
|
|
|
|
if(callTime && callTime.length == 8){
|
|
|
|
|
|
|
|
NSLog(@"upload call time = %@", callTime);
|
|
|
|
|
|
|
|
NSArray *hhmmss = [callTime componentsSeparatedByString:@":"];
|
|
|
|
|
|
|
|
if (hhmmss && hhmmss.count == 3) {
|
|
|
|
|
|
|
|
int hh = [[NSString stringWithFormat:@"%@", hhmmss[0]] intValue];
|
|
|
|
int mm = [[NSString stringWithFormat:@"%@", hhmmss[1]] intValue];
|
|
|
|
int ss = [[NSString stringWithFormat:@"%@", hhmmss[2]] intValue];
|
|
|
|
|
|
|
|
int total = hh*60*60 + mm*60 + ss;
|
|
|
|
|
|
|
|
//MARK:上传视频时间
|
|
|
|
|
|
|
|
NSMutableDictionary *dics = [NSMutableDictionary dictionary];
|
|
|
|
[dics setValue:@(total) forKey:@"duration"];
|
|
|
|
[dics setValue:@(0) forKey:@"waitDuration"];
|
|
|
|
[dics setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
|
|
|
|
[dics setValue:self.videoId forKey:@"videoId"];
|
|
|
|
|
|
|
|
[[[APIManager sharedManager] APPOST:VideoRecord_URL parameters:dics isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) {
|
|
|
|
[UICommon HidenLoading];
|
|
|
|
NSLog(@"上传视频时间成功");
|
|
|
|
//MARK: 上传完视频时间后删除存储的 Key
|
|
|
|
[UserDefaults removeObjectForKey:VideoTimeAndIDAndWHRecordKey];
|
|
|
|
} error:^(NSError * _Nullable error) {
|
|
|
|
NSDictionary *dic = error.userInfo;
|
|
|
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|