I created a Server-Sent Event connection with Spring and Angular to send a periodic message about possible incoming restart.
But the SSE connection is limited to 6 connections per user. This means that if I open more than 6 tabs, everything slows down because the browser can't get connections - the page doesn't load.
angular
const source = new EventSource('/api/incoming-restart-event')
source.addEventListener('message', (message: MessageEvent) => {
minutesUntilRestart = message.data
})
Spring
@GetMapping(path = "/incoming-restart-event", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Date> incomingRestartEventStream() {
return Flux.interval(Duration.ofSeconds(3), Duration.ofSeconds(100))
.map(sequence -> incomingRestartService.getIncomingRestartTime() != null
? incomingRestartService.getIncomingRestartTime()
: new Date(0));
}
What would be the best way to only send updates to the active tab (or just last active tab)? Basically - I want to make sure that we aren't opening 6+ open connections.
I would prefer to handle this in the back-end so I don't have to build some kind of a front-end session handler for trying to count user's active tabs.