diff --git a/README.md b/README.md index 3015b94..675c3ad 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,36 @@ boolean completeAfterMessage, String... events) SseEmitter emitter = new SseEmitter(timeout); + +#Use in javascript + +
+var eventSource; +window.onbeforeunload = () => { + if (eventSource) { + eventSource.close(); + } +} +eventSource = new EventSource(`http://10.1.16.61:8080/SpringMVCHibernateWithSpringSecurity/register/${uuid}`); +eventSource.addEventListener('message', response => { + for (let line of response.data.split('\n')) { + console.log(line); + handleResponse(JSON.parse(line)); + } +}, false); ++ +#Use in Angular JS +
+const EventSource: any = window['EventSource']; + const es = new EventSource('http://10.1.16.61:8080/SpringMVCHibernateWithSpringSecurity/register/${uuid}', + { headers: { 'Content-Type': 'text/event-stream' } }); + es.onconnect = (e) => { + console.log(e); + } + es.onmessage = evt => { + console.log('Event source testing', evt); + const data = JSON.parse(evt.data); // TODO handle parse error + }; ++