Jump to content
Vodia PBX forum
Sign in to follow this  
voltier

Sample working code for Web Socket

Recommended Posts

Just wondering if anybody out there has working code for Web Sockets that they could share. We have looked at Vodia's latest php sample, along with some samples found in the forum e.g. (http://forum.vodia.com/index.php/topic/14660-rest-api-calls-from-javascript/?hl=websocket&do=findComment&comment=42175) however they do not appear to work. We are currently sitting on 5.5.4 of the pbx.

 

Edit:

 

I am expecting to get this:

{"action":"call-state","calls":[{"id":85895,"from":"\"AUTO PARTS\"
But, instead, I am getting the following:
{"action":"user-state","type":"","account":"","domain":"","chatstatus":"online"}
{"action":"user-state","type":"attendants","
Which is not consistent with the REST API documentation.

Share this post


Link to post
Share on other sites

I too am running into this issue. I have found that if I login to the portal then create a connection then it will work as I have a cookie setup. However, if I do not do this then I get the same issue as voltier. I am wondering if there is a query parameter we can pass in on the connection instead of relying on the cookie? The cookie does not work across different domains.

 

However, I do have an example of the web sockets working you just need to login through the login interface and set a session in a cookie on the same domain as your pbx.

 

ie: document.cookie = "session={apikeyfromlogin};path=/;domain={pbxdomain.com}";

 

After that your code should work. Not sure if you are still having problems but this should point you in the right direction if you still need help.

Share this post


Link to post
Share on other sites

You have to login as a user to get a session id before using the websocket API, which can be used to monitor calls or make and hangup calls etc.

 

You can get the session ID during login and then use that token on every subsequent call. An example is given below:
hash = MD5(password);
vars = { name: "auth", value: account + " " + hash };
sessId = putRest("/rest/system/session", vars);
if (sessId != "") {
document.cookie = "session=" + sessId;
}
The account (extension@domain) and password (its MD5 hash is used) are for the user login. To login, you make a REST call to "/rest/system/session" to the PBX with the variables explained above. You will get a session ID which you can then set to a cookie as shown, for all subsequent calls.
I hope that solves the problem for you.
Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×