I was following the ChatWithWebsockets sample and trying to implement the connection in the same way to ‘/…/api/ws/events/v1’ by trying to have the first message sent on “open” be the auth command with the token. This does not seem to work like it does on the ‘/…/api/ws/messages/v1’ endpoint. However, I can connect when the auth is included in the header through the sample python app as well as through Insomnia/Postman.
Is the events endpoint incompatible with the javascript websockets API method of auth?
let statesWebsocket = new WebSocket(`${wsScheme}://${host}/api/ws/events/v1`);
statesWebsocket.addEventListener("open", () => {
statesWebsocket.send(buildAuthCommand(token));
});
No, It turns out that the JavaScript support did NOT make it to the 2023R3 release, only the documentation for it was released
.
The functionality is ready and tested, but unfortunately not available until the release of 2024R1.
The short answer is: Yes the functionality is compatible with javascript.
There is a separate command for authorization that can be used by javascript
It is documented here:
“Authenticate Command”,
Milestone XProtect Events and Status WS API Reference (milestonesys.com)
There is a javascript sample. It is beta, awaiting approval..
Thanks for this example, it looks like I was following the same logic. When testing this new example on my dev machine I get the same 401 response. The initial token request gets a 200 response with a valid token, but the upgrade gets a 401 response. However, this same token works when I use it in Insomnia/Postman to upgrade the connection to a websocket. It is also hitting the “error” listener on line 201. Is it possible I have incorrectly configured my API? I have all origins allowed for CORS for testing/development purposes, and am using an insecure connection. I am just very confused because the ChatWithWebsockets example seems to be working fine.
I am sorry. My first answer was wrong. After consulting the developers I now got the opposite answer..
It turns out that the JavaScript support did NOT make it to the 2023R3 release, only the documentation for it was released
.
The functionality is ready and tested, but unfortunately not available until the release of 2024R1.
I am very sorry for the confusion.
No worries at all! Thank you so much for verifying that information with me… Honestly, I am just relieved that I wasn’t doing it wrong on my end!
I’ll be looking out for that feature in the next release.