Interpreting EventStream via Javascript

Hi. So, I’m all set up with getting events from my Electron as an event stream, i.e. by entering this URL into my browser:{access_token}

This works fine, and the page updates with events as they occur.

What I’m trying to do now is interpret those incoming events with JavaScript, and process and display them in some useful way on a webpage, e.g.

var source = new EventSource("{access_token}");
source.onmessage = function(event) {
    // Do something useful with

But when I do this, no events ever seem to come through, even when triggering them manually. Some further reading seems to imply this might be a problem with the domains of the webpage and the event source not matching. (Cross-origin URLs)

Does anyone know of a way to get around this? Either through Particle configuration or JavaScript fiddling.

Alternatively, it would be sufficient for the project (albeit less preferable) to just query the Particle API for the last few events that have occurred. I’d be interested in how to do this as well.

I’m running on Chrome.


Why not use the JS SDK?

And there currently is no way to request past events.


Bingo. I didn’t even know that was there.

As always “Read the gosh-darned manual”.


1 Like