Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
faizakram authored Nov 15, 2017
1 parent d653010 commit 5f73e21
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,36 @@
boolean completeAfterMessage, String... events)
SseEmitter emitter = new SseEmitter(timeout);
</pre>

#Use in javascript

<pre>
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);
</pre>

#Use in Angular JS
<pre>
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
};
</pre>

0 comments on commit 5f73e21

Please sign in to comment.