Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/CallKit-bob' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Voorneveld committed Nov 21, 2016
2 parents 8574bb7 + e628d6e commit b782c8d
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 223 deletions.
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 0f7b04fb045caf39ed7c2486524959b2d2be90e8

COCOAPODS: 1.1.1
COCOAPODS: 1.2.0.beta.1
329 changes: 167 additions & 162 deletions Example/VialerSIPLib/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

78 changes: 41 additions & 37 deletions Example/VialerSIPLib/VSLIncomingCallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,53 +63,57 @@ class VSLIncomingCallViewController: UIViewController {
// MARK: - Actions

@IBAction func declineButtonPressed(_ sender: UIButton) {
try! call?.hangup()
performSegue(withIdentifier: Configuration.Segues.UnwindToMainViewController, sender: nil)
guard let call = call else { return }
callManager.end(call) { error in
if error != nil {
DDLogWrapper.logError("cannot decline call: \(error)")
} else {
self.performSegue(withIdentifier: Configuration.Segues.UnwindToMainViewController, sender: nil)
}
}
}

@IBAction func acceptButtonPressed(_ sender: UIButton) {
if let call = call, call.callState == .incoming {

callManager.answer(call) { error in
if error != nil {
DDLogWrapper.logError("error answering call: \(error)")
} else {
self.performSegue(withIdentifier: Configuration.Segues.ShowCall, sender: nil)
}
guard let call = call, call.callState == .incoming else { return }
callManager.answer(call) { error in
if error != nil {
DDLogWrapper.logError("error answering call: \(error)")
} else {
self.performSegue(withIdentifier: Configuration.Segues.ShowCall, sender: nil)
}
}
}

fileprivate func updateUI() {
if let call = call {
numberLabel?.text = call.callerNumber
switch call.callState {
case .incoming:
statusLabel?.text = "Incoming call"
case .connecting:
statusLabel?.text = "Connecting"
case .confirmed:
statusLabel?.text = "Connected"
case .disconnected:
statusLabel?.text = "Disconnected"
case .null: fallthrough
case .calling: fallthrough
case .early:
statusLabel?.text = "Invalid"
}

if call.callState == .incoming {
declineButton?.isEnabled = true
acceptButton?.isEnabled = true
ringtone.start()
} else {
ringtone.stop()
declineButton?.isEnabled = false
acceptButton?.isEnabled = false
}
} else {
guard let call = call else {
numberLabel?.text = ""
statusLabel?.text = ""
return
}
numberLabel?.text = call.callerNumber
switch call.callState {
case .incoming:
statusLabel?.text = "Incoming call"
case .connecting:
statusLabel?.text = "Connecting"
case .confirmed:
statusLabel?.text = "Connected"
case .disconnected:
statusLabel?.text = "Disconnected"
case .null: fallthrough
case .calling: fallthrough
case .early:
statusLabel?.text = "Invalid"
}

if call.callState == .incoming {
declineButton?.isEnabled = true
acceptButton?.isEnabled = true
ringtone.start()
} else {
ringtone.stop()
declineButton?.isEnabled = false
acceptButton?.isEnabled = false
}
}

Expand Down
28 changes: 14 additions & 14 deletions Example/VialerSIPLib/VSLSecondCallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ class VSLSecondCallViewController: VSLCallViewController {
}

override func endCall() {
if let call = activeCall, call.callState != .null {
do {
try call.hangup()
guard let call = activeCall, call.callState != .null else { return }

callManager.end(call) { error in
if error != nil {
DDLogWrapper.logError("Could not end call: \(error)")
} else {
self.performSegue(withIdentifier: Configuration.Segues.UnwindToFirstCall, sender: nil)
} catch let error {
DDLogWrapper.logError("Couldn't hangup call: \(error)")
}
}
}

@IBAction func cancelButtonPressed(_ sender: UIBarButtonItem) {

// Hangup active Call if it is not disconnected.
if let call = activeCall, call.callState != .disconnected {
do {
try call.hangup()
guard let call = activeCall, call.callState != .disconnected else {
self.performSegue(withIdentifier: Configuration.Segues.UnwindToFirstCall, sender: nil)
return
}
callManager.end(call) { error in
if error != nil {
DDLogWrapper.logError("Could not end call: \(error)")
} else {
self.performSegue(withIdentifier: Configuration.Segues.UnwindToFirstCall, sender: nil)
} catch let error {
DDLogWrapper.logError("Couldn't hangup call: \(error)")
}
} else {
self.performSegue(withIdentifier: Configuration.Segues.UnwindToFirstCall, sender: nil)
}
}

Expand Down
12 changes: 9 additions & 3 deletions Example/VialerSIPLib/VSLTransferCallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ private var myContext = 0

@IBAction override func callButtonPressed(_ sender: UIButton) {
UIDevice.current.isProximityMonitoringEnabled = true
if let number = numberToDialLabel.text, number != "" {
currentCall?.account!.callNumber(number) { (call, error) in
guard let number = numberToDialLabel.text, number != "" else { return }

callManager.startCall(toNumber: number, for: currentCall!.account! ) { (call, error) in
if error != nil {
DDLogWrapper.logError("Could not start second call: \(error)")
} else {
self.newCall = call
self.performSegue(withIdentifier: Configuration.Segues.SecondCallActive, sender: nil)
DispatchQueue.main.async {
self.performSegue(withIdentifier: Configuration.Segues.SecondCallActive, sender: nil)
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions Pod/Classes/CallKitProviderDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ - (CXProviderConfiguration *)providerConfiguration {
CXProviderConfiguration *providerConfiguration = [[CXProviderConfiguration alloc]
initWithLocalizedName:NSLocalizedString(appname, nil)];

providerConfiguration.maximumCallGroups = 1;
providerConfiguration.maximumCallsPerCallGroup = 2;
providerConfiguration.maximumCallGroups = 2;
providerConfiguration.maximumCallsPerCallGroup = 1;
providerConfiguration.supportsVideo = false;

providerConfiguration.supportedHandleTypes = [NSSet setWithObject:[NSNumber numberWithInt:CXHandleTypePhoneNumber]];
Expand Down Expand Up @@ -188,6 +188,9 @@ - (void)provider:(CXProvider *)provider performSetHeldCallAction:(CXSetHeldCallA
DDLogError(@"Could not hold call(%@). Error: %@", call.uuid.UUIDString, holdError);
[action fail];
} else {
if (call.onHold) {
[self.callManager.audioController deactivateAudioSession];
}
[action fulfill];
}
}
Expand Down
3 changes: 3 additions & 0 deletions Pod/Classes/VSLAudioController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ - (void)checkCurrentThreadIsRegisteredWithPJSUA {
}

- (void)activateAudioSession {
DDLogDebug(@"Activating audiosession");
[self checkCurrentThreadIsRegisteredWithPJSUA];
pjsua_set_no_snd_dev();
pj_status_t status;
status = pjsua_set_snd_dev(PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV);
if (status != PJ_SUCCESS) {
Expand All @@ -63,6 +65,7 @@ - (void)activateAudioSession {
}

- (void)deactivateAudioSession {
DDLogDebug(@"Deactivating audiosession");
[self checkCurrentThreadIsRegisteredWithPJSUA];
pjsua_set_no_snd_dev();
}
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/VSLCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ - (void)mediaStateChanged:(pjsua_call_info)callInfo {
DDLogVerbose(@"Media State Changed from %@ to %@", VSLMediaStateString(self.mediaState), VSLMediaStateString((VSLMediaState)mediaState));
self.mediaState = (VSLMediaState)mediaState;

if (_mediaState == PJSUA_CALL_MEDIA_ACTIVE || _mediaState == PJSUA_CALL_MEDIA_REMOTE_HOLD) {
if (self.mediaState == VSLMediaStateActive || self.mediaState == VSLMediaStateRemoteHold) {
[self.ringback stop];
pjsua_conf_connect(callInfo.conf_slot, 0);
pjsua_conf_connect(0, callInfo.conf_slot);
Expand Down Expand Up @@ -450,7 +450,7 @@ - (BOOL)toggleHold:(NSError **)error {
*error = [NSError errorWithDomain:VSLCallErrorDomain code:VSLCallErrorCannotToggleHold userInfo:userInfo];
}
return NO;
DDLogError(@"Error toggle muting microphone in call %@", self.uuid.UUIDString);
DDLogError(@"Error toggle holding in call %@", self.uuid.UUIDString);
}
return YES;
}
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/VSLCallManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

#import "VSLCallManager.h"

@import CallKit;
#import "Constants.h"
#import <CocoaLumberJack/CocoaLumberjack.h>
Expand Down Expand Up @@ -147,10 +148,9 @@ - (void)toggleHoldForCall:(VSLCall *)call completion:(void (^)(NSError * _Nullab
if ([VialerSIPLib callKitAvailable]) {
CXAction *toggleHoldAction = [[CXSetHeldCallAction alloc] initWithCallUUID:call.uuid onHold:!call.onHold];
[self requestCallKitAction:toggleHoldAction completion:completion];

} else {
NSError *holdError;
[call toggleMute:&holdError];
[call toggleHold:&holdError];
if (holdError) {
DDLogError(@"Could not hold call (%@). Error: %@", call.uuid.UUIDString, holdError);
completion(holdError);
Expand Down

0 comments on commit b782c8d

Please sign in to comment.