Skip to Content
0
Jul 19, 2016 at 12:53 PM

SDS SWS Subscribe using Websocket

172 Views

Hi

I want my UI to subscribe to the output stream using websockets.

But I am unable to open the websocket connection due 'authorization missing (HTTP Code 401)' error. Since UI uses javascript, providing headers in websocket connection is not an option. The document says following:

If your WebSocket client does not support setting headers, include your credentials as the first element of the JSON map when requesting authorization

But how can this be achieved since the connection is closed?

Here is the code:

var ws = new WebSocket("wss://host:port/1/workspaces/default/projects/myProject/subscriber");

ws.onopen = function() { alert("WebSocket connection!"); ws.send(JSON.stringify(authorizationRequest)); };

ws.onmessage = function (evt) { var received_msg = evt.data; alert(received_msg); };

ws.onclose = function() { // websocket is closed. alert("Connection is closed...");

};

Thanks!