This commit is contained in:
yumoqing 2025-09-12 15:03:44 +08:00
parent 62cf2c2bff
commit 7cacd35598

View File

@ -17,6 +17,29 @@ bricks.Wterm = class extends bricks.JsWidget {
this.bind('domon', this.send_term_size.bind(this)); this.bind('domon', this.send_term_size.bind(this));
this.bind('domoff', this.destroy.bind(this)); this.bind('domoff', this.destroy.bind(this));
} }
close_websocket(){
try {
console.log('socket alive, destroy it');
// this.socket.send(JSON.stringify({ type: "close"}));
this.socket.close(1,'close now');
this.socket.onopen = null;
this.socket.onmessage = null;
this.socket.onerror = null;
this.socket.onclose = null;
this.socket = null;
} catch(e) {
console.log('e=', e);
}
}
close_terminal(){
try {
this.fitAddon.dispose();
this.term.dispose();
this.term = null;
} catch(e){
console.log('e=', e);
}
}
destroy(){ destroy(){
console.debug('------domoff event, destory this widget'); console.debug('------domoff event, destory this widget');
try { try {
@ -28,20 +51,11 @@ bricks.Wterm = class extends bricks.JsWidget {
} }
console.debug('---1--domoff event, destory this widget'); console.debug('---1--domoff event, destory this widget');
if (this.socket){ if (this.socket){
console.log('socket alive, destroy it'); this.close_websocket();
this.socket.send(JSON.stringify({ type: "close"}));
this.socket.close(1,'close now');
this.socket.onopen = null;
this.socket.onmessage = null;
this.socket.onerror = null;
this.socket.onclose = null;
this.socket = null;
} }
console.debug('---2--domoff event, destory this widget'); console.debug('---2--domoff event, destory this widget');
if (this.term){ if (this.term){
this.fitAddon.dispose(); this.close_terminal();
this.term.dispose();
this.term = null;
} }
console.debug('---3--domoff event, destory this widget'); console.debug('---3--domoff event, destory this widget');
} }