Click to Call example

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

Code of the example

The path to the source code of the example on WCS server is:

/usr/local/FlashphonerWebCallServer/client/examples/demo/sip/click-to-call

click-to-call.html - page of the example
click-to-call.js - script providing functionality for the example

This example can be tested using the following address:

https://host:8888/client/examples/demo/sip/click-to-call/click-to-call.html

Here host is the address of the WCS server.

Work with code of the example

To analyze the code, let's take the version of file click-to-call.js with hash 26fc5afa246baea80867fa011305da811edab1f0, which is available here and can be downloaded with corresponding build 0.5.5.1894.

1. Initialization of the API. line 11

API is initialized after loading the page. For Flash support, the path to SWF file is passed to the init() method.

Flashphoner.init({flashMediaProviderSwfLocation: '../../../../media-provider.swf'});


2. Connection to server. line 41

Connection to server is established when Call button is clicked.

Flashphoner.createSession(connectionOptions).on(SESSION_STATUS.REGISTERED, function(session){
    setStatus("Session", SESSION_STATUS.REGISTERED);
    //session connected, place call
    call(session);
}).on(SESSION_STATUS.DISCONNECTED, function(){
    setStatus("Session", SESSION_STATUS.DISCONNECTED);
    onHangup();
}).on(SESSION_STATUS.FAILED, function(){
    setStatus("Session", SESSION_STATUS.FAILED);
    onHangup();
});


Session is created with method createSession(). Callback function, which will be called to place outgoing call in case of successfully established connection (status SESSION_STATUS.REGISTERED), is added.

Object with connection options is passed to the method when session is created

Parameters for SIP connection are taken from config accounts.xml.

3. Outgoing call. line 62

New call is created with method session.createCall().
The following parameters are passed when call is created

var constraints = {
    audio: true,
    video: false
};


var outCall = session.createCall({
    callee: $("#callee").val(),
    visibleName: "Click To Call",
    localVideoDisplay: localDisplay,
    remoteVideoDisplay: remoteDisplay,
    constraints: constraints,
    receiveAudio: true,
    receiveVideo: false
}).on(CALL_STATUS.RING, function(){
    setStatus("Call", CALL_STATUS.RING);
}).on(CALL_STATUS.ESTABLISHED, function(){
    setStatus("Call", CALL_STATUS.ESTABLISHED);
}).on(CALL_STATUS.FINISH, function(){
    setStatus("Call", CALL_STATUS.FINISH);
    onHangup();
});


When call is created, callback functions for events CALL_STATUS.RING, CALL_STATUS.ESTABLISHED, CALL_STATUS.FINISH are added to make appropriate changes in controls of the interface.

Outgoing call is placed with method call(). line 79

outCall.call();


4. Call hangup. line 83

Method hangup() is used to hang up call.

outCall.hangup();