Picture of Felix 2874
Registered 8 years 177 days
Felix 2874 Thursday, 18 April 2024, 03:53 PM
StartCall without opening die PhoneApp?
Hi,

I start a call like described in
https://sdk.innovaphone.com/14r1/web1/com.innovaphone.phone/com.innovaphone.phone.htm
via
phoneApi.send({ mt: "StartCall", num: "88" });
this starts the call indeed, but also starts the phone app in the foreground.

Is there a way to just start the call without bringing the phoneapp in the foreground?
Picture of Peter Stock (innovaphone)
Moderator Registered 225 days 1 hour
Peter Stock (innovaphone) Monday, 22 April 2024, 11:05 PM
Re: StartCall without opening die PhoneApp?
Hi Felix,

as mentioned in the SDK Developer Meeting, i would use the RccApi for this.
With this, you can choose a device of a User and do something like "CTI"...

I also told you, that you will get an example for this, so here it is.

You could copy this into your clientside-app.js "vendor-appname.js", after the functions "app_connected" and "app_message".

This example is not about perfect code, but about you being able to understand how it works ;). I hope you get on with it.

The App Objekt should give you a dropdownlist of your devices. If you change the drowdown, the RccApi will be initialized with the given devices.

You have to Grant Access to the "RCC" - API on your App Object.

Also you should have a look to:

Maybe you can extend the code with choosing a device and setup a call ;)

Best Regards,

Peter


// Array for Devices of User - we fill it later
var hwdevices = [];
// Function for getting the right URL to PBX - For RccApi we need a AppSocket to PBX.
function convertToWebSocket(url) {
// Check if connections was established over http or https
if (url.startsWith("http://")) {
//Build Websocketurl of PBX with ws://
return "ws://" + url.slice(7, url.indexOf("/", 7)) + "/PBX0/APPS/websocket";
} else if (url.startsWith("https://")) {
//Build Websocketurl of PBX with wss://
return "wss://" + url.slice(8, url.indexOf("/", 8)) + "/PBX0/APPS/websocket";
} else {
// Return Websocket URL for AppWebsocket
return url;
}
}

// Genereate WebsocketURL from PBX by start-Variable
var pbxurl = convertToWebSocket(start.clientUrl);
//console.log(pbxurl);

// Create innovaphone AppWebSocket to PBX
var pbxconn = new innovaphone.appwebsocket.Connection(pbxurl, start.name, null, null);
pbxconn.checkBuild = false;
pbxconn.onconnected = pbxconn_connected;
pbxconn.onmessage = pbxconn_message;
var pbxUserCn = "";

// If we are connected to PBX, we can send UserInitialize. (RccApi has to be activated on AppObjekt.)
function pbxconn_connected() {
console.log("PBX Connected - " + pbxconn.logindata.info.cn);
// Just to show from what Object you could get the CN of af User......
pbxUserCn = pbxconn.logindata.info.cn;
//Connection is up, we create a Dropdown for Devices of the User.
createDropdown();
}

function pbxconn_message(obj) {
// If everything is okay, we will get UserInitializeResult. Now you can use RccApi
if (obj.mt == "UserInitializeResult"){
console.log ("RccApi Initialized - Have fun !!!");
}
}


// We need the phoneApi to get information about what devices are availabe
var phoneApi = start.consumeApi("com.innovaphone.phone");

// Add an Eventlistener for incoming APP Messages
window.addEventListener("message", onwindowmessage);

function onwindowmessage(msg) {
const obj = JSON.parse(msg.data);
if (obj.mt === "ApiUpdate") {
//console.log(obj);

// Get Devices of User from phoneApi.model
// console.log(phoneApi.model);

// Loop through each device
for (const deviceId in phoneApi.model) {
// Check if the device is its own property and not inherited
if (phoneApi.model.hasOwnProperty(deviceId)) {
// Access the current device
const device = phoneApi.model[deviceId];
// Log the title of the device
console.log("Devicename:", device.title);
// Log the model of the device
console.log("HardwareId:", deviceId.substring(4));
console.log("------------------------------");
hwdevices.push([device.title, deviceId.substring(4)]);
}
}
}
}

function createDropdown() {
var select = document.createElement('select');
select.id = 'deviceDropdown';

// Loop through the hwdevices array
for (var i = 0; i < hwdevices.length; i++) {
var option = document.createElement('option');
option.value = hwdevices[i][1]; // HardwareId as the value of the option
option.textContent = hwdevices[i][0]; // Devicename as the text of the option
select.appendChild(option);
}

// Add event listener for when an option is selected
select.addEventListener('change', function() {
var selectedValue = this.value; // Get the selected value
// Call your function here with the selected value
GetRccApi(selectedValue);
});

// Add the dropdown menu to the body
document.body.appendChild(select);
}

// Function to be called when an option is selected
function GetRccApi(selectedValue) {
console.log('Selected value:', selectedValue);
pbxconn.send({"mt":"UserInitialize","api":"RCC","xfer":true,"cn":pbxUserCn,"hw":selectedValue,"disc":true})
}
Picture of Felix 2874
Registered 8 years 177 days
Felix 2874 Tuesday, 23 April 2024, 08:52 AM
1 of 1 users consider this post helpful
Re: StartCall without opening die PhoneApp?
Hi,

thanks for your answer.
Yes that helped me a lot.
I now got an idea how I can do calls without the phone API.

Thanks.
Picture of Peter Stock (innovaphone)
Moderator Registered 225 days 1 hour
Peter Stock (innovaphone) Tuesday, 23 April 2024, 09:32 AM
Re: StartCall without opening die PhoneApp?
Hi,

as you can see, the phone API is used, but only for getting the Devices of a User.

I could be that you have to do some asynchronous Functions in your code to be save, that all information and variable are loaded. In this example it works, but maybe in future it makes sense to build dependencies while loading the app.

Best Regards,

Peter
Picture of Felix 2874
Registered 8 years 177 days
Felix 2874 Wednesday, 24 April 2024, 09:58 AM in response to Peter Stock (innovaphone)
Re: StartCall without opening die PhoneApp?
One more question here.
I discovered that I can use the PbxApi here as well for SetPresence like:

pbxconn.send({ "mt": "SetPresence", "api": "PbxApi", "sip": sip, "activity": "" });

But not the PbxAdminApi like:
pbxconn.send({ "mt": "GetGroups", "api": "PbxAdminApi" });

I see that it sends the request but no response.

Permission should be OK:

Everything checked beside "Impersonation"

Do I miss something?
Screenshot_2024-04-24_095652.png

Picture of Peter Stock (innovaphone)
Moderator Registered 225 days 1 hour
Peter Stock (innovaphone) Wednesday, 24 April 2024, 10:09 AM
Re: StartCall without opening die PhoneApp?
Hi Felix,

that was implemted for security issues. An UserWebsockt shoud not be able to use the PbxAdminApi. You can use it in the Serverside.

So you can send from user to server with "app.send...) and in the service.js you can have the PbxAdminApi, but you must handle the PBX Connections between the User Connections.

Here in this example is an implemented Handling of user Connections and PBX Connections.

https://github.com/innovaphone/jslicenseexample/blob/main/jslicenseexample/jslicenseexample/innovaphone-jslicenseexampleservice.js


Best Regards,

Peter
Picture of Felix 2874
Registered 8 years 177 days
Felix 2874 Wednesday, 24 April 2024, 02:57 PM
Re: StartCall without opening die PhoneApp?
Hi,

now I got it.
Looks a bit complicated in the first place but make sense if you know how it works.
In German we would say "von hinten durch die brust ins auge" wink
But for security reasons it makes sense.

Thanks again.
Picture of Peter Stock (innovaphone)
Moderator Registered 225 days 1 hour
Peter Stock (innovaphone) Wednesday, 24 April 2024, 03:04 PM
Re: StartCall without opening die PhoneApp?
Hi,

yes , if you just do an 1:1 relay through the service, this would be so.
But here, you can say what is allowed from this API in the Service, and what is not allowed smile.

Best Regards,

Peter
← You can define your color theme preference here