|
|
|
@ -11,7 +11,7 @@
@@ -11,7 +11,7 @@
|
|
|
|
|
//ios > 10 |
|
|
|
|
//#import <CallKit/CXCallObserver.h> |
|
|
|
|
//#import <CallKit/CXCall.h> |
|
|
|
|
|
|
|
|
|
#import "User.h" |
|
|
|
|
#import "CallViewController.h" |
|
|
|
|
#import <JLAuthorizationManager.h> |
|
|
|
|
#import <AVFoundation/AVFoundation.h> |
|
|
|
@ -28,68 +28,232 @@
@@ -28,68 +28,232 @@
|
|
|
|
|
NSInteger tempElapsed ; |
|
|
|
|
BOOL hangUping; |
|
|
|
|
|
|
|
|
|
SystemSoundID sound; |
|
|
|
|
NSTimer *shakeTimer; |
|
|
|
|
|
|
|
|
|
//CXCallObserver *callObserver; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@property (strong, nonatomic) LGAlertView *alertView; |
|
|
|
|
|
|
|
|
|
/// 远端摄像头预览 |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *remoteVideo; |
|
|
|
|
|
|
|
|
|
/// 自己摄像头预览 |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *localVideo; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
控制 挂断 和 接听的 容器 |
|
|
|
|
*/ |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIStackView *buttonStackView; |
|
|
|
|
/** |
|
|
|
|
主动挂断按钮 View |
|
|
|
|
*/ |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *activeHangupView; |
|
|
|
|
///头像 |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIImageView *headImageView; |
|
|
|
|
/// 名称 |
|
|
|
|
@property (weak, nonatomic) UILabel *nameLabel; |
|
|
|
|
/// 通话时间 |
|
|
|
|
@property (weak, nonatomic) UILabel *timeLabel; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
摄像头切换 容器 View |
|
|
|
|
*/ |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *switchCameraView; |
|
|
|
|
/** |
|
|
|
|
静音按钮 容器View |
|
|
|
|
*/ |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *muteBtnView; |
|
|
|
|
|
|
|
|
|
/// 摄像头开关 |
|
|
|
|
@property (weak, nonatomic) UIButton *onSwitchCameraBtn; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
被动挂断按钮 View |
|
|
|
|
*/ |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *hangupView; |
|
|
|
|
///// 摄像头切换 |
|
|
|
|
//@property (weak, nonatomic) UIButton *switchCameraBtn; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
接听按钮 View |
|
|
|
|
*/ |
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *acceptView; |
|
|
|
|
/// 静音按钮 |
|
|
|
|
@property (weak, nonatomic) UIButton *muteBtn; |
|
|
|
|
|
|
|
|
|
/// 接听按钮 |
|
|
|
|
@property (nonatomic ,weak) UIButton *answerBtn; |
|
|
|
|
|
|
|
|
|
/// 挂断按钮(接通之后或拨打等待接听) |
|
|
|
|
@property (nonatomic ,weak) UIButton *hangUpBtn; |
|
|
|
|
|
|
|
|
|
/// 挂断按钮(被动呼叫等待接听) |
|
|
|
|
@property (nonatomic ,weak) UIButton *lefthangUpBtn; |
|
|
|
|
|
|
|
|
|
/// 麦克风开关 |
|
|
|
|
@property (nonatomic ,weak) UIButton *microphoneBtn; |
|
|
|
|
|
|
|
|
|
/// 呼叫状态 |
|
|
|
|
@property (nonatomic ,weak) UILabel *statusLabel; |
|
|
|
|
|
|
|
|
|
/// 与谁的通话 |
|
|
|
|
@property (nonatomic ,weak) UILabel *tonghuaLabel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property (strong, nonatomic) AgoraRtcEngineKit *agoraKit; |
|
|
|
|
@property (nonatomic) int timeLength; |
|
|
|
|
@property (strong, nonatomic) NSTimer *timeTimer; |
|
|
|
|
@property (weak, nonatomic) IBOutlet UILabel *timeLabel; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
是否是接通状态 |
|
|
|
|
*/ |
|
|
|
|
@property (nonatomic) BOOL isCall; |
|
|
|
|
|
|
|
|
|
@property (weak, nonatomic) IBOutlet UIImageView *headImageView; |
|
|
|
|
|
|
|
|
|
@property (weak, nonatomic) IBOutlet UILabel *nameLabel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end |
|
|
|
|
|
|
|
|
|
@implementation CallViewController |
|
|
|
|
|
|
|
|
|
- (void)subViewsLayout |
|
|
|
|
{ |
|
|
|
|
CGSize btnSize = CGSizeMake(60, 90); |
|
|
|
|
WEAKSELF |
|
|
|
|
// /// 摄像头切换 |
|
|
|
|
// UIButton *switchCameraBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKClearColor normalText:@"" click:^(id x) { |
|
|
|
|
// [weakSelf.agoraKit switchCamera]; |
|
|
|
|
// }]; |
|
|
|
|
// switchCameraBtn.hidden = YES; |
|
|
|
|
// [switchCameraBtn setImage:ImageName_(@"video_icon_camera") forState:0]; |
|
|
|
|
// self.switchCameraBtn = switchCameraBtn; |
|
|
|
|
// [self.view addSubview:switchCameraBtn]; |
|
|
|
|
// [switchCameraBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
// make.right.equalTo(self.view.mas_right).inset(16); |
|
|
|
|
// make.top.equalTo(self.view).offset(52); |
|
|
|
|
// make.size.mas_equalTo(CGSizeMake(28, 28)); |
|
|
|
|
// }]; |
|
|
|
|
|
|
|
|
|
self.remoteVideo.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight); |
|
|
|
|
|
|
|
|
|
/// 自己摄像头预览 |
|
|
|
|
self.localVideo.frame = CGRectMake(ScreenWidth-116, 104, 100, 130); |
|
|
|
|
// self.localVideo.layer.borderWidth = 1; |
|
|
|
|
// self.localVideo.layer.borderColor = KKWhiteColorColor.CGColor; |
|
|
|
|
// self.localVideo.layer.cornerRadius = 4; |
|
|
|
|
// self.localVideo.layer.masksToBounds = YES; |
|
|
|
|
// self.localVideo.hidden = YES; |
|
|
|
|
|
|
|
|
|
self.headImageView.hidden = YES; |
|
|
|
|
self.headImageView.layer.cornerRadius = 12; |
|
|
|
|
self.headImageView.layer.masksToBounds = YES; |
|
|
|
|
[self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.centerX.equalTo(self.view); |
|
|
|
|
make.top.equalTo(self.view).offset(154); |
|
|
|
|
make.size.mas_equalTo(CGSizeMake(128, 128)); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(24) textColor:KKWhiteColorColor text:@"" Radius:0]; |
|
|
|
|
nameLabel.hidden = YES; |
|
|
|
|
self.nameLabel = nameLabel; |
|
|
|
|
[self.view addSubview:nameLabel]; |
|
|
|
|
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.centerX.equalTo(self.view); |
|
|
|
|
make.top.equalTo(self.headImageView.mas_bottom).offset(14); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
/// 挂断按钮 |
|
|
|
|
UIButton *hangUpBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(11) normalColor:KKWhiteColorColor normalText:@"挂断" click:^(UIButton *btn) { |
|
|
|
|
[weakSelf activeHangUpBtnAction:btn]; |
|
|
|
|
}]; |
|
|
|
|
hangUpBtn.size = btnSize; |
|
|
|
|
hangUpBtn.hidden = YES; |
|
|
|
|
[hangUpBtn setImage:ImageName_(@"video_icon_cancle") forState:0]; |
|
|
|
|
[self setBtnImageAndTitle:hangUpBtn]; |
|
|
|
|
self.hangUpBtn = hangUpBtn; |
|
|
|
|
[self.view addSubview:hangUpBtn]; |
|
|
|
|
[hangUpBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.centerX.equalTo(self.view); |
|
|
|
|
make.bottom.equalTo(self.view.mas_bottom).inset(58); |
|
|
|
|
make.size.mas_equalTo(btnSize); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 摄像头切换 |
|
|
|
|
UIButton *onSwitchCameraBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(11) normalColor:KKWhiteColorColor normalText:@"转换摄像头" click:^(UIButton *btn) { |
|
|
|
|
[weakSelf.agoraKit switchCamera]; |
|
|
|
|
}]; |
|
|
|
|
onSwitchCameraBtn.size = btnSize; |
|
|
|
|
onSwitchCameraBtn.hidden = YES; |
|
|
|
|
[onSwitchCameraBtn setImage:ImageName_(@"video_icon_camera") forState:UIControlStateNormal]; |
|
|
|
|
[self setBtnImageAndTitle:onSwitchCameraBtn]; |
|
|
|
|
self.onSwitchCameraBtn = onSwitchCameraBtn; |
|
|
|
|
[self.view addSubview:onSwitchCameraBtn]; |
|
|
|
|
[onSwitchCameraBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.right.mas_equalTo(self.view.mas_right).inset(40); |
|
|
|
|
make.centerY.equalTo(hangUpBtn); |
|
|
|
|
make.size.mas_equalTo(btnSize); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
/// 麦克风开关 |
|
|
|
|
UIButton *microphoneBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(11) normalColor:KKWhiteColorColor normalText:@"静音" click:^(UIButton *btn) { |
|
|
|
|
btn.selected = !btn.selected; |
|
|
|
|
[weakSelf.agoraKit muteLocalAudioStream:btn.selected]; |
|
|
|
|
}]; |
|
|
|
|
microphoneBtn.size = btnSize; |
|
|
|
|
microphoneBtn.hidden = YES; |
|
|
|
|
[microphoneBtn setImage:ImageName_(@"video_icon_muteon") forState:UIControlStateNormal]; |
|
|
|
|
[microphoneBtn setImage:ImageName_(@"video_icon_muteoff") forState:UIControlStateSelected]; |
|
|
|
|
[self setBtnImageAndTitle:microphoneBtn]; |
|
|
|
|
self.microphoneBtn = microphoneBtn; |
|
|
|
|
[self.view addSubview:microphoneBtn]; |
|
|
|
|
[microphoneBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.left.equalTo(self.view).offset(40); |
|
|
|
|
make.centerY.equalTo(hangUpBtn); |
|
|
|
|
make.size.mas_equalTo(btnSize); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 挂断按钮(被动呼叫等待接听) |
|
|
|
|
UIButton *lefthangUpBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(11) normalColor:KKWhiteColorColor normalText:@"挂断" click:^(UIButton *btn) { |
|
|
|
|
[weakSelf hangUpButton:btn]; |
|
|
|
|
}]; |
|
|
|
|
lefthangUpBtn.size = btnSize; |
|
|
|
|
lefthangUpBtn.hidden = YES; |
|
|
|
|
[lefthangUpBtn setImage:ImageName_(@"video_icon_cancle") forState:0]; |
|
|
|
|
[self setBtnImageAndTitle:lefthangUpBtn]; |
|
|
|
|
self.lefthangUpBtn = lefthangUpBtn; |
|
|
|
|
[self.view addSubview:lefthangUpBtn]; |
|
|
|
|
[lefthangUpBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.left.equalTo(self.view).offset(40); |
|
|
|
|
make.centerY.equalTo(hangUpBtn); |
|
|
|
|
make.size.mas_equalTo(btnSize); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
/// 接听按钮 |
|
|
|
|
UIButton *answerBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(11) normalColor:KKWhiteColorColor normalText:@"接听" click:^(UIButton *btn) { |
|
|
|
|
[weakSelf acceptBtnAction:btn]; |
|
|
|
|
}]; |
|
|
|
|
answerBtn.size = btnSize; |
|
|
|
|
answerBtn.hidden = YES; |
|
|
|
|
[answerBtn setImage:ImageName_(@"video_icon_pickup") forState:UIControlStateNormal]; |
|
|
|
|
[self setBtnImageAndTitle:answerBtn]; |
|
|
|
|
self.answerBtn = answerBtn; |
|
|
|
|
[self.view addSubview:answerBtn]; |
|
|
|
|
[answerBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.right.equalTo(self.view.mas_right).inset(40); |
|
|
|
|
make.centerY.equalTo(hangUpBtn); |
|
|
|
|
make.size.mas_equalTo(btnSize); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
/// 通话时间 |
|
|
|
|
UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(18) textColor:KKWhiteColorColor text:@"" Radius:0]; |
|
|
|
|
timeLabel.hidden = YES; |
|
|
|
|
self.timeLabel = timeLabel; |
|
|
|
|
[self.view addSubview:timeLabel]; |
|
|
|
|
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.centerX.equalTo(self.view); |
|
|
|
|
make.bottom.equalTo(hangUpBtn.mas_top).inset(24); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
UILabel *statusLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(16) textColor:KKWhiteColorColor text:@"" Radius:0]; |
|
|
|
|
statusLabel.hidden = YES; |
|
|
|
|
self.statusLabel = statusLabel; |
|
|
|
|
[self.view addSubview:statusLabel]; |
|
|
|
|
[statusLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.centerX.equalTo(self.view); |
|
|
|
|
make.top.equalTo(nameLabel.mas_bottom).offset(60); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UILabel *tonghuaLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(18) textColor:KKWhiteColorColor text:@"" Radius:0]; |
|
|
|
|
tonghuaLabel.hidden = YES; |
|
|
|
|
self.tonghuaLabel = tonghuaLabel; |
|
|
|
|
[self.view addSubview:tonghuaLabel]; |
|
|
|
|
[tonghuaLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
|
|
make.left.right.equalTo(self.view).inset(64); |
|
|
|
|
make.top.equalTo(self.view).offset(52); |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad |
|
|
|
|
{ |
|
|
|
|
[super viewDidLoad]; |
|
|
|
|
|
|
|
|
|
WEAKSELF |
|
|
|
|
//添加通知 |
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:AccountMessageNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) { |
|
|
|
@ -105,49 +269,47 @@
@@ -105,49 +269,47 @@
|
|
|
|
|
|
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
self.remoteVideo.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight); |
|
|
|
|
/// 初始化声网 |
|
|
|
|
self.headImageView.layer.cornerRadius = 4; |
|
|
|
|
self.headImageView.layer.masksToBounds = YES; |
|
|
|
|
[self subViewsLayout]; |
|
|
|
|
|
|
|
|
|
//view.layer.masksToBounds = YES; |
|
|
|
|
//判断性别 |
|
|
|
|
NSString *sexImageName = [cUser.cDevice.sex isEqualToString:@"girl"] ? @"icon_girl_head_portrait" : @"icon_boy_head_portrait"; |
|
|
|
|
[self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.device.avator] |
|
|
|
|
placeholderImage:[myHelper getImageWithName:sexImageName] |
|
|
|
|
options:SDWebImageRetryFailed]; |
|
|
|
|
placeholderImage:[myHelper getImageWithName:sexImageName] |
|
|
|
|
options:SDWebImageRetryFailed]; |
|
|
|
|
self.nameLabel.text = self.device.name; |
|
|
|
|
|
|
|
|
|
//设置视频 分辨率等设置 |
|
|
|
|
// [self setupVideo]; |
|
|
|
|
// [self setupVideo]; |
|
|
|
|
//设置 本地视频摄像头 |
|
|
|
|
// [self setupLocalVideo]; |
|
|
|
|
// [self setupLocalVideo]; |
|
|
|
|
|
|
|
|
|
//MARK: 时间默认 不显示 接通后才显示 |
|
|
|
|
self.timeLabel.hidden = YES; |
|
|
|
|
|
|
|
|
|
JLAuthorizationManager *jlManager = [JLAuthorizationManager defaultManager]; |
|
|
|
|
[jlManager JL_requestAuthorizationWithAuthorizationType:JLAuthorizationTypeAudio |
|
|
|
|
authorizedHandler:nil |
|
|
|
|
unAuthorizedHandler:^{ |
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"请为智能守护5打开麦克风权限" message:nil style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
|
|
|
|
|
|
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; |
|
|
|
|
|
|
|
|
|
} cancelHandler:^(LGAlertView *alertView) { |
|
|
|
|
if(weakSelf.isReceiveCall){ |
|
|
|
|
[weakSelf activeHangUpBtnAction:nil]; |
|
|
|
|
}else{ |
|
|
|
|
[weakSelf hangUpButton:nil]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} destructiveHandler:nil]; |
|
|
|
|
[alertView showAnimated:YES completionHandler:nil]; |
|
|
|
|
}]; |
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"请为作业帮打开麦克风权限" message:nil style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
|
|
|
|
|
|
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; |
|
|
|
|
|
|
|
|
|
} cancelHandler:^(LGAlertView *alertView) { |
|
|
|
|
if(weakSelf.isReceiveCall){ |
|
|
|
|
[weakSelf activeHangUpBtnAction:nil]; |
|
|
|
|
}else{ |
|
|
|
|
[weakSelf hangUpButton:nil]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} destructiveHandler:nil]; |
|
|
|
|
[alertView showAnimated:YES completionHandler:nil]; |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
// MARK: 处理来电接听挂断 |
|
|
|
|
if([UIDevice currentDevice].systemVersion.floatValue > 10.0){ |
|
|
|
|
//callObserver= [CXCallObserver new]; |
|
|
|
|
//[callObserver setDelegate:self queue:dispatch_get_main_queue()]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -164,7 +326,7 @@
@@ -164,7 +326,7 @@
|
|
|
|
|
//[self.agoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting]; |
|
|
|
|
[self.agoraKit setClientRole:AgoraClientRoleBroadcaster]; |
|
|
|
|
|
|
|
|
|
[self.agoraKit setLogFile:@"agorasdk"]; |
|
|
|
|
//[self.agoraKit setLogFile:@"agorasdk"]; |
|
|
|
|
|
|
|
|
|
/// 设置默认使用前置摄像头 |
|
|
|
|
AgoraCameraCapturerConfiguration *Camera = [[AgoraCameraCapturerConfiguration alloc] init]; |
|
|
|
@ -174,7 +336,7 @@
@@ -174,7 +336,7 @@
|
|
|
|
|
|
|
|
|
|
[self.agoraKit enableVideo]; |
|
|
|
|
/// 设置 视频分辨率 |
|
|
|
|
[self setupVideo]; |
|
|
|
|
[self setupVideo]; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -204,7 +366,7 @@
@@ -204,7 +366,7 @@
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// [self.agoraKit setParameters:@"{\"rtc.audio.custom_payload_type\":9}"]; |
|
|
|
|
//[self.agoraKit setParameters:@"{\"rtc.audio.custom_payload_type\":9}"]; |
|
|
|
|
self.videoSize = AgoraVideoDimension240x240; |
|
|
|
|
|
|
|
|
|
AgoraVideoEncoderConfiguration *encoderConfiguration = |
|
|
|
@ -239,21 +401,19 @@
@@ -239,21 +401,19 @@
|
|
|
|
|
- (void)setupLocalVideo |
|
|
|
|
{ |
|
|
|
|
if(self.videoSize.width == 160 && self.videoSize.height == 128) |
|
|
|
|
self.localVideo.frame = CGRectMake(ScreenWidth-(128*Adapted(0.35))-50, 50, 160*Adapted(0.35), 128*Adapted(0.35)); |
|
|
|
|
self.localVideo.frame = CGRectMake(ScreenWidth-(128*Adapted(0.35))-50, 104, 160*Adapted(0.35), 128*Adapted(0.35)); |
|
|
|
|
else |
|
|
|
|
self.localVideo.frame = CGRectMake(ScreenWidth*(1-0.25)-25, 50, ScreenWidth * 0.25, ScreenHeight*0.25); |
|
|
|
|
self.localVideo.frame = CGRectMake(ScreenWidth*(1-0.25)-25, 104, ScreenWidth * 0.25, ScreenHeight*0.25); |
|
|
|
|
self.localVideo.backgroundColor = UIColor.blackColor; |
|
|
|
|
AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init]; |
|
|
|
|
videoCanvas.uid = self.uid.integerValue; |
|
|
|
|
videoCanvas.uid = self.uid; |
|
|
|
|
videoCanvas.view = self.localVideo; |
|
|
|
|
//videoCanvas.renderMode = AgoraVideoRenderModeFit; |
|
|
|
|
videoCanvas.mirrorMode = AgoraVideoMirrorModeAuto; |
|
|
|
|
videoCanvas.renderMode = AgoraVideoRenderModeFit; |
|
|
|
|
[self.agoraKit setupLocalVideo:videoCanvas]; |
|
|
|
|
[self.agoraKit startPreview]; |
|
|
|
|
[self.agoraKit setDefaultAudioRouteToSpeakerphone:YES]; |
|
|
|
|
//MARK: 设置录音的音量是原本的4倍 |
|
|
|
|
int adjust = [self.agoraKit adjustRecordingSignalVolume:400]; |
|
|
|
|
NSLog(@"调节录音音量=%d",adjust); |
|
|
|
|
[self.agoraKit adjustRecordingSignalVolume:400]; |
|
|
|
|
self.localVideo.hidden = YES; |
|
|
|
|
|
|
|
|
|
//添加拖动手势 |
|
|
|
@ -273,20 +433,19 @@
@@ -273,20 +433,19 @@
|
|
|
|
|
*/ |
|
|
|
|
- (void)joinChannel |
|
|
|
|
{ |
|
|
|
|
//if(self.channelID && self.uid ) |
|
|
|
|
if(self.channelID && self.uid ) |
|
|
|
|
{ |
|
|
|
|
WeakSelf |
|
|
|
|
AgoraRtcChannelMediaOptions *option = [[AgoraRtcChannelMediaOptions alloc] init]; |
|
|
|
|
AgoraRtcChannelMediaOptions *option = [AgoraRtcChannelMediaOptions new]; |
|
|
|
|
[option setPublishCameraTrack:YES]; |
|
|
|
|
[option setClientRoleType:AgoraClientRoleBroadcaster]; |
|
|
|
|
|
|
|
|
|
int res = [self.agoraKit joinChannelByToken:self.token channelId:self.channelID uid:self.uid.integerValue mediaOptions:option joinSuccess:^(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed) { |
|
|
|
|
xLog(@"加入通道成功"); |
|
|
|
|
|
|
|
|
|
int res = [self.agoraKit joinChannelByToken:self.token channelId:self.channelID uid:self.uid mediaOptions:option joinSuccess:^(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed) { |
|
|
|
|
xLog(@"加入通道"); |
|
|
|
|
//启动定时器 |
|
|
|
|
[weakSelf _startTimeTimer]; |
|
|
|
|
weakSelf.isCall = YES; |
|
|
|
|
[weakSelf stopRing]; |
|
|
|
|
weakSelf.localVideo.hidden = NO; |
|
|
|
|
self.agoraKit.delegate = self; |
|
|
|
|
|
|
|
|
|
}]; |
|
|
|
|
xLog(@"加入通道res == %d" , res); |
|
|
|
@ -294,34 +453,25 @@
@@ -294,34 +453,25 @@
|
|
|
|
|
[self.agoraKit setEnableSpeakerphone:YES]; |
|
|
|
|
//启用不自动锁屏 |
|
|
|
|
[UIApplication sharedApplication].idleTimerDisabled = YES; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
MARK: APP 接听按钮 |
|
|
|
|
*/ |
|
|
|
|
- (IBAction)acceptBtnAction:(id)sender { |
|
|
|
|
// AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate); |
|
|
|
|
// [self stopAlertSoundWithSoundID:sound]; |
|
|
|
|
// self.isCall = YES; |
|
|
|
|
- (void)acceptBtnAction:(id)sender { |
|
|
|
|
self.isCall = YES; |
|
|
|
|
[self joinChannel]; |
|
|
|
|
// [self stopRing]; |
|
|
|
|
// self.localVideo.hidden = NO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
-(void)stopAlertSoundWithSoundID:(SystemSoundID)sound { |
|
|
|
|
AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate); |
|
|
|
|
[self stopRing]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
MARK: APP 主动挂断按钮 (接通后APP的挂断) |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
- (IBAction)activeHangUpBtnAction:(id)sender { |
|
|
|
|
- (void)activeHangUpBtnAction:(id)sender |
|
|
|
|
{ |
|
|
|
|
[self stopRing]; |
|
|
|
|
[self leaveChannel]; |
|
|
|
|
if(!hangUping) |
|
|
|
@ -345,11 +495,10 @@
@@ -345,11 +495,10 @@
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
//MARK: 收到设备主动挂断 后的 推送的 动作 |
|
|
|
|
//[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@ 拒绝了你的通话请求",cUser.cDevice.name]]; |
|
|
|
|
[SVProgressHUD showInfoWithStatus:@"视频通话结束"]; |
|
|
|
|
[SVProgressHUD dismissWithDelay:1 completion:^{ |
|
|
|
|
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@ 拒绝了你的通话请求",cUser.cDevice.name]]; |
|
|
|
|
AfterDispatch(1, ^{ |
|
|
|
|
[weakSelf dismissViewControllerAnimated:YES completion:nil]; |
|
|
|
|
}]; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -360,7 +509,7 @@
@@ -360,7 +509,7 @@
|
|
|
|
|
MARK: APP 被动挂断按钮 (接通前APP的挂断) |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
- (IBAction)hangUpButton:(UIButton *)sender { |
|
|
|
|
- (void)hangUpButton:(UIButton *)sender { |
|
|
|
|
[self stopRing]; |
|
|
|
|
[self leaveChannel]; |
|
|
|
|
if(!hangUping){ |
|
|
|
@ -430,12 +579,6 @@
@@ -430,12 +579,6 @@
|
|
|
|
|
}]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//MARK: 静音 |
|
|
|
|
- (IBAction)didClickMuteButton:(UIButton *)sender { |
|
|
|
|
sender.selected = !sender.selected; |
|
|
|
|
[self.agoraKit muteLocalAudioStream:sender.selected]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
用户在 视频通话 和 语音通话间切换 (暂时不用) |
|
|
|
|
*/ |
|
|
|
@ -446,15 +589,6 @@
@@ -446,15 +589,6 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//MARK: 切换摄像头 |
|
|
|
|
- (IBAction)didClickSwitchCameraButton:(UIButton *)sender { |
|
|
|
|
sender.selected = !sender.selected; |
|
|
|
|
[self.agoraKit switchCamera]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark AgoraRtcEngineDelegate |
|
|
|
|
/// 发生错误回调 |
|
|
|
|
- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurError:(AgoraErrorCode)errorCode{ |
|
|
|
@ -523,7 +657,7 @@
@@ -523,7 +657,7 @@
|
|
|
|
|
//MARK: 频道的统计数据 回调 每两秒触发一次。 |
|
|
|
|
-(void)rtcEngine:(AgoraRtcEngineKit *)engine reportRtcStats:(AgoraChannelStats *)stats |
|
|
|
|
{ |
|
|
|
|
//NSLog(@"//MARK: 频道的统计数据 回调 每两秒触发一次。"); |
|
|
|
|
NSLog(@"//MARK: 频道的统计数据 回调 每两秒触发一次。"); |
|
|
|
|
if(self.isCall) |
|
|
|
|
{ |
|
|
|
|
// self.timeLength = (int)stats.duration - wait_duration; |
|
|
|
@ -555,13 +689,12 @@
@@ -555,13 +689,12 @@
|
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(uid == self.device_uid.integerValue) |
|
|
|
|
if(uid == self.device_uid) |
|
|
|
|
{ |
|
|
|
|
[self leaveChannel]; |
|
|
|
|
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@已挂断",cUser.cDevice.name]]; |
|
|
|
|
[SVProgressHUD dismissWithDelay:1]; |
|
|
|
|
} |
|
|
|
|
if(uid == self.uid.integerValue){ |
|
|
|
|
if(uid == self.uid){ |
|
|
|
|
xLog(@"自己离开通道"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -580,10 +713,10 @@
@@ -580,10 +713,10 @@
|
|
|
|
|
wait_duration = self.wait_time; |
|
|
|
|
[self leaveChannel]; |
|
|
|
|
WEAKSELF |
|
|
|
|
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@ 未接听",cUser.cDevice.name]]; |
|
|
|
|
[SVProgressHUD dismissWithDelay:1 completion:^{ |
|
|
|
|
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@ 未接听",self.device.name]]; |
|
|
|
|
AfterDispatch(1, ^{ |
|
|
|
|
[weakSelf dismissViewControllerAnimated:YES completion:nil]; |
|
|
|
|
}]; |
|
|
|
|
}); |
|
|
|
|
[self _stopTimeTimer]; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -685,14 +818,11 @@
@@ -685,14 +818,11 @@
|
|
|
|
|
if(!self.isReceiveCall) |
|
|
|
|
{ |
|
|
|
|
//主动拨打 |
|
|
|
|
//显示静音 和 切换摄像头 |
|
|
|
|
self.switchCameraView.hidden = NO; |
|
|
|
|
self.muteBtnView.hidden = NO; |
|
|
|
|
|
|
|
|
|
//隐藏 被动接听 和 被动挂断 |
|
|
|
|
self.activeHangupView.hidden = NO; |
|
|
|
|
self.acceptView.hidden = YES; |
|
|
|
|
self.hangupView.hidden = YES; |
|
|
|
|
self.hangUpBtn.hidden = NO; |
|
|
|
|
self.headImageView.hidden = NO; |
|
|
|
|
self.nameLabel.hidden = NO; |
|
|
|
|
self.statusLabel.hidden = NO; |
|
|
|
|
self.statusLabel.text = @"正在呼叫中..."; |
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
|
|
[weakSelf playRing:@"ring"]; |
|
|
|
|
}); |
|
|
|
@ -701,38 +831,21 @@
@@ -701,38 +831,21 @@
|
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
//被动接听 |
|
|
|
|
//隐藏 静音 和 切换摄像头 |
|
|
|
|
self.switchCameraView.hidden = YES; |
|
|
|
|
self.muteBtnView.hidden = YES; |
|
|
|
|
self.activeHangupView.hidden = YES; |
|
|
|
|
self.acceptView.hidden = NO; |
|
|
|
|
self.hangupView.hidden = NO; |
|
|
|
|
// if([UIApplication sharedApplication].applicationState == UIApplicationStateActive) |
|
|
|
|
{ |
|
|
|
|
self.headImageView.hidden = NO; |
|
|
|
|
self.nameLabel.hidden = NO; |
|
|
|
|
self.statusLabel.hidden = NO; |
|
|
|
|
self.statusLabel.text = @"连接中"; |
|
|
|
|
self.lefthangUpBtn.hidden = NO; |
|
|
|
|
self.answerBtn.hidden = NO; |
|
|
|
|
|
|
|
|
|
if([UIApplication sharedApplication].applicationState == UIApplicationStateActive){ |
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
|
|
// AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, soundCompleteCallback, NULL); |
|
|
|
|
// AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); |
|
|
|
|
// AudioServicesPlaySystemSound(self->sound); |
|
|
|
|
[weakSelf playRing:@"tones"]; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void soundCompleteCallback(SystemSoundID sound,void * clientData) { |
|
|
|
|
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //震动 |
|
|
|
|
AudioServicesPlaySystemSound(sound); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern OSStatus |
|
|
|
|
AudioServicesAddSystemSoundCompletion( SystemSoundID inSystemSoundID, |
|
|
|
|
CFRunLoopRef inRunLoop, |
|
|
|
|
CFStringRef inRunLoopMode, |
|
|
|
|
AudioServicesSystemSoundCompletionProc inCompletionRoutine, |
|
|
|
|
void* inClientData) |
|
|
|
|
__OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_2_0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)setIsCall:(BOOL)isCall |
|
|
|
|
{ |
|
|
|
@ -742,16 +855,19 @@ __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_2_0);
@@ -742,16 +855,19 @@ __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_2_0);
|
|
|
|
|
//隐藏 设备 头像 和 昵称 显示 (默认是显示的) |
|
|
|
|
self.headImageView.hidden = YES; |
|
|
|
|
self.nameLabel.hidden = YES; |
|
|
|
|
self.localVideo.hidden = NO; // 显示自己 |
|
|
|
|
self.lefthangUpBtn.hidden = YES; /// 挂断按钮(被动呼叫等待接听) |
|
|
|
|
self.answerBtn.hidden = YES; /// 接听按钮 |
|
|
|
|
self.statusLabel.hidden = YES; |
|
|
|
|
|
|
|
|
|
self.activeHangupView.hidden = NO; |
|
|
|
|
self.acceptView.hidden = YES; |
|
|
|
|
self.hangupView.hidden = YES; |
|
|
|
|
//显示 时间Label |
|
|
|
|
self.localVideo.hidden = NO; // 显示自己 |
|
|
|
|
self.timeLabel.hidden = NO; |
|
|
|
|
//显示 |
|
|
|
|
self.switchCameraView.hidden = NO; |
|
|
|
|
self.muteBtnView.hidden = NO; |
|
|
|
|
//self.switchCameraBtn.hidden = NO;/// 切换摄像头 |
|
|
|
|
self.microphoneBtn.hidden = NO; /// 麦克风 |
|
|
|
|
self.muteBtn.hidden = NO; /// 静音按钮 |
|
|
|
|
self.onSwitchCameraBtn.hidden = NO; /// 切换摄像头 |
|
|
|
|
self.hangUpBtn.hidden = NO; /// 接通后挂断按钮 |
|
|
|
|
self.tonghuaLabel.hidden = NO; |
|
|
|
|
self.tonghuaLabel.text = [NSString stringWithFormat:@"与%@的对话",self.device.name]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -796,6 +912,15 @@ __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_2_0);
@@ -796,6 +912,15 @@ __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_2_0);
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)setBtnImageAndTitle:(UIButton *)button |
|
|
|
|
{ |
|
|
|
|
CGFloat offset = 20.0f; |
|
|
|
|
button.titleEdgeInsets = UIEdgeInsetsMake(0,-button.imageView.frame.size.width,-button.imageView.frame.size.height-offset/2,0); |
|
|
|
|
// button.imageEdgeInsets = UIEdgeInsetsMake(-button.titleLabel.frame.size.height-offset/2,0,0,-button.titleLabel.frame.size.width); |
|
|
|
|
// 由于iOS8中titleLabel的size为0,用上面这样设置有问题,修改一下即可 |
|
|
|
|
button.imageEdgeInsets = UIEdgeInsetsMake(-button.titleLabel.intrinsicContentSize.height-offset/2,0,0,-button.titleLabel.intrinsicContentSize.width); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(void)dealloc |
|
|
|
|
{ |
|
|
|
|