Can App Receive Phone Status Event

Community based support for the Digium Phone Application Programming Interface (API).

Moderators: jwitt, sruffell, malcolmd, Moderator

Can App Receive Phone Status Event

Postby terrywhipple11 » Mon Apr 22, 2013 6:53 pm

Is it possibe for an app to receive an event when the phones status changes. For example when the status changes to Do not disturb.

We have a service center that would like to track the time available on the phone, i would like to create an app on the phone for the users to see each day how long they were on Do not disturb and how long they were available to take calls.
terrywhipple11
Newsterisk
 
Posts: 2
Joined: Mon Apr 22, 2013 6:46 pm

Re: Can App Receive Phone Status Event

Postby sruffell » Tue Apr 23, 2013 8:51 am

Yes. A phone subscribes to it's own status updates. For example if you ran the following on your phone:

Code: Select all
var app = require('app');
app.init();
var util = require('util');

// Allows this application to run in the background.
digium.app.exitAfterBackground = false;

var presenceChanged = function(param) {
    util.debug("Presence Changed: ");
    util.debug(JSON.stringify(param));
};

digium.event.observe({
    'eventName'     : 'digium.phone.contact_presence',
    'callback'      : presenceChanged
});

util.debug("Presence monitored");


You could get output on the debug console when switching to DND and back to available like:
Code: Select all
Presence monitored
Presence Changed:
{"eventName":"digium.phone.contact_presence","eventData":{"url":"sip:auto_hint_6003@10.19.135.2:5060","onlineStatus":"online","note":"Ready","subscriptionState":"ACTIVE","type":"dnd","subtype":"","text":""},"messageId":"ae501522"}
Presence Changed:
{"eventName":"digium.phone.contact_presence","eventData":{"url":"sip:auto_hint_6003@10.19.135.2:5060","onlineStatus":"online","note":"Ready","subscriptionState":"ACTIVE","type":"available","subtype":"","text":""},"messageId":"ae501538"}


You can see that param.eventData.type changed to 'dnd' and back to 'available'. You would need to parse the url in order to know it was the users phone that changed state and not another phone.
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm

Re: Can App Receive Phone Status Event

Postby terrywhipple11 » Tue Apr 23, 2013 1:33 pm

thank you for your quick reply, i am going to try it now
terrywhipple11
Newsterisk
 
Posts: 2
Joined: Mon Apr 22, 2013 6:46 pm


Return to Digium Phone API

Who is online

Users browsing this forum: No registered users and 1 guest