Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/y-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,23 @@ const setupWS = provider => {
provider.emit('status', [{
status: 'disconnected'
}])
} else {
provider.wsUnsuccessfulReconnects++
clearTimeout(provider.resetUnsuccessfulReconnects)
}

// Start with no reconnect timeout and increase timeout by
// log10(wsUnsuccessfulReconnects).
// The idea is to increase reconnect timeout slowly and have no reconnect
// timeout at the beginning (log(1) = 0)
provider.wsUnsuccessfulReconnects++
setTimeout(setupWS, math.min(math.log10(provider.wsUnsuccessfulReconnects + 1) * reconnectTimeoutBase, maxReconnectTimeout), provider)
}
websocket.onopen = () => {
provider.wsLastMessageReceived = time.getUnixTime()
provider.wsconnecting = false
provider.wsconnected = true
provider.wsUnsuccessfulReconnects = 0
provider.resetUnsuccessfulReconnects = setTimeout(() => {
provider.wsUnsuccessfulReconnects = 0
}, 1000)
provider.emit('status', [{
status: 'connected'
}])
Expand Down Expand Up @@ -207,6 +210,7 @@ export class WebsocketProvider extends Observable {
this.wsconnecting = false
this.bcconnected = false
this.wsUnsuccessfulReconnects = 0
this.resetUnsuccessfulReconnects = undefined
this.messageHandlers = messageHandlers.slice()
this.mux = mutex.createMutex()
/**
Expand Down