|
@@ -7,51 +7,15 @@
|
|
|
//
|
|
|
|
|
|
#import "SKInCallViewController.h"
|
|
|
+#import "SKInCallViewController+juphoon.h"
|
|
|
+#import "SKInCallViewController+agora.h"
|
|
|
+#import "SKInCallViewController+touch.h"
|
|
|
#import "VideoManager+ringtone.h"
|
|
|
|
|
|
-#define kDoodleVersionChecker 1
|
|
|
-#define AUDIO_RECORD_DIR @"audio_record"
|
|
|
-#define SNAPSHOT_DIR @"snapshot"
|
|
|
-#define VIDEO_RECORD_DIR @"video_record"
|
|
|
-
|
|
|
|
|
|
@interface SKInCallViewController() {
|
|
|
- JCMediaDeviceVideoCanvas* _localCanvas;
|
|
|
- JCMediaDeviceVideoCanvas* _remoteCanvas;
|
|
|
- JCMediaDeviceVideoCanvas* _mSmallCanvas;
|
|
|
NSTimer* _timer;
|
|
|
- BOOL isTouchInSmallCanvas;
|
|
|
- BOOL isMoveInSmallCanvas;
|
|
|
- CGPoint mStartPoint;
|
|
|
}
|
|
|
-
|
|
|
-@property (weak, nonatomic) IBOutlet UIImageView *backgroudView;
|
|
|
-@property (weak, nonatomic) IBOutlet UIView *mIngHeaderView;
|
|
|
-@property (weak, nonatomic) IBOutlet UILabel *mIngNameLabel;
|
|
|
-@property (weak, nonatomic) IBOutlet UILabel *mIngTimeLabel;
|
|
|
-@property (weak, nonatomic) IBOutlet UILabel *mIngNetWorkLabel;
|
|
|
-
|
|
|
-@property (weak, nonatomic) IBOutlet UIView *mWaitHeaderView;
|
|
|
-@property (weak, nonatomic) IBOutlet UIImageView *mWaitHeadImage;
|
|
|
-@property (weak, nonatomic) IBOutlet UILabel *mWaitNameLabel;
|
|
|
-@property (weak, nonatomic) IBOutlet UILabel *mWaitInHintLabel;
|
|
|
-@property (weak, nonatomic) IBOutlet UILabel *mWaitOutHintLabel;
|
|
|
-
|
|
|
-@property (weak, nonatomic) IBOutlet UIView *mInVideoView;
|
|
|
-@property (weak, nonatomic) IBOutlet UIView *mOutView;
|
|
|
-@property (weak, nonatomic) IBOutlet UIView *mIngView;
|
|
|
-
|
|
|
-// selected 为相机打开状态, default 为相机关闭状态
|
|
|
-@property (weak, nonatomic) IBOutlet UIButton *switchCameraBtn;
|
|
|
-// selected 为保持通话状态, default 为未保持通话状态, disable 为被保持通话状态
|
|
|
-@property (weak, nonatomic) IBOutlet UIButton *holdBtn;
|
|
|
-// selected 为静音状态, default 为正常状态
|
|
|
-@property (weak, nonatomic) IBOutlet UIButton *muteBtn;
|
|
|
-
|
|
|
-// selected 为听筒模式, default 为扬声器模式
|
|
|
-@property (weak, nonatomic) IBOutlet UIButton *speakerBtn;
|
|
|
-@property (weak, nonatomic) IBOutlet UIButton *endCallBtn;
|
|
|
-
|
|
|
@end
|
|
|
|
|
|
@implementation SKInCallViewController
|
|
@@ -64,16 +28,15 @@
|
|
|
[EUtil setViewShadow:self.mWaitNameLabel color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:4];
|
|
|
[EUtil setViewShadow:self.mWaitOutHintLabel color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:4];
|
|
|
[EUtil setViewShadow:self.mWaitInHintLabel color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:4];
|
|
|
- [VideoManager shared].mJuphoonMediaDevice.videoAngle = JCMediaDeviceVideoAngel0;
|
|
|
|
|
|
[EUtil setViewShadow:self.mIngNameLabel color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:4];
|
|
|
[EUtil setViewShadow:self.mIngTimeLabel color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:4];
|
|
|
[EUtil setViewShadow:self.mIngNetWorkLabel color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:4];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUI:) name:kCallNotification object:nil];
|
|
|
|
|
|
- _mSmallCanvas = nil;
|
|
|
- isTouchInSmallCanvas = NO;
|
|
|
- isMoveInSmallCanvas = NO;
|
|
|
+ _smallView = nil;
|
|
|
+ self.isTouchInSmallCanvas = NO;
|
|
|
+ self.isMoveInSmallCanvas = NO;
|
|
|
[self initView];
|
|
|
[self updateUI:nil];
|
|
|
[[VideoManager shared] playVideoWaitingRingtone];
|
|
@@ -106,98 +69,11 @@
|
|
|
[[VideoManager shared] playVideoFinishRingtone];
|
|
|
}
|
|
|
|
|
|
-- (NSObject*)getRemoteCanvas {
|
|
|
- return _remoteCanvas;
|
|
|
-}
|
|
|
-
|
|
|
- (void)initView {
|
|
|
[EUtil setURLImage:self.mWaitHeadImage placeHolderName:@"avatar" imageURL:[[VideoManager shared] getTalkHeadImageURL] cornerRadius:self.mWaitHeadImage.frame.size.width/2];
|
|
|
}
|
|
|
|
|
|
-- (void)updateUI:(NSNotification *)noti {
|
|
|
- NSInteger count = [VideoManager shared].mJuphoonCall.callItems.count;
|
|
|
- JCCallItem *activeCall = [VideoManager shared].mJuphoonCall.callItems.firstObject;
|
|
|
- HDNormalLog(([NSString stringWithFormat:@"VideoManager: updateUI count:%ld updateUI: %ld", count, activeCall.state]));
|
|
|
-
|
|
|
- if (activeCall.state == JCCallStateInit || activeCall.state == JCCallStatePending) {
|
|
|
-
|
|
|
- self.mInVideoView.hidden = !activeCall.video || activeCall.direction == JCCallDirectionOut;
|
|
|
- self.mOutView.hidden = activeCall.direction != JCCallDirectionOut;
|
|
|
- self.mWaitHeaderView.hidden = NO;
|
|
|
- self.mIngHeaderView.hidden = YES;
|
|
|
- self.mIngView.hidden = YES;
|
|
|
-
|
|
|
- self.mIngNameLabel.text = @"";
|
|
|
- self.mWaitNameLabel.text = [[VideoManager shared] getTalkName];
|
|
|
- self.mWaitInHintLabel.hidden = activeCall.direction != JCCallDirectionIn;
|
|
|
- self.mWaitOutHintLabel.hidden = activeCall.direction != JCCallDirectionOut;
|
|
|
-
|
|
|
- if (activeCall.video) {
|
|
|
- if (_localCanvas == nil && activeCall.uploadVideoStreamSelf) {
|
|
|
- _localCanvas = [[VideoManager shared].mJuphoonMediaDevice startCameraVideo:JCMediaDeviceRenderFullScreen];
|
|
|
- //_localCanvas.videoView.frame = CGRectMake(SCREEN_WIDTH - 150, SCREEN_HEIGHT - 150 - 160, 120, 160);
|
|
|
- _localCanvas.videoView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
- [self.view insertSubview:_localCanvas.videoView aboveSubview:self.backgroudView];
|
|
|
- } else if (_localCanvas != nil && !activeCall.uploadVideoStreamSelf) {
|
|
|
- [[VideoManager shared].mJuphoonMediaDevice stopVideo:_localCanvas];
|
|
|
- [_localCanvas.videoView removeFromSuperview];
|
|
|
- _localCanvas = nil;
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (activeCall.state == JCCallStateTalking) {
|
|
|
- self.mInVideoView.hidden = YES;
|
|
|
- self.mOutView.hidden = YES;
|
|
|
- self.mWaitHeaderView.hidden = YES;
|
|
|
- self.mIngHeaderView.hidden = NO;
|
|
|
- self.mIngView.hidden = NO;
|
|
|
- self.mIngNameLabel.text = [[VideoManager shared] getTalkName];
|
|
|
-
|
|
|
- self.switchCameraBtn.enabled = activeCall.video;
|
|
|
- self.holdBtn.enabled = !activeCall.held;
|
|
|
- self.holdBtn.selected = activeCall.hold;
|
|
|
- self.muteBtn.selected = activeCall.mute;
|
|
|
- self.speakerBtn.selected = [VideoManager shared].mJuphoonMediaDevice.isSpeakerOn;
|
|
|
-
|
|
|
- if (activeCall != nil && activeCall.audioRecord && (activeCall.hold || activeCall.held)) {
|
|
|
- [[VideoManager shared].mJuphoonCall audioRecord:activeCall enable:false filePath:@""];
|
|
|
- }
|
|
|
- if (activeCall != nil && activeCall.localVideoRecord && !activeCall.uploadVideoStreamSelf) {
|
|
|
- //[[VideoManager shared].mJuphoonCall videoRecord:activeCall enable:false remote:false width:0 height:0 filePath:@""];
|
|
|
- [[VideoManager shared].mJuphoonCall videoRecord:activeCall enable:false remote:false width:0 height:0 filePath:@"" bothAudio:false keyFrame:10];
|
|
|
- }
|
|
|
- if (activeCall != nil && activeCall.remoteVideoRecord && !activeCall.uploadVideoStreamOther) {
|
|
|
- [[VideoManager shared].mJuphoonCall videoRecord:activeCall enable:false remote:true width:0 height:0 filePath:@"" bothAudio:false keyFrame:10];
|
|
|
- }
|
|
|
- if (activeCall.video) {
|
|
|
- if (_localCanvas != nil && activeCall.uploadVideoStreamSelf) {
|
|
|
- if (_mSmallCanvas == nil) {
|
|
|
- _localCanvas.videoView.frame = CGRectMake(SCREEN_WIDTH - 130, SCREEN_STATUS_HEIGHT+10, 120, 160);
|
|
|
- }
|
|
|
- _mSmallCanvas = _localCanvas;
|
|
|
- }
|
|
|
-
|
|
|
- if (_remoteCanvas == nil && activeCall.uploadVideoStreamOther) {
|
|
|
- _remoteCanvas = [[VideoManager shared].mJuphoonMediaDevice startVideo:activeCall.renderId renderType:JCMediaDeviceRenderFullContent];
|
|
|
- _remoteCanvas.videoView.frame = self.view.frame;
|
|
|
- _remoteCanvas.videoView.hidden = !activeCall.uploadVideoStreamSelf;
|
|
|
- [self.view insertSubview:_remoteCanvas.videoView aboveSubview:self.backgroudView];
|
|
|
- [[VideoManager shared].mJuphoonMediaDevice enableSpeaker:YES];
|
|
|
- } else if (_remoteCanvas != nil && !activeCall.uploadVideoStreamOther) {
|
|
|
- [[VideoManager shared].mJuphoonMediaDevice stopVideo:_remoteCanvas];
|
|
|
- [_remoteCanvas.videoView removeFromSuperview];
|
|
|
- _remoteCanvas = nil;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [self startTimer];
|
|
|
- [[VideoManager shared] stopVideoRingtone];
|
|
|
- } else {
|
|
|
- self.mInVideoView.hidden = YES;
|
|
|
- }
|
|
|
- if (!activeCall.video) {
|
|
|
- [self removeCanvas];
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
#pragma mark - Incoming Actions
|
|
|
- (IBAction)endCall:(id)sender {
|
|
@@ -211,17 +87,20 @@
|
|
|
}
|
|
|
|
|
|
- (IBAction)videoAnswer:(id)sender {
|
|
|
- [[VideoManager shared].mJuphoonCall answer:[self getActiveCall] video:true];
|
|
|
+ JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
|
|
|
+ [[VideoManager shared].mJuphoonCall answer:activeCall video:true];
|
|
|
}
|
|
|
|
|
|
- (IBAction)voiceAnswer:(id)sender {
|
|
|
- [[VideoManager shared].mJuphoonCall answer:[self getActiveCall] video:false];
|
|
|
+ JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
|
|
|
+ [[VideoManager shared].mJuphoonCall answer:activeCall video:false];
|
|
|
}
|
|
|
|
|
|
#pragma mark - In Calling Actions
|
|
|
|
|
|
- (IBAction)setCameraState:(id)sender {
|
|
|
- [[VideoManager shared].mJuphoonCall enableUploadVideoStream:[self getActiveCall]];
|
|
|
+ JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
|
|
|
+ [[VideoManager shared].mJuphoonCall enableUploadVideoStream:activeCall];
|
|
|
}
|
|
|
|
|
|
- (IBAction)addNewCall:(id)sender {
|
|
@@ -232,11 +111,13 @@
|
|
|
}
|
|
|
|
|
|
- (IBAction)hold:(id)sender {
|
|
|
- [[VideoManager shared].mJuphoonCall hold:[self getActiveCall]];
|
|
|
+ JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
|
|
|
+ [[VideoManager shared].mJuphoonCall hold:activeCall];
|
|
|
}
|
|
|
|
|
|
- (IBAction)mute:(id)sender {
|
|
|
- [[VideoManager shared].mJuphoonCall mute:[self getActiveCall]];
|
|
|
+ JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
|
|
|
+ [[VideoManager shared].mJuphoonCall mute:activeCall];
|
|
|
}
|
|
|
|
|
|
- (IBAction)audioRecord:(id)sender {
|
|
@@ -257,16 +138,7 @@
|
|
|
}
|
|
|
|
|
|
#pragma mark - 工具函数
|
|
|
--(JCCallItem*)getActiveCall {
|
|
|
- for (JCCallItem* item in [VideoManager shared].mJuphoonCall.callItems) {
|
|
|
- if (item.active) {
|
|
|
- return item;
|
|
|
- }
|
|
|
- }
|
|
|
- return nil;
|
|
|
-}
|
|
|
-
|
|
|
-- (NSString *)genCallInfo:(JCCallItem*)item {
|
|
|
+- (NSString *)getCallInfo:(JCCallItem*)item {
|
|
|
switch (item.state) {
|
|
|
case JCCallStateTalking:
|
|
|
return [self formatTalkingTime:((long)[[NSDate date] timeIntervalSince1970] - item.talkingBeginTime)];
|
|
@@ -275,50 +147,12 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (NSString *)genNetStatus:(JCCallItem *)item {
|
|
|
- if (item.state != JCCallStateTalking) {
|
|
|
- return @"";
|
|
|
- }
|
|
|
- switch (item.videoNetSendStatus) {
|
|
|
- case JCCallNetWorkDisconnected:
|
|
|
- return NSLocalizedString(@"Video.Network.Status.0", nil);
|
|
|
- case JCCallNetWorkVeryBad:
|
|
|
- return NSLocalizedString(@"Video.Network.Status.1", nil);
|
|
|
- case JCCallNetWorkBad:
|
|
|
- return NSLocalizedString(@"Video.Network.Status.2", nil);
|
|
|
- case JCCallNetWorkNormal:
|
|
|
- return NSLocalizedString(@"Video.Network.Status.3", nil);
|
|
|
- case JCCallNetWorkGood:
|
|
|
- return NSLocalizedString(@"Video.Network.Status.4", nil);
|
|
|
- case JCCallNetWorkVeryGood:
|
|
|
- return NSLocalizedString(@"Video.Network.Status.5", nil);
|
|
|
- default:
|
|
|
- return @"";
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (NSString *)formatTalkingTime:(long)time
|
|
|
-{
|
|
|
+- (NSString *)formatTalkingTime:(long)time {
|
|
|
return [NSString stringWithFormat:@"%02ld:%02ld", time/60, time%60];
|
|
|
}
|
|
|
|
|
|
-- (void)removeCanvas {
|
|
|
- if (_localCanvas) {
|
|
|
- [[VideoManager shared].mJuphoonMediaDevice stopVideo:_localCanvas];
|
|
|
- [_localCanvas.videoView removeFromSuperview];
|
|
|
- _localCanvas = nil;
|
|
|
- _mSmallCanvas = nil;
|
|
|
- }
|
|
|
- if (_remoteCanvas) {
|
|
|
- [[VideoManager shared].mJuphoonMediaDevice stopVideo:_remoteCanvas];
|
|
|
- [_remoteCanvas.videoView removeFromSuperview];
|
|
|
- _remoteCanvas = nil;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#pragma mark - Timer
|
|
|
-- (void)startTimer
|
|
|
-{
|
|
|
+- (void)startTimer {
|
|
|
if (_timer == nil) {
|
|
|
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerProc) userInfo:nil repeats:YES];
|
|
|
}
|
|
@@ -335,92 +169,11 @@
|
|
|
|
|
|
- (void)timerProc {
|
|
|
self.mIngHeaderView.hidden = NO;
|
|
|
- JCCallItem *activeCall = [VideoManager shared].mJuphoonCall.callItems.firstObject;
|
|
|
- self.mIngTimeLabel.text = [self genCallInfo:activeCall];
|
|
|
- self.mIngNetWorkLabel.text = [self genNetStatus:activeCall];
|
|
|
+ JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
|
|
|
+ self.mIngTimeLabel.text = [self getCallInfo:activeCall];
|
|
|
+ self.mIngNetWorkLabel.text = [self getNetStatus:activeCall];
|
|
|
if (activeCall.direction == JCCallDirectionOut) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
|
- //如果不在通话
|
|
|
- JCCallItem *activeCall = [VideoManager shared].mJuphoonCall.callItems.firstObject;
|
|
|
- if (!activeCall.video && activeCall.state != JCCallStateTalking)
|
|
|
- return;
|
|
|
-
|
|
|
- UITouch *touch = [touches anyObject];
|
|
|
- //当前的坐标,第一次触摸
|
|
|
- CGPoint point = [touch locationInView: self.view];
|
|
|
- mStartPoint = point;
|
|
|
-
|
|
|
- point = [_mSmallCanvas.videoView.layer convertPoint:point fromLayer:self.view.layer];
|
|
|
- if ([_mSmallCanvas.videoView.layer containsPoint:point]) {
|
|
|
- isTouchInSmallCanvas = YES;
|
|
|
- }
|
|
|
- else {
|
|
|
- isTouchInSmallCanvas = NO;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
|
- //如果不在通话
|
|
|
- JCCallItem *activeCall = [VideoManager shared].mJuphoonCall.callItems.firstObject;
|
|
|
- if (!activeCall.video && activeCall.state != JCCallStateTalking)
|
|
|
- return;
|
|
|
-
|
|
|
- if (!isTouchInSmallCanvas)
|
|
|
- return;
|
|
|
-
|
|
|
- UITouch *touch = [touches anyObject];
|
|
|
- CGPoint movePoint = [touch locationInView: self.view];
|
|
|
-
|
|
|
- CGPoint offsetPoint = CGPointMake(movePoint.x - mStartPoint.x, movePoint.y - mStartPoint.y);
|
|
|
- if (offsetPoint.x == 0 && offsetPoint.y == 0)
|
|
|
- return;
|
|
|
-
|
|
|
- isMoveInSmallCanvas = YES;
|
|
|
- CGRect canvasRect = _mSmallCanvas.videoView.frame;
|
|
|
- CGPoint endPoint = CGPointMake(canvasRect.origin.x + offsetPoint.x, canvasRect.origin.y + offsetPoint.y);
|
|
|
-
|
|
|
- //避免超框
|
|
|
- if (endPoint.x < 0.0) {
|
|
|
- endPoint.x = 0.0;
|
|
|
- }
|
|
|
- if (endPoint.y < SCREEN_STATUS_HEIGHT) {
|
|
|
- endPoint.y = SCREEN_STATUS_HEIGHT;
|
|
|
- }
|
|
|
- if (endPoint.x + canvasRect.size.width > SCREEN_WIDTH) {
|
|
|
- endPoint.x = SCREEN_WIDTH - canvasRect.size.width;
|
|
|
- }
|
|
|
- if (endPoint.y + canvasRect.size.height > SCREEN_HEIGHT) {
|
|
|
- endPoint.y = SCREEN_HEIGHT - canvasRect.size.height;
|
|
|
- }
|
|
|
-
|
|
|
- [_mSmallCanvas.videoView setOrigin:endPoint];
|
|
|
-
|
|
|
- mStartPoint = movePoint;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
|
- //如果不在通话
|
|
|
- JCCallItem *activeCall = [VideoManager shared].mJuphoonCall.callItems.firstObject;
|
|
|
- if (!activeCall.video && activeCall.state != JCCallStateTalking)
|
|
|
- return;
|
|
|
-
|
|
|
- isTouchInSmallCanvas = NO;
|
|
|
- isMoveInSmallCanvas = NO;
|
|
|
- mStartPoint = CGPointMake(0, 0);
|
|
|
-}
|
|
|
-
|
|
|
-- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
|
- //如果不在通话
|
|
|
- JCCallItem *activeCall = [VideoManager shared].mJuphoonCall.callItems.firstObject;
|
|
|
- if (!activeCall.video && activeCall.state != JCCallStateTalking)
|
|
|
- return;
|
|
|
-
|
|
|
- isTouchInSmallCanvas = NO;
|
|
|
- isMoveInSmallCanvas = NO;
|
|
|
- mStartPoint = CGPointMake(0, 0);
|
|
|
-}
|
|
|
-
|
|
|
@end
|