Skip to main content
Question

Connect to FME Web Socket Subscriber with Pure Javascript

  • August 23, 2018
  • 1 reply
  • 18 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?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

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