diff --git a/BACKEND/app/services/switch_connection.ts b/BACKEND/app/services/switch_connection.ts index ec7e81e..7013492 100644 --- a/BACKEND/app/services/switch_connection.ts +++ b/BACKEND/app/services/switch_connection.ts @@ -76,6 +76,10 @@ export default class SwitchController { this.onData(this.portGroups, this.status) } + private _handleTimeout() { + this.onData(this.portGroups, this.status) + } + private _waitFor(prompt: string, timeout = 5000): Promise { return new Promise((resolve, reject) => { const timer = setTimeout(() => { @@ -109,8 +113,18 @@ export default class SwitchController { this.socket.on('data', (data) => this._handleData(data.toString())) resolve() }) - this.socket.on('close', () => this._handleClose()) - this.socket.on('error', (err) => this._handleError(err)) + this.socket.on('close', () => { + this._handleClose() + resolve() + }) + this.socket.on('error', (err) => { + this._handleError(err) + resolve() + }) + this.socket.on('timeout', () => { + this._handleTimeout() + resolve() + }) } catch (error: any) { console.log('[ERROR CONNECT SWITCH]:', error.message) reject(error)