Created
April 29, 2022 14:04
-
-
Save senoritadeveloper01/ad8136ce02f7ce10e907ec6df487dd35 to your computer and use it in GitHub Desktop.
Angular SSE component - detect back to online status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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