Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Example of Click to Call application for iOS

This example allows to place outgoing audio call with one button click using account specified in server config file

/usr/local/FlashphonerWebCallServer/conf/apps/click-to-call/accounts.xml

Image Added

Analyzing the code of the example

To analyze the code, let's take ClickToCall example version, which can be downloaded with build 2.5.2.

View class for the main view of the application: ViewController (header file ViewController.h; implementation file ViewController.m).

1. Import of API. code

Code Block
languagecpp
themeRDark
#import <FPWCSApi2/FPWCSApi2.h>


2. Connection to the server.

FPWCSApi2 createSession, FPWCSApi2Session connect code

FPWCSApi2SessionOptions object with the following parameters is passed to createSession() method

  • URL of WCS server
  • appKey of internal server-side application (clickToCallApp)
Code Block
languagecpp
themeRDark
- (FPWCSApi2Session *)connect {
    FPWCSApi2SessionOptions *options = [[FPWCSApi2SessionOptions alloc] init];
    options.urlServer = _connectUrl.text;
    options.appKey = @"clickToCallApp";
    NSError *error;
    session = [FPWCSApi2 createSession:options error:&error];
    ...    
    [session connect];
    return session;
}


3. Receiving the event confirming successful connection.

ViewController onConnected, ViewController call code

Onthis event, ViewController call method is called to make outgoing call.

Code Block
languagecpp
themeRDark
- (void)onConnected:(FPWCSApi2Session *)session {
    [self onHangup];
    [self call];
}


4. Outgoing call.

FPWCSApi2Session createCall, FPWCSApi2Call call code

The next options are passed to the createCall() method:

  • callee SIP username
  • call constraints: audio only
Code Block
languagecpp
themeRDark
- (FPWCSApi2Call *)call {
    FPWCSApi2CallOptions *options = [[FPWCSApi2CallOptions alloc] init];
    options.callee = _callee.input.text;
    options.localConstraints = [[FPWCSApi2MediaConstraints alloc] initWithAudio:YES video:NO];
    NSError *error;
    call = [session createCall:options error:&error];
    ...    
    [call call];
    return call;
}


5. Call hangup.

FPWCSApi2Call hangup code

Code Block
languagecpp
themeRDark
- (void)callButton:(UIButton *)button {
    [self changeViewState:button enabled:NO];
    if ([button.titleLabel.text isEqualToString:@"HANGUP"]) {
        if (call) {
            [call hangup];
        }
        ...
    }
}