Picture of Marko 6403
Registered 2 years 89 days
Marko 6403 Monday, 5 September 2022, 03:26 PM
App service - problems with logging to file and connection via PbxApi
Hello,

I am developing a Javascript-based app using the (at this moment) latest beta version of 13r3 and I have faced two issues in the service-part of the app (written in Javascript):

- the global log(...) function does not write the log into the file. When I open the log file using the AP Manager, I can see a lot of log messages from the SDK, but not my own. I have already tried changing the log-settings in AP Manager > MyApp > Diagnostics, but that didn't work

- it seems that the service cannot access the PbxAdminApi, despite having the required permissions for it (as set in the advanced admin settings under PBX > Objects > MyApp > Apps > Grant Access to APIs).

To be more concrete, here's the corresponding code snippet:

new JsonApi("admin").onconnected(function(conn) {
log("Admin connected") // ----- this log doesn't work

if (conn.app == "mycompany-myapp") {
conn.onmessage(function(msg) {
var obj = JSON.parse(msg);
if (obj.mt == "Foo") {
var licensesApi = new PbxApi("PbxAdminApi");
licensesApi.onconnected(function(apiConn) {
// ----- this is never triggered -----
apiConn.send(JSON.stringify({api: "PbxAdminApi", mt: "GetAppLics"}))
apiConn.onmessage(function(msg) {
let data = JSON.parse(msg)
conn.send(JSON.stringify({ api: "admin", mt: "FooResult", src: obj.src}))
})
}
})

}
});


The goal is the following: the client (not shown here) sends a message with mt : "Foo" to the service. The service receives the message and sends a PBX API request. Once the PBX API sends a response to the service, the service sends a response back to the client. In other words, I tried achieving what is described in this post, but it didn't work. The client never gets a response at the end. What happens in between is hard to tell, since logging doesn't work.

Simply sending a message from client to service and from service to client (without an API request in-between) works though.

Any idea what the cause of the aforementioned problems may be? Thanks!

Best regards
Marko


Andreas Fink
Moderator Registered 12 years 278 days
Andreas Fink (innovaphone) Monday, 5 September 2022, 07:04 PM
Re: App service - problems with logging to file and connection via PbxApi
Hello Marko,

> the global log(...) function does not write the log into the file

If you start the App Instance from AP Manager, you have to activate App flag under Diagnostics options of the App Instance, to be able to see the output of the log (this log lines will start with "JS:").

In case you start the App from Visual Studio (debugging via gdb), the App flag is already activated and you should be able to see the output of the log in the "Linux Console Window" of the Visual Studio.


> - it seems that the service cannot access the PbxAdminApi

Make sure to enable "Websocket" option of the App Object also, to activate a WebSocket connection from the PBX to the App Service (you should see "connected" near the URL of the App Service )


> To be more concrete, here's the corresponding code snippet:

This part contains errors and will not evaluate at all. Make sure, you use only ECMAScript 2015 (check https://duktape.org/guide.html for more information). In this particular case "let" should be replaced by "var". Also one } too much is there.

Paste your code into https://www.jslint.com/ or enable JSLint in your IDE to see possible JS errors prior uploading the code to the AP.

Best Regards
Andreas Fink
Picture of Marko 6403
Registered 2 years 89 days
Marko 6403 Wednesday, 7 September 2022, 04:35 PM
Re: App service - problems with logging to file and connection via PbxApi
I somehow got the logs working (the corresponding flags under "Diagnostics" were already checked in my case), however, I do not always see my logs. Every now and then I need to re-deploy the app (without modifying any code) in order to see the logs.

Thanks to the now functional logs and your hint regarding ECMAScript 2015, I managed to get the PbxAdminApi working smile, though this also occasionally demands re-deployment in order to work.

I will keep an eye of things and come back here in case the issue persists. If you have any idea what the cause might be that it only occasionally works, I'd be grateful if you could tell me.
← You can define your color theme preference here