|
| 1 | +#import "AppAudioManager.h" |
1 | 2 | #import "CallAudioManager.h" |
2 | 3 | #import "PhoneManager.h" |
3 | 4 | #import "ThreadManager.h" |
@@ -52,22 +53,30 @@ -(void) initiateOutgoingCallToRemoteNumber:(PhoneNumber*)remoteNumber { |
52 | 53 |
|
53 | 54 | -(void) initiateOutgoingCallToRemoteNumber:(PhoneNumber*)remoteNumber withOptionallyKnownContact:(Contact*)contact { |
54 | 55 | require(remoteNumber != nil); |
55 | | - |
| 56 | + |
| 57 | + [[AppAudioManager sharedInstance] requestRequiredPermissionsIfNeededWithCompletion:^(BOOL granted) { |
| 58 | + if (granted) { |
| 59 | + [self callToRemoteNumber:remoteNumber withOptionallyKnownContact:contact]; |
| 60 | + } |
| 61 | + } incoming:NO]; |
| 62 | +} |
| 63 | + |
| 64 | +- (void)callToRemoteNumber:(PhoneNumber*)remoteNumber withOptionallyKnownContact:(Contact*)contact { |
56 | 65 | CallController* callController = [self cancelExistingCallAndInitNewCallWork:true |
57 | 66 | remote:remoteNumber |
58 | 67 | optionalContact:contact]; |
59 | 68 | [callController acceptCall]; // initiator implicitly accepts call |
60 | 69 | TOCCancelToken* lifetime = [callController untilCancelledToken]; |
61 | | - |
| 70 | + |
62 | 71 | TOCFuture* futureConnected = [CallConnectUtil asyncInitiateCallToRemoteNumber:remoteNumber |
63 | 72 | andCallController:callController]; |
64 | 73 |
|
65 | 74 | TOCFuture* futureCalling = [futureConnected thenTry:^id(CallConnectResult* connectResult) { |
66 | 75 | [callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString]; |
67 | 76 | CallAudioManager *cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket |
68 | | - andErrorHandler:callController.errorHandler |
69 | | - untilCancelled:lifetime]; |
70 | | - [callController setCallAudioManager:cam]; |
| 77 | + andErrorHandler:callController.errorHandler |
| 78 | + untilCancelled:lifetime]; |
| 79 | + [callController setCallAudioManager:cam]; |
71 | 80 | return nil; |
72 | 81 | }]; |
73 | 82 |
|
@@ -96,28 +105,32 @@ -(void) incomingCallWithSession:(ResponderSessionDescriptor*)session { |
96 | 105 | return; |
97 | 106 | } |
98 | 107 |
|
99 | | - Contact* callingContact = [Environment.getCurrent.contactsManager latestContactForPhoneNumber:session.initiatorNumber]; |
100 | | - CallController* callController = [self cancelExistingCallAndInitNewCallWork:false |
101 | | - remote:session.initiatorNumber |
102 | | - optionalContact:callingContact]; |
103 | | - |
104 | | - TOCCancelToken* lifetime = [callController untilCancelledToken]; |
105 | | - |
106 | | - TOCFuture* futureConnected = [CallConnectUtil asyncRespondToCallWithSessionDescriptor:session |
107 | | - andCallController:callController]; |
108 | | - |
109 | | - TOCFuture* futureStarted = [futureConnected thenTry:^id(CallConnectResult* connectResult) { |
110 | | - [callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString]; |
111 | | - CallAudioManager* cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket |
112 | | - andErrorHandler:callController.errorHandler |
113 | | - untilCancelled:lifetime]; |
114 | | - [callController setCallAudioManager:cam]; |
115 | | - return nil; |
116 | | - }]; |
117 | | - |
118 | | - [futureStarted catchDo:^(id error) { |
119 | | - callController.errorHandler(error, nil, true); |
120 | | - }]; |
| 108 | + [[AppAudioManager sharedInstance] requestRequiredPermissionsIfNeededWithCompletion:^(BOOL granted) { |
| 109 | + if (granted) { |
| 110 | + Contact* callingContact = [Environment.getCurrent.contactsManager latestContactForPhoneNumber:session.initiatorNumber]; |
| 111 | + CallController* callController = [self cancelExistingCallAndInitNewCallWork:false |
| 112 | + remote:session.initiatorNumber |
| 113 | + optionalContact:callingContact]; |
| 114 | + |
| 115 | + TOCCancelToken* lifetime = [callController untilCancelledToken]; |
| 116 | + |
| 117 | + TOCFuture* futureConnected = [CallConnectUtil asyncRespondToCallWithSessionDescriptor:session |
| 118 | + andCallController:callController]; |
| 119 | + |
| 120 | + TOCFuture* futureStarted = [futureConnected thenTry:^id(CallConnectResult* connectResult) { |
| 121 | + [callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString]; |
| 122 | + CallAudioManager* cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket |
| 123 | + andErrorHandler:callController.errorHandler |
| 124 | + untilCancelled:lifetime]; |
| 125 | + [callController setCallAudioManager:cam]; |
| 126 | + return nil; |
| 127 | + }]; |
| 128 | + |
| 129 | + [futureStarted catchDo:^(id error) { |
| 130 | + callController.errorHandler(error, nil, true); |
| 131 | + }]; |
| 132 | + } |
| 133 | + } incoming:YES]; |
121 | 134 | } |
122 | 135 | -(CallController*) curCallController { |
123 | 136 | return currentCallControllerObservable.currentValue; |
|
0 commit comments