Summary for the followers of this thread
When issue was reported, app client side javascript looked like this,
var client;
$(document).ready( function() {
app.initialized()
.then(function(_client) {
client = _client; // FOCUS SECTION START
client.events.on("app.activated",
function() {
// LOGIC
});
client.events.on("calling", handlec2cevent);
function handlec2cevent(event){
console.log("c2c triggered", event);
}
// FOCUS SECTION END
});
});
function openModal() {
client.interface.trigger('showModal', {title: 'Add Integration Action', template: 'modal.html'});
}
function closePopup() {
client.instance.close();
}
- Looking at the above code, it is clear that as soon as app is initialized there are two event listeners attached to it. One is on
"app.activated"and other one is"calling". - (Assumption) This meant that when product prepares itself to open up the api, by then app is initialized and the call back is registered but not fired.
- As soon as app is activated, and User clicks on the phone number within the page, the callback
handlec2ceventis registered and fired. Since the call stack already has the previous invocation also in the stack, led to call back method executing twice.
Fix
Our fix was simple, We moved the "calling" event listener under "app.activated" to avoid this.
var client;
$(document).ready(function () {
app.initialized().then(function (_client) {
client = _client;
client.events.on("app.activated", function () {
client.events.on("calling", handlec2cevent);
});
});
});
function openModal() {
client.interface.trigger("showModal", {
title: "Add Integration Action",
template: "modal.html",
});
}
function closePopup() {
client.instance.close();
}
function handlec2cevent(event) {
console.log("c2c triggered", event);
}