mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-27 13:54:01 +02:00
Update max socket reconnection to 15s, add socket reconnection logs
This commit is contained in:
+21
-2
@@ -10,6 +10,8 @@ class ServerSocket extends EventEmitter {
|
|||||||
this.connected = false
|
this.connected = false
|
||||||
this.serverAddress = null
|
this.serverAddress = null
|
||||||
this.token = null
|
this.token = null
|
||||||
|
|
||||||
|
this.lastReconnectAttemptTime = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
$on(evt, callback) {
|
$on(evt, callback) {
|
||||||
@@ -35,8 +37,8 @@ class ServerSocket extends EventEmitter {
|
|||||||
const socketOptions = {
|
const socketOptions = {
|
||||||
transports: ['websocket'],
|
transports: ['websocket'],
|
||||||
upgrade: false,
|
upgrade: false,
|
||||||
path: `${serverPath}/socket.io`
|
path: `${serverPath}/socket.io`,
|
||||||
// reconnectionAttempts: 3
|
reconnectionDelayMax: 15000
|
||||||
}
|
}
|
||||||
this.socket = io(serverHost, socketOptions)
|
this.socket = io(serverHost, socketOptions)
|
||||||
this.setSocketListeners()
|
this.setSocketListeners()
|
||||||
@@ -54,6 +56,9 @@ class ServerSocket extends EventEmitter {
|
|||||||
this.socket.on('user_updated', this.onUserUpdated.bind(this))
|
this.socket.on('user_updated', this.onUserUpdated.bind(this))
|
||||||
this.socket.on('user_item_progress_updated', this.onUserItemProgressUpdated.bind(this))
|
this.socket.on('user_item_progress_updated', this.onUserItemProgressUpdated.bind(this))
|
||||||
this.socket.on('playlist_added', this.onPlaylistAdded.bind(this))
|
this.socket.on('playlist_added', this.onPlaylistAdded.bind(this))
|
||||||
|
this.socket.io.on('reconnect_attempt', this.onReconnectAttempt.bind(this))
|
||||||
|
this.socket.io.on('reconnect_error', this.onReconnectError.bind(this))
|
||||||
|
this.socket.io.on('reconnect_failed', this.onReconnectFailed.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
removeListeners() {
|
removeListeners() {
|
||||||
@@ -72,6 +77,20 @@ class ServerSocket extends EventEmitter {
|
|||||||
this.socket.emit('auth', this.token) // Required to connect a user with their socket
|
this.socket.emit('auth', this.token) // Required to connect a user with their socket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onReconnectAttempt(attemptNumber) {
|
||||||
|
const timeSinceLastReconnectAttempt = this.lastReconnectAttemptTime ? Date.now() - this.lastReconnectAttemptTime : 0
|
||||||
|
this.lastReconnectAttemptTime = Date.now()
|
||||||
|
console.log(`[SOCKET] Reconnect attempt ${attemptNumber} ${timeSinceLastReconnectAttempt > 0 ? `after ${timeSinceLastReconnectAttempt}ms` : ''}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
onReconnectError(error) {
|
||||||
|
console.log('[SOCKET] Reconnect error', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
onReconnectFailed(error) {
|
||||||
|
console.log('[SOCKET] Reconnect failed', error)
|
||||||
|
}
|
||||||
|
|
||||||
onDisconnect(reason) {
|
onDisconnect(reason) {
|
||||||
console.log('[SOCKET] Socket Disconnected: ' + reason)
|
console.log('[SOCKET] Socket Disconnected: ' + reason)
|
||||||
this.connected = false
|
this.connected = false
|
||||||
|
|||||||
Reference in New Issue
Block a user