ref(connectable tab) on session destroyed

This commit is contained in:
Clem Fern 2023-05-12 19:39:44 +02:00
parent 2b5976f202
commit 312b365851
5 changed files with 44 additions and 41 deletions

View File

@ -83,20 +83,17 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent<SerialPr
this.write(`\r\n${colors.black.bgWhite(' Serial ')} ${msg}\r\n`)
this.session?.resize(this.size.columns, this.size.rows)
})
this.attachSessionHandler(this.session!.destroyed$, () => {
super.attachSessionHandlers()
}
protected onSessionDestroyed() {
if (this.frontend) {
// Session was closed abruptly
this.write('\r\n' + colors.black.bgWhite(' SERIAL ') + ` session closed\r\n`)
if (this.profile.behaviorOnSessionEnd === 'reconnect') {
this.reconnect()
} else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) {
this.offerReconnection()
super.onSessionDestroyed()
}
}
})
super.attachSessionHandlers()
}
async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise<any> {
return {

View File

@ -148,22 +148,14 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent<SSHProfile>
return session
}
protected attachSessionHandlers (): void {
const session = this.session!
this.attachSessionHandler(session.destroyed$, () => {
protected onSessionDestroyed() {
if (this.frontend) {
// Session was closed abruptly
this.write('\r\n' + colors.black.bgWhite(' SSH ') + ` ${this.sshSession?.profile.options.host}: session closed\r\n`)
if (this.profile.behaviorOnSessionEnd === 'reconnect') {
this.reconnect()
} else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) {
this.offerReconnection()
super.onSessionDestroyed()
}
}
})
super.attachSessionHandlers()
}
private async initializeSessionMaybeMultiplex (multiplex = true): Promise<void> {
this.sshSession = await this.setupOneSession(this.injector, this.profile, multiplex)

View File

@ -42,22 +42,14 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent<TelnetPr
super.onFrontendReady()
}
protected attachSessionHandlers (): void {
const session = this.session!
this.attachSessionHandler(session.destroyed$, () => {
protected onSessionDestroyed() {
if (this.frontend) {
// Session was closed abruptly
this.write('\r\n' + colors.black.bgWhite(' TELNET ') + ` ${this.session?.profile.options.host}: session closed\r\n`)
if (this.profile.behaviorOnSessionEnd === 'reconnect') {
this.reconnect()
} else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) {
this.offerReconnection()
super.onSessionDestroyed()
}
}
})
super.attachSessionHandlers()
}
async initializeSession (): Promise<void> {
await super.initializeSession()

View File

@ -784,7 +784,7 @@ export class BaseTerminalTabComponent<P extends BaseTerminalProfile> extends Bas
})
this.attachSessionHandler(this.session.destroyed$, () => {
this.setSession(null)
this.onSessionDestroyed()
})
this.attachSessionHandler(this.session.oscProcessor.copyRequested$, content => {
@ -793,6 +793,13 @@ export class BaseTerminalTabComponent<P extends BaseTerminalProfile> extends Bas
})
}
/**
* Method called when session is destroyed. Set the session to null
*/
protected onSessionDestroyed() {
this.setSession(null)
}
protected detachSessionHandlers (): void {
this.sessionHandlers.cancelAll()
}

View File

@ -33,6 +33,21 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
this.reconnectOffered = false
}
/**
* Method called when session is destroyed. Handle the tab behavior on session end for connectable tab
*/
protected onSessionDestroyed() {
super.onSessionDestroyed()
if (this.frontend) {
if (this.profile.behaviorOnSessionEnd === 'reconnect') {
this.reconnect()
} else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) {
this.offerReconnection()
}
}
}
/**
* Offering reconnection to the user if it hasn't been done yet.
* Set reconnectOffered to true