Page 1 of 1

Can App Receive Phone Status Event

PostPosted: Mon Apr 22, 2013 6:53 pm
by terrywhipple11
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.

Re: Can App Receive Phone Status Event

PostPosted: Tue Apr 23, 2013 8:51 am
by sruffell
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.

Re: Can App Receive Phone Status Event

PostPosted: Tue Apr 23, 2013 1:33 pm
by terrywhipple11
thank you for your quick reply, i am going to try it now