This commit is contained in:
nguyentrungthat 2025-11-06 10:04:53 +07:00
parent e4014054d2
commit db1ce8987d
1 changed files with 16 additions and 2 deletions

View File

@ -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<string> {
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)