Monitoring presence, getting event error.

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

Moderators: jwitt, sruffell, malcolmd, Moderator

Monitoring presence, getting event error.

Postby jfulfordtdn » Thu Dec 18, 2014 3:13 pm

I'm using the following code:
Code: Select all
var app = require('app');
var util = require('util');
app.init();

var presenceReporter = { };
presenceReporter.bindListeners = function() {
      digium.event.observe({
         'eventName' : 'digium.phone.contact_presence',
         'callback' : this.reportPresence()
      });
};

presenceReporter.reportPresence = function(params) {
      //var msg = params.eventData;
      util.debug("Presence Changed: ");
      util.debug(JSON.stringify(params));
};
presenceReporter.init = function () {
   digium.app.exitAfterBackground = false;
   this.bindListeners();
};
presenceReporter.init();




This code works the first time it starts, then every other time the event is fired, I get the following error:
error executing handler for event digium.phone.contact_presence: TypeError: Property '0' of object is not a function

I'm a C# developer so JS is new to me.
jfulfordtdn
Newsterisk
 
Posts: 12
Joined: Wed Dec 10, 2014 9:13 am

Re: Monitoring presence, getting event error.

Postby sruffell » Mon Dec 22, 2014 12:42 pm

jfulfordtdn, At first glance, this looks OK to me.

I'll set it up today and try it out and get back to you.
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm

Re: Monitoring presence, getting event error.

Postby sruffell » Tue Dec 23, 2014 1:01 pm

Now I feel silly that I had to set this up to see the error.

You need to make sure 'callback' is the function object, not the result from calling the function.

In your code, change the following block:

Code: Select all
var presenceReporter = { };
presenceReporter.bindListeners = function() {
      digium.event.observe({
         'eventName' : 'digium.phone.contact_presence',
         'callback' : this.reportPresence()
      });
};


to this:

Code: Select all
var presenceReporter = { };
presenceReporter.bindListeners = function() {
      digium.event.observe({
         'eventName' : 'digium.phone.contact_presence',
         'callback' : this.reportPresence
      });
};
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm


Return to Digium Phone API

Who is online

Users browsing this forum: No registered users and 1 guest