Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 17, 2020 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/223270b855e3c6409f8a9953c7eec61b to your computer and use it in GitHub Desktop.
Save velotiotech/223270b855e3c6409f8a9953c7eec61b to your computer and use it in GitHub Desktop.
js code to subscribe to stream
var source = new EventSource("{{ url_for('sse.stream') }}");
source.addEventListener('publish', function(event) {
var data = JSON.parse(event.data);
console.log("The server says " + data.message);
}, false);
source.addEventListener('error', function(event) {
console.log("Error"+ event)
alert("Failed to connect to event stream. Is Redis running?");
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment