Creating the Web Socket Connection
Create a websocket
To create a web socket, point a web socket client at:
ws://[server]/insightservices/ws/v1/compute/messagesFor secure web sockets, use the following:
wss://[server]/insightservices/ws/v1/compute/messages
You must supply the bearer token for the authorization header when opening the socket. For information on generating the bearer token using the REST API, see Generate the Bearer Token.
The response will include the header connection-id to indicate the id of the socket. The connection-id is an important value to retain. Each job submission must include this header to associate the job and its progress events with the web socket.
const WebSocket = require('ws'); this.webSocket = new WebSocket(wsAddress, { perMessageDeflate: true, //enables message compression headers: { authorization: 'Bearer ${this._token}'. //token generated from clientId and secret } }); ws.on('message', function incoming(data) { let message = JSON.parse(data); if (message.messageType == "JOB_STATUS_UPDATED") { //then do something with the status } else if (message.messageType == "RUNLOG_UPDATED") { //then print the runlog } else …. });
![]() |
Important The response will set the header
connection-id to indicate the id of the socket. This connection id must be added as the
id parameter in the submitted job when you are using a web socket to connect to
Xpress Insight 5.
|
Keep Alive Ping
The server will periodically issue ping messages to ensure the client is still alive. The client should respond with a pong message echoing back the contents of the ping. If no pong is received after a five-minute period, the socket is classed as idle and will be disconnected.
Bearer Token Refresh
{ "messageType": "UPDATE_TOKEN" "messagePayload": { "token": "<token_associated_with_the_socket>" } }
Reconnecting a Socket
ws://[server]/insightservices/ws/v1/compute/messagesIt is not possible to reconnect to the same socket.