Picture of nickname
Registered 3 years 37 days
nickname Sunday, 12 June 2022, 10:59 PM
Questionable behavior of phone / phoneinfo api
Dear innovaphone forum,

We have noticed a strange behavior of what signals are sent by the phone / phoneinfo api when having more than one phone provider. We are currently using both apis, because com.innovaphone.phone has no "disconnected" signal.

Code:

var phoneinfoApi;
var phoneApi;

if(!phoneinfoApi) phoneinfoApi = start.provideApi("com.innovaphone.phoneinfo");
if(!phoneApi) phoneApi = start.consumeApi("com.innovaphone.phone");

phoneinfoApi.onmessage.attach(function (sender, obj) {
switch (obj.msg.mt) {
case "CallAdded":
break;
case "CallUpdated":
break;
case "CallRemoved":
that.add(new innovaphone.ui1.Div(null, "Call ended"));
break;
}
});

phoneApi.onupdate.attach(function onPhoneApiUpdate(arg0) {
const providers = arg0.providers;
if(providers) providers.forEach(function (provider) {
const calls = arg0.model[provider].model.calls;
if(calls) calls.forEach(function (call) {
if (call.state == "Alerting") {
that.add(new innovaphone.ui1.Div(null, "Call incoming from provider: " + arg0.model[provider].title));
}
});
});
});

These are the messages we get:
Call incoming from provider: Softphone0
Call incoming from provider: Softphone0
Call incoming from provider: Softphone1
Call ended
Call ended
Call incoming from provider: Softphone1

After a call gets removed, the other provider pushes an alert at the ending.
How can we avoid this problem?
How can we identify a specific call, because every call currently has the id "-1"?
Is there a possibility to only use one of those apis instead of combindig them?




Picture of Daniel 450
Registered 14 years 174 days
Daniel 450 Sunday, 3 July 2022, 08:17 PM
Re: Questionable behavior of phone / phoneinfo api
This info we need to could launch three apps shown on last thursday.
Andreas Fink
Moderator Registered 13 years 52 days
Andreas Fink (innovaphone) Thursday, 7 July 2022, 11:52 AM in response to nickname
Re: Questionable behavior of phone / phoneinfo api
Hello Nick,

I'm sorry for long delay.

The behaviour described corresponds to the nature of the com.innovaphone.phone interface, which always represents the current reported state of the apis.

In the case of two phone providers, it can happen that one provider reports a change in which the alerting call is dropped, but the second provider has not yet reported a change and the call is listed as alerting here.

Since the ApiUpdate message carries the models of all Apis, it can always happen that a state is reported in which one provider has no more calls, but the other still has a alerting one.

Shortly after this, an update will arrive with no calls at all at com.innovaphone.phone providers. This event is not handled in your application, cause the statement inside of " if (calls) ..." is always true, even if calls is an empty array, but forEach do nothing in case calls array has no entries. In your case this is an important state change - that should be handled.

If you add following code below the " if (calls) ..." statement, you will handle the case with empty call list:

if (calls.length === 0) {
msg = "No calls at " + arg0.model[provider].title;
that.add(new innovaphone.ui1.Div(null, msg));
console.warn(msg);
}

Indeed the com.innovaphone.phoneinfo API is a better way to get messages about added or removed calls.

With com.innovaphone.phone API you have to store seen calls and update the call list based on infos delivered by the com.innnovaphone.phone API.

I hope my explanation is more or less clear. If not, feel free to contact me.

Best Regards
Andreas Fink
Picture of nickname
Registered 3 years 37 days
nickname Thursday, 7 July 2022, 02:40 PM
Re: Questionable behavior of phone / phoneinfo api
Dear Andreas Fink,

Thanks for the explanation - it helped me a lot to understand the Api better. I will try it out later.


← You can define your color theme preference here