Versions Compared

Key

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

...

Note

Desk Phone API features described in this section are deprecated and supported only on the following models: D40, d45, d50, d60, d62, d65, d70

This guide provides a basic overview for handling call events and performing various actions (e.g., hangup) on calls.

...

The digium.phone function provides a set of useful methods for working with calls. You can do things such as answer, hangup, and dial. Dial is used for starting a call, and the rest can be used to handle an existing call. The following example shows the process of observing a call, handling the response, and performing actions on the call itself. 

Code Block
//declare currentCall as a "global"
var currentCall = {};
digium.app.exitAfterBackground = false; //keep the app running in the background
  
// event listener for incoming calls
digium.event.observe({
    'eventName' : 'digium.phone.incoming_call',
    'callback'  : showCID
});
  
function showCID (evt) {
    digium.foreground(); //foreground the app when we get an incoming_call
    var callHandle = evt.eventData.callHandle; //this how the system identifies the call
    var role = evt.eventData.role; //caller or callee
  
    // parse out name from remoteInfo using a regex
    var name = (new RegExp(/^\"(.*)\"/).exec(evt.eventData.remoteInfo)) ? RegExp.$1 : "";
    // parse out number from remoteInfo using a regex
    var number = (new RegExp(/<sip:(\d+)/).exec(evt.eventData.remoteInfo)) ? RegExp.$1 : "";
  
    // this is declared outside of our function so it is "global" and accessible to other functions
    currentCall = {
        'role'          : role,
        'name'          : name,
        'number'        : number,
        'callHandle'    : callHandle
    }
  
    var cid = "Name: " + currentCall.name + " Number: " + currentCall.number;
    window.add(new Text(0, 20, window.w, Text.LINE_HEIGHT, cid));
  
    // set softkeys up
    setSoftkeys();
}
  
function setSoftkeys () {
    //softkey 1 answers
    window.setSoftkey(1, 'Answer', function () {
        digium.phone.answer({
            'callHandle'    : currentCall.callHandle,
            'handler'       : function (obj) {
                myDebug('App had a phone action (Answer)take place. State:' + obj.state);
            }
        });
    });
  
    //softkey 2 rejects
    window.setSoftkey(2, 'Reject', function () {
        digium.phone.reject({
            'callHandle'    : currentCall.callHandle,
            'handler'       : function (obj) {
                myDebug('App had a phone action (Reject)take place. State:' + obj.state);
            }
        });
    });
  
    //softkey 3 transfer
    window.setSoftkey(3, 'Transfer', function () {
        digium.phone.transfer({
            'callHandle'    : currentCall.callHandle,
            'handler'       : function (obj) {
                myDebug('App had a phone action (Transfer) take place. State:' + obj.state);
            }
        });
    });
}