SKInCallViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // InCallViewController.m
  3. // JCSampleOC
  4. //
  5. // Created by Ginger on 2017/10/12.
  6. // Copyright © 2017年 juphoon. All rights reserved.
  7. //
  8. #import "SKInCallViewController.h"
  9. #import "SKInCallViewController+juphoon.h"
  10. #import "SKInCallViewController+agora.h"
  11. #import "SKInCallViewController+touch.h"
  12. #import "VideoManager+ringtone.h"
  13. @interface SKInCallViewController() {
  14. NSTimer* _timer;
  15. }
  16. @end
  17. @implementation SKInCallViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
  21. [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];
  22. [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];
  23. [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];
  24. [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];
  25. [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];
  26. [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];
  27. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUI:) name:kCallNotification object:nil];
  28. _smallView = nil;
  29. self.isTouchInSmallCanvas = NO;
  30. self.isMoveInSmallCanvas = NO;
  31. [self initView];
  32. [self updateUI:nil];
  33. [[VideoManager shared] playVideoWaitingRingtone];
  34. }
  35. - (void)viewWillAppear:(BOOL)animated {
  36. [super viewWillAppear:animated];
  37. [self.navigationController setNavigationBarHidden:YES animated:NO];
  38. }
  39. - (void)viewDidAppear:(BOOL)animated {
  40. [[VideoManager shared].mJuphoonMediaDevice enableSpeaker:YES];
  41. }
  42. - (void)viewWillDisappear:(BOOL)animated {
  43. [super viewWillDisappear:animated];
  44. [self.navigationController setNavigationBarHidden:NO animated:NO];
  45. [self stopTimer];
  46. self.mIngTimeLabel.text = @"";
  47. self.mIngNetWorkLabel.text = @"";
  48. }
  49. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  50. return UIInterfaceOrientationMaskPortrait;
  51. }
  52. - (void)dealloc {
  53. [[NSNotificationCenter defaultCenter] removeObserver:self];
  54. [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
  55. [[VideoManager shared] playVideoFinishRingtone];
  56. }
  57. - (void)initView {
  58. [EUtil setURLImage:self.mWaitHeadImage placeHolderName:@"avatar" imageURL:[[VideoManager shared] getTalkHeadImageURL] cornerRadius:self.mWaitHeadImage.frame.size.width/2];
  59. }
  60. #pragma mark - Incoming Actions
  61. - (IBAction)endCall:(id)sender {
  62. //通话中挂断; 自己发起时,对方未接通,自己挂断//
  63. [[VideoManager shared] videoEnd:NO isSendMessage:YES];
  64. }
  65. - (IBAction)endCallWhenIncoming:(id)sender {
  66. //对方发起时,自己拒接//
  67. [[VideoManager shared] videoEnd:YES isSendMessage:YES];
  68. }
  69. - (IBAction)videoAnswer:(id)sender {
  70. JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
  71. [[VideoManager shared].mJuphoonCall answer:activeCall video:true];
  72. }
  73. - (IBAction)voiceAnswer:(id)sender {
  74. JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
  75. [[VideoManager shared].mJuphoonCall answer:activeCall video:false];
  76. }
  77. #pragma mark - In Calling Actions
  78. - (IBAction)setCameraState:(id)sender {
  79. JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
  80. [[VideoManager shared].mJuphoonCall enableUploadVideoStream:activeCall];
  81. }
  82. - (IBAction)addNewCall:(id)sender {
  83. }
  84. - (IBAction)switchCamera:(id)sender {
  85. [[VideoManager shared].mJuphoonMediaDevice switchCamera];
  86. }
  87. - (IBAction)hold:(id)sender {
  88. JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
  89. [[VideoManager shared].mJuphoonCall hold:activeCall];
  90. }
  91. - (IBAction)mute:(id)sender {
  92. JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
  93. [[VideoManager shared].mJuphoonCall mute:activeCall];
  94. }
  95. - (IBAction)audioRecord:(id)sender {
  96. }
  97. - (IBAction)videoRecord:(id)sender {
  98. }
  99. - (IBAction)snapshot:(id)sender {
  100. }
  101. - (IBAction)speaker:(id)sender {
  102. [[VideoManager shared].mJuphoonMediaDevice enableSpeaker:![VideoManager shared].mJuphoonMediaDevice.isSpeakerOn];
  103. self.speakerBtn.selected = [VideoManager shared].mJuphoonMediaDevice.isSpeakerOn;
  104. }
  105. - (IBAction)callStatistics:(id)sender {
  106. }
  107. #pragma mark - 工具函数
  108. - (NSString *)getCallInfo:(JCCallItem*)item {
  109. switch (item.state) {
  110. case JCCallStateTalking:
  111. return [self formatTalkingTime:((long)[[NSDate date] timeIntervalSince1970] - item.talkingBeginTime)];
  112. default:
  113. return @"";
  114. }
  115. }
  116. - (NSString *)formatTalkingTime:(long)time {
  117. return [NSString stringWithFormat:@"%02ld:%02ld", time/60, time%60];
  118. }
  119. #pragma mark - Timer
  120. - (void)startTimer {
  121. if (_timer == nil) {
  122. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerProc) userInfo:nil repeats:YES];
  123. }
  124. }
  125. - (void)stopTimer {
  126. if (_timer) {
  127. if ([_timer isValid]) {
  128. [_timer invalidate];
  129. _timer = nil;
  130. }
  131. }
  132. }
  133. - (void)timerProc {
  134. self.mIngHeaderView.hidden = NO;
  135. JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
  136. self.mIngTimeLabel.text = [self getCallInfo:activeCall];
  137. self.mIngNetWorkLabel.text = [self getNetStatus:activeCall];
  138. if (activeCall.direction == JCCallDirectionOut) {
  139. }
  140. }
  141. @end