Picture of Richard 3284
Registered 8 years 115 days
Richard 3284 Thursday, 10 August 2023, 04:48 PM
onsend callback is not executed
Hi,

I can't get the onsend callback working. I receive on the pbxapiadmin a response (that's the conn object var) and it should response to the original web request (req object var). See code:

conn.onmessage(function (msg) {
log('New PbxAdminApi-Message: ' + msg);
msg = JSON.parse(msg);

switch (msg.mt) {
case 'UpdateObjectResult':
req.onsend(function (req) {
log("in onsend");
req.send(new TextEncoder("utf-8").encode(JSON.stringify(msg)), true);
log("Result has been send back to client.");
});
req.responseContentType("json");
log("reponse type set");
req.sendResponse();
log("SendResponse done");
break;
}
});

In the log I do see:
08-10 14:45:41.935 booleancreator@bonkestoter.nl Data send to PBX: {"mt":"UpdateObject","api":"PbxAdminApi","src":"Johan","cn":"Johan","h323":"Johan","e164":"","node":"root","loc":"pbx","pseudo":{"type":"bool","time-map":[{"start-h":"17","start-m":"00","end-h":"23","end-m":"00","start-day":"23","start-month":"7","start-year":"2024","end-day":"24","end-month":"7","end-year":"2023"}]},"dn":"Johan"}
08-10 14:45:41.936 booleancreator@bonkestoter.nl AppWebsocket(00227de0)::AppWebsocketMessageSend {"mt":"UpdateObject","api":"PbxAdminApi","src":"Johan","cn":"Johan","h323":"Johan","e164":"","node":"root","loc":"pbx","pseudo":{"type":"bool","time-map":[{"start-h":"17","start-m":"00","end-h":"23","end-m":"00","start-day":"23","start-month":"7","start-year":"2024","end-day":"24","end-month":"7","end-year":"2023"}]},"dn":"Johan"} connected:true
08-10 14:45:41.937 booleancreator@bonkestoter.nl AppWebsocket(00227de0)::WebsocketSendResult() connected=1 sendCount=1
08-10 14:45:41.937 booleancreator@bonkestoter.nl AppWebsocket(00227de0)::AppWebsocketRecvResult {"api":"PbxAdminApi","src":"Johan","mt":"UpdateObjectResult","error":"cn already exists"}
08-10 14:45:41.938 booleancreator@bonkestoter.nl New PbxAdminApi-Message: {"api":"PbxAdminApi","src":"Johan","mt":"UpdateObjectResult","error":"cn already exists"}
08-10 14:45:41.938 booleancreator@bonkestoter.nl reponse type set
08-10 14:45:41.939 booleancreator@bonkestoter.nl SendResponse done
08-10 14:45:41.939 booleancreator@bonkestoter.nl AppWebsocket(00227de0)::AppWebsocketMessageComplete connected:true

So the case 'UpdateObjectResult': is processed but the onsend never called.

Any idea why?

Richard
Andreas Fink
Moderator Registered 13 years 109 days
Andreas Fink (innovaphone) Monday, 21 August 2023, 11:12 PM
Re: onsend callback is not executed
Hello Richard,

could you describe what type are conn and req Objects in your example?

In case we are talking about JsonApi Library - there is no onsend callback function.

Best Regards
Andreas Fink
Picture of Richard 3284
Registered 8 years 115 days
Richard 3284 Friday, 25 August 2023, 07:51 PM
Re: onsend callback is not executed
Hi,

I'm talking about de webserver.onsend as documented in the API:
https://sdk.innovaphone.com/13r3/doc/javascript/WebServer.htm

What I try to achieve is the following:
In a excel sheet I'm creating a time schedule.
With a HTTP Get reguest with the time schedule data as json in the body, I wan't to create a boolean object in the PBX. I do receive the data and can read it. But when I wan to send the result back to excel, the onsend seems not being called.

I'm able to achieve a result with the request url with query paramaters only, but I really like to use a JSON message in the body.

The program does get in the onmessage function, but the send and so the onsend seems not to be called??

See the complete code in the attachment

With regards
Richard Bonkestoter
js_code_for_creating_boolean_object_from_webrequest.txt
Picture of Richard 3284
Registered 8 years 115 days
Richard 3284 Wednesday, 11 October 2023, 09:04 PM
Re: onsend callback is not executed
Hi

Anybody who can help me with this?

Richard
Picture of mitop
Registered 3 years 349 days
mitop Monday, 16 October 2023, 03:28 PM
Re: onsend callback is not executed
Hi Richard,

before I go deeper, from your posted log one can see, that there is no "in case" output that should be printed to the log in case of a "UpdateObjectResult" message. From this I conclude that the code does not jump to the case statement at all. Switch statements should always have a default (https://www.w3schools.com/js/js_switch.asp), add default to your switch statement and test it again. A few other points stand out to me, but I think it's because of the Switch statement.


Best regards
Mladen
Picture of mitop
Registered 3 years 349 days
mitop Monday, 16 October 2023, 03:36 PM
Re: onsend callback is not executed
...since the code is executed in the backend and processed by Duktape, the behavior of the same Javscript code in the front and backend may differ.
Picture of Richard 3284
Registered 8 years 115 days
Richard 3284 Thursday, 14 December 2023, 08:56 PM in response to Richard 3284
1 of 1 users consider this post helpful
Re: onsend callback is not executed
Hi,

I found the problem. The onsend was never executed because it wasn't included in the even context of the original request.

Thanks for the responses.

RIchard
← You can define your color theme preference here