I'm using Socket.IO client and have the following code:
export const notificationsWsSubject = new BehaviorSubject<Socket | null>(null)
signedInObservable.pipe(
switchMap(user => forkJoin([of(user), from(getNotificationsWebsocketTicket())]))
).subscribe(values => {
notificationsWsSubject.next(
io(SERVER_URL, {
auth: {
ticket: values[1].data,
accessToken: values[0].accessToken
}
})
)
})
basically whenever a user signs in (signedInObservable) I request a ticket from my server (getNotificationsWebsocketTicket()) and only then I actually open a websocket connection.
Now I want to do the same for when a connection has closed for some reason (temporary offline) and a reconnnect attempt has been made by Socket.IO.
How can I make sure Socket.IO attempts to "reconnect" only after I made a request to
getNotificationsWebsocketTicket()? so that I can reconnect again with auth data?
something like:
io.beforeReconnect(() => {
return getNotificationsWebsocketTicket()
}).then(ticket => io(SERVER_URL, {
auth: {
ticket: ticket
accessToken: getToken()
})
)