Skip to content

Commit

Permalink
Error if server disconnects client before authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
freeall committed Jul 8, 2021
1 parent 8c5d564 commit b205fb5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const isWritingToStdoutOrFile = isWritingToStdout || isWritingToFile
const isWritingToStdoutAndFile = isWritingToStdout && isWritingToFile
let capturedPackets = 0
let capturedBytes = 0
let isAuthenticated = false

console.error(`Onomondo Live ${pkgJson.version}\n`)

Expand Down Expand Up @@ -86,13 +87,18 @@ function connect () {
socket.on('error', onerror)
socket.on('subscribe-error', onerror)

socket.on('disconnect', () => {
socket.on('disconnect', err => {
const hasServerForcefullyDisconnectedClient = err === 'io server disconnect'
if (hasServerForcefullyDisconnectedClient && isAuthenticated) return console.error('The server disconnected you')
if (hasServerForcefullyDisconnectedClient && !isAuthenticated) return console.error('The server disconnected you. Is the token correct?')

console.error('Connection closed. Trying to re-establish')
socket.disconnect()
setTimeout(connect, 1000)
})

socket.on('authenticated', () => {
isAuthenticated = true
console.error('Authenticated')
simIds.forEach(simId => socket.emit('subscribe:packets', simId))
})
Expand Down

0 comments on commit b205fb5

Please sign in to comment.