Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.
Websocket support
-
Hi there!
I am interested in using the websocket connection that Mango provides. I am also interested in developing apps with other frameworks other than AngularJS that may be served separately from Mango.
I know of the REST API, but hooking into the websocket provides the responsiveness that I am looking for.
I am wondering if it is possible for you guys to add the ability to enable cross-origin support for the websocket?
Regards,
Leandro -
@leandro said in Websocket support:
I am wondering if it is possible for you guys to add the ability to enable cross-origin support for the websocket?
Yes definitely, I wasn't aware that it wasn't working. I'll make an issue around this and look into it.
-
Hi Leandro,
Sorry to be delayed in getting back to you. Have you attempted changing the env.properties associated with CORS? I believe the relevant section of the code for that part of the configuration happens here: https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/serotonin/m2m2/web/mvc/spring/MangoWebSocketConfiguration.java#L77
The console on the left is with the env.properties
rest.cors.enabled=false rest.cors.allowedOrigins=
while the console on the right has the properties
rest.cors.enabled=true rest.cors.allowedOrigins=localhost:8080,127.0.0.1:8080
Note that in the right console I am still getting a 403 error for my request to 127.0.0.1:8080, probably because I didn't login on that hostname and don't have a valid session in an accessible cookie to send as a header in the websocket request. The reason I am getting 405s is that I didn't try to register for a real websocket, I was merely testing if the origin would be permitted, and it was. I can provide a more complete example if requested where the logging in gets done and a session cookie is available to the browser's JavaScript.
Hope that's helpful!
-
Hi,
Thanks for the input and sorry for the long delay. I am finally able to tackle this again.
I have tried as you suggested and I too get the 403 and 405 errors. Can you provide an example of how to do this while logged?
I think that I should be able to run :
new WebSocket('ws://localhost:8080/rest/v1/websocket/point-values')
or (not sure of the difference):
new WebSocket('ws://localhost:8080/rest/v2/point-values')
within the console of a correctly logged in session and connect to the ws server.
-
Actually, never mind. I am able to connect to the websocket on a console on a logged in tab.
Now I need to figure out how to log in and use that in my connection.
-
You can watch the network tab for an example of acquiring a session cookie and xsrf token by using the /ui/login page and the network tools, or find the best example on the forum for the framework you're using.
Basic authentication and Token authentication are also options!
-
It looks like @leandro is opening the websocket connection from a browser, in which case only session authentication is an option. You can't set the
Authorization
header using the browser WebSocket API.