Question

Getting an FME Server stream back via Javascript

  • 30 November 2019
  • 4 replies
  • 2 views

Userlevel 4
Badge +25

Hi FME'ers,

Just in case anyone is online today, and might know this, I have a question about JavaScript and FME Server. I have a line of JavaScript like this:

<svg id="fillgauge1" width="10%" height="600" onclick="gauge1.update(42);"></svg>

It basically sets a new value to 42. But I also have an FME Server stream that returns the number 42:

http://imark/fmedatastreaming/imark/CreateNumberStream.fmw?DestDataset_TEXTLINE=C%3A%5CFMETesting%5Ctestfile.txt&token=617ec6bebe9ccd1a98f9d9b5481a979e083bdc61

So, what I want to know is, can I somehow get the response from that FME Server URL into my JavaScript? 

I was hoping something simple like pasting the URL would do it:

<svg id="fillgauge1" width="10%" height="600" onclick="gauge1.update(http://imark/fmedatastreaming/imark/CreateNumberStream.fmw?etc etc);"></svg>

But I figure that's very unlikely, and just shows my lack of js experience.

Any assistance would be much appreciated!

Mark


4 replies

Userlevel 4
Badge +25

Thinking about it, I'm just passing the value to a JavaScript script, that part is more HTML. Maybe that makes it easier - or perhaps it's easier to actually do that part in the script. Hmmm.

Badge +11

Hey Mark, not sure if you're still stuck on this...

You probably want to be using the FME Server Javascript API to make the call to the streaming service, then get the result using a callback function. Once you've got the result you can set the fillgauge1 value.

Documentation for the streaming service call is here:

https://playground.fmeserver.com/javascript/javascript-library/server-documentation/

On the above page, look at the definition for:

"FMEServer.runDataStreaming( repository, workspace, parameters, callback ) , return Object "

You're going to need to learn about callback methods and how they work (which is a bit beyond the scope of what can be explained in my answer here!).

Hope that helps... I don't have any sample code I can send at the moment but if you need something I can probably mock something up relatively quickly.

Nic

Userlevel 4
Badge +25

Hey Mark, not sure if you're still stuck on this...

You probably want to be using the FME Server Javascript API to make the call to the streaming service, then get the result using a callback function. Once you've got the result you can set the fillgauge1 value.

Documentation for the streaming service call is here:

https://playground.fmeserver.com/javascript/javascript-library/server-documentation/

On the above page, look at the definition for:

"FMEServer.runDataStreaming( repository, workspace, parameters, callback ) , return Object "

You're going to need to learn about callback methods and how they work (which is a bit beyond the scope of what can be explained in my answer here!).

Hope that helps... I don't have any sample code I can send at the moment but if you need something I can probably mock something up relatively quickly.

Nic

Hi Nic.

Thanks for that. You know, I didn't even think of using the Server API! I just thought read it through the web service. That's a facepalm on my part for sure.

It's not too urgent now, but if I find time to go back and play with this, I'll certainly look into that call.

Cheers.

Mark

Badge +5

It's pretty easy to use a json streaming service with JQuery, happy to provide sample code.

Reply