Skip to content

Latest commit

 

History

History
56 lines (48 loc) · 1.55 KB

README.md

File metadata and controls

56 lines (48 loc) · 1.55 KB

PUSH-NOTIFICATION Using SseEventBus and SseEmitter

#When you using spring MVC using the version 4.2.4.RELEASE org.springframework spring-web 4.2.4.RELEASE

The resion is SseEmiter Have parameterised constructor in

#org.springframework.web.servlet.mvc.method.annotation.SseEmitter

#When calling

	eventBus.createSseEmitter(id, SseEvent.DEFAULT_EVENT);
	// it calls SseEventBus -->
	public SseEmitter createSseEmitter(String clientId, Long timeout, boolean unsubscribe,
			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
    };