From 5f73e21277fd9bed79c7b59ee892e0a84457813e Mon Sep 17 00:00:00 2001 From: Faiz Akram Date: Wed, 15 Nov 2017 18:57:16 +0530 Subject: [PATCH] Update README.md --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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
+    };
+
+