Skip to main content

I'm attempting to use the standard javascript web socket to subscribe to the FME server web sockets endpoint.

I'm simply doing:

this.socketConnection = new WebSocket(webSocketUrl);

That^ code connects to the web socket on FME server but never receives or sends messages. Am I meant to include a protocol?

Does anyone know why messages would not be coming through or not be sent?

After posting this I figured out the solution pretty quickly using FMEServer.js as a reference. 

Basically - You have to create a new WebSocket object with the URL and then "onopen" send a message to the server with a special FME JSON object describing what stream you are interested in and how the server should handle it. below is an example of just subscribing to a particular stream:

let streamId = "myStreamId";
let fmeWebSocket = new WebSocket("ws://myWebServer:7078/websocket");

fmeWebSocket.onopen = function(event){
    console.log("websocket connected!!!!");
   
    let openMsg = {
        ws_op : 'open',
        ws_stream_id : streamId
    };
    fmeWebSocket.send(JSON.stringify(openMsg));
};

fmeWebSocket.onmessage = function(event) {
    console.log("Got the message from the server!!! Event data: " + event.data);
};

Reply