Versions Compared

Key

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

Example of Click to Call application for Android

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

On the screenshot below the example is displayed after terminating a call and closing connection to server
Input fields required for connecting to WCS server and placing a call

  • 'WCS URL', where 192.168.2.104 is the address of the WCS server
  • 'Callee', where 001 is the SIP username of the callee

Image Added

Work with code of the example

To analyze the code, let's take class ClickToCallActivity.java of the click-to-call example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.

1. Initialization of the API. line 56

Code Block
languagejs
themeRDark
Flashphoner.init(this);


For initialization, object Сontext is passed to the init() method.

2. Connection to server.

Session for connection to server is created when Call button is clicked. line 75

Code Block
languagejs
themeRDark
session = Flashphoner.createSession(sessionOptions);


Session is created with method createSession(), to which object SessionOptions (line 74) with URL of WCS server is passed.

Callback functions for session events are added (line 76)

  • onConnected() - will be called when connection is successfully established
  • onDisconnection() - will be called when connection is closed
Code Block
languagejs
themeRDark
session.on(new SessionEvent() {
    public void onConnected(final Connection connection) {
        .....
    }
    public void onDisconnection(final Connection connection) {
        .....
    }
});


Method Session.connect() is called to establish connection with WCS server.line 253
Connection object (line 248) with appKey of internal server-side application 'clickToCallApp' is passed to the method.

Code Block
languagejs
themeRDark
session.connect(connection);


3. Outgoing call. line 99

New call is created with method Session.createCall().
CallOptions object with callee SIP username is passed to the method.

Code Block
languagejs
themeRDark
call = session.createCall(streamOptions);


Callback functions, which make appropriate changes in controls of the interface, are added for processing call statuses. (line 100).

Code Block
languagejs
themeRDark
call.on(new CallStatusEvent() {
    public void onTrying(final Call call) {
        .....
    }
    public void onBusy(final Call call) {
        .....
    }
    public void onFailed(final Call call) {
        .....
    }
    public void onRing(final Call call) {
        .....
    }
    public void onHold(final Call call) {
        .....
    }
    public void onEstablished(final Call call) {
        .....
    }
    public void onFinished(final Call call) {
        .....
    }
});


Outgoing call is placed with method Call.call(). line 211

Code Block
languagejs
themeRDark
call.call();


4. Disconnection. line 261

Method Session.disconnect() is called to close connection to the server.

Code Block
languagejs
themeRDark
session.disconnect();