Versions Compared

Key

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

Example of Android application for audio calls

On the screenshot below the example is displayed when a call is established.

In the input field 'WCS URL', 192.168.2.104 is the address of the WCS server.
In the input field 'Callee', 001 is the SIP username of the callee.

SIP connection is established/closed when Connect/Disconnect button is clicked.
Call is placed/terminated when Call/Hangup button is clicked, and put on hold/retrieve when Hold/Unhold button is clicked.

Image Added

Work with code of the example

To analyze the code, let's take class PhoneMinActivity.java of the phone-min example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.

1. Initialization of the API. line 71

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 Connect button is clicked. line 223

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


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

Callback functions for session events are added (line 224)

  • onConnected() - will be called when connection is successfully established
  • onRegistered() - will be called when SIP registration 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 onRegistered(final Connection connection) {
        .....
    }
    public void onDisconnection(final Connection connection) {
        .....
    }
});


Callback function for processing incoming call is added. (line 295)

Code Block
languagejs
themeRDark
session.on(new IncomingCallEvent() {
    public void onCall(final Call call) {
        .....
    }
});


Method Session.connect() is called to establish connection with WCS server. line 345
Connection object (line 338) with parameters required for establishing SIP connection is passed to the method.

Code Block
languagejs
themeRDark
session.connect(connection);


3. Outgoing call. line 387

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(callOptions);


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

Code Block
languagejs
themeRDark
call.on(callStatusEvent);


Сallback functions are defined in CallStatusEvent object. (line 93).

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

Code Block
languagejs
themeRDark
call.call();


4. Answering incoming call.

Incoming call is answered with method Call.answer().

Code Block
languagejs
themeRDark
call.answer();


5. Call hold.

The following methods are used to put call on hold and retrieve

6. Call hangup.

Method Call.hangup() is used to hang up call

Code Block
languagejs
themeRDark
call.hangup();


7. Disconnection. line 358

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

Code Block
languagejs
themeRDark
session.disconnect();