Skip to main content
Question

Connect to FME Web Socket Subscriber with Pure Javascript

  • August 23, 2018
  • 1 reply
  • 15 views

Forum|alt.badge.img

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?

1 reply

Forum|alt.badge.img
  • Author
  • August 24, 2018

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);
};

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings