Skip to content

Commit

Permalink
Manually reconnect closed sockets (#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Nov 24, 2024
1 parent e0bdc84 commit 6eaea17
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions assets/src/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ export function buildClient(gqlUrl, wsUrl, fetchToken) {
},
})

socket.onClose((e) => {
console.log('reconnecting closed socket', e)
if (socket.closeWasClean) {
socket.reconnectTimer.scheduleTimeout()
}
})

setInterval(() => {
if (socket.transport.readyState == WebSocket.CLOSED) {
console.log('found dead websocket, attempting a reconnect')
socket.reconnectTimer.scheduleTimeout()
}
}, 10000)

window.addEventListener('pageshow', () => socket.connect())

const absintheSocket = AbsintheSocket.create(socket)

const socketLink = createAbsintheSocketLink(absintheSocket)
Expand Down

0 comments on commit 6eaea17

Please sign in to comment.