zeined / idoubs

Automatically exported from code.google.com/p/idoubs
0 stars 0 forks source link

SIP call will be override by regular call #58

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Set up the SIP call
2. Be called on your real phone

What is the expected output? What do you see instead?
The sip call stays alive but the person you are calling with isn't hearing 
anything anymore.

What is the solution to this problem?

The modification gives the user to answer the incoming phone call by pausing 
the SIP call.
If the server is installed correctly the user gets a very nice soothing music 
song :-). 
At first we need to be able to intercept the phone call by looking at the call 
state of the iPhone.

So we need to add a new framework (Frameworks -> Add -> Existing Frameworks) 
CoreTelephony.framework to our project.
Now we open up the idoubs2AppDelegate.mm file en scroll to the "#import" 
section.
Here we add these three lines:

 #import <CoreTelephony/CTCallCenter.h>
 #import <CoreTelephony/CTCall.h>
 #import "idoubs2Constants.h"

We go to the startup function (didFinishLaunchingWithOptions) and add this to 
the top of the function:

 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
    //Setup callCenter
    CTCallCenter callCenter = [[CTCallCenter alloc] init];
    callCenter.callEventHandler=^(CTCall *call) {
        //If iPhone has succesfully connected the phone call
        if(call.callState == CTCallStateConnected){
            NSLog(@"Incoming phone call"); //To test if it really works
            if([idoubs2AppDelegate sharedInstance].audioCallController.audioSession){ //Check if client has an active audioSession
                //Audiosession available
                if(![idoubs2AppDelegate sharedInstance].audioCallController.paused){
                    [idoubs2AppDelegate sharedInstance].audioCallController.paused = TRUE; //Set the paused state
                    [[idoubs2AppDelegate sharedInstance].audioCallController.audioSession toggleHoldResume];
                    //Set the "pause" button to blue gradient
                    [[idoubs2AppDelegate sharedInstance].audioCallController 
                                applyGradienWithColors: kColorsBlue
                                        forView:[idoubs2AppDelegate sharedInstance].audioCallController.buttonMute
                                        withBorder:NO];
                }
            }
        }
    };
 #endif

We now have added the eventHandler to the application so if there is an 
incoming phone call the application automatically holds the conversation.
But we also want the client to recognize the ending of a call and resume our 
conversation.
We can do that by adding the following code to our function 
(applicationWillEnterForeground)

//If converstaion was put on hold resume
    if([idoubs2AppDelegate sharedInstance].audioCallController.paused){
        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Conversation hold"
                                message:@"The conversation is put on hold and will automatically resume."
                                delegate:self 
                             cancelButtonTitle:@"Ok"
                               otherButtonTitles:nil] autorelease];
        [alert setTag:1]; //If we have other UIAlertViewDelegate's we can filter them by TagID
        [alert show];
    }

Now we only need to add an eventHandler to the "Ok" button we have on the 
UIAlertView, like this:
Go to your idoubs2AppDelegate.h file and look up the @interface rule after your 
class typecast you'll see two brackets (<UIApplicationDelegate, etc.>).
Add to these brackets: UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView 
didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if ([alertView tag] == 1) {
        if (buttonIndex == 0) {
            if([idoubs2AppDelegate sharedInstance].audioCallController.audioSession){
                [idoubs2AppDelegate sharedInstance].audioCallController.paused = FALSE; //Set paused state
                [[idoubs2AppDelegate sharedInstance].audioCallController.audioSession toggleHoldResume];
                //Set the gradient of the "pause" button to natural
                [[idoubs2AppDelegate sharedInstance].audioCallController 
                                applyGradienWithColors: kColorsLightBlack
                                        forView:[idoubs2AppDelegate sharedInstance].audioCallController.buttonMute
                                        withBorder:NO];
            }
        }
    }
}

Conclusion:
I've been searching all over the internet and after a couple of tries and some 
debugging I finally got it working. 
So I thought it would be nice to share it with you people.
The Doubango framework has done a lot for me so I thought it would be nice to 
do something back too :-).
I hope it'll be very useful to all of you and any comments are welcome.

Regards,

Leon Keijzer

P.S. 
I know this is the issue part but Google Code wouldn't let me write a Wiki so I 
thought this would be a nice approach ^^

Original issue reported on code.google.com by nightfox...@gmail.com on 20 Jul 2011 at 7:01

GoogleCodeExporter commented 8 years ago
Thanks for your contribution.
We will add it to the repository after review.

Original comment by boss...@yahoo.fr on 23 Jul 2011 at 2:39