Created
June 17, 2020 05:49
-
-
Save velotiotech/223270b855e3c6409f8a9953c7eec61b to your computer and use it in GitHub Desktop.
js code to subscribe to stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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