Service - cannot connect to PbxApi a second time
Hello,
in my (Javascript) app, the client sends a message to the service, which the service forwards to the PBX. The PBX then sends back a response to the service, which the service finally forwards to the client. However, this works only when I launch the client the first time. The second time, the "onconnected" callback is never triggered. Here's the code (of the service-part) which I used to create a minimum reproduction of the problem:
in my (Javascript) app, the client sends a message to the service, which the service forwards to the PBX. The PBX then sends back a response to the service, which the service finally forwards to the client. However, this works only when I launch the client the first time. The second time, the "onconnected" callback is never triggered. Here's the code (of the service-part) which I used to create a minimum reproduction of the problem:
new JsonApi("admin").onconnected(function(conn) {
if (conn.app == "my-app") {
conn.onmessage(function(msg) {
var obj = JSON.parse(msg)
if (obj.mt == "TestMessage") {
var pbxAdminApi = new PbxApi("PbxAdminApi")
pbxAdminApi.onconnected(function(pbxConn) {
// this never happens the 2nd time I launch the app
conn.send(JSON.stringify({ api: "admin", mt: "TestMessageResult", src: obj.src }))
pbxConn.close()
})
})
}
});
}
});
Could it be that the PbxApi from the previous launch is still open and multiple connections are not allowed?
Edit: sorry for the hard-to-read code snippet. In the preview of the post it looked somewhat better and all indentations were preserved.
Best regards
Marko
Edit: sorry for the hard-to-read code snippet. In the preview of the post it looked somewhat better and all indentations were preserved.
Best regards
Marko