Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save senoritadeveloper01/ad8136ce02f7ce10e907ec6df487dd35 to your computer and use it in GitHub Desktop.
Save senoritadeveloper01/ad8136ce02f7ce10e907ec6df487dd35 to your computer and use it in GitHub Desktop.
Angular SSE component - detect back to online status
isOnlineSubscription: Subscription;
ngOnInit() {
...
this.checkIfBackToOnline();
}
ngOnDestroy() {
...
this.isOnlineSubscription.unsubscribe();
}
checkIfBackToOnline() {
this.isOnlineSubscription = fromEvent(window, 'online').subscribe(status => {
if (status) {
//create dummy data to trigger refresh
let parsedUsername = this.getUsername();
let socketEvent = new SocketEvent(parsedUsername, 'ONLINE');
this.socketEventStorage.refreshSocketMailEventInfo([{...socketEvent, itemType: 'MESSAGE'}]);
this.socketEventStorage.refreshSocketContactEventInfo([{...socketEvent, itemType: 'CONTACT'}]);
this.socketEventStorage.refreshSocketCalendarEventInfo([{...socketEvent, itemType: 'CALENDAR'}]);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment