Page 1 of 1

Monitoring presence, getting event error.

PostPosted: Thu Dec 18, 2014 3:13 pm
by jfulfordtdn
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.

Re: Monitoring presence, getting event error.

PostPosted: Mon Dec 22, 2014 12:42 pm
by sruffell
jfulfordtdn, At first glance, this looks OK to me.

I'll set it up today and try it out and get back to you.

Re: Monitoring presence, getting event error.

PostPosted: Tue Dec 23, 2014 1:01 pm
by sruffell
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
      });
};