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.