EventSource - Working polyfill

I'm trying to create a subscribtion to monitor nodes via javascript using the /event endpoint in the datalayer rest interface.

The problem is that the /automation/api/v2/events/subID GET requires authorization headers and that is not supported in any browser

https://developer.mozilla.org/en-US/docs/Web/API/EventSource

So i googled for a polyfill that suppors it and found this one;

https://github.com/Yaffle/EventSource

The problem is that using this never returns any messages. It does recieve data continously (the size increases) so so far it does work.

Does anyone have a working example using this?

/Andreas

 

Best reply by jochen-scheib

Hi Andreas,

can you replace

 

    es.addEventListener("message", listener);

 

with

 

    es.addEventListener("update", listener);

 

That should do the trick.

โ€ƒ

Subscription event update

Best regards

Jochen

View original
eventsource.zip
15.55KB
2 replies