From 7cacd355989b554d4966c9cbc82d3498e0c4e50f Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 12 Sep 2025 15:03:44 +0800 Subject: [PATCH] bugfix --- bricks/wterm.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/bricks/wterm.js b/bricks/wterm.js index 1621cc8..7880993 100644 --- a/bricks/wterm.js +++ b/bricks/wterm.js @@ -17,6 +17,29 @@ bricks.Wterm = class extends bricks.JsWidget { this.bind('domon', this.send_term_size.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(){ console.debug('------domoff event, destory this widget'); try { @@ -28,20 +51,11 @@ bricks.Wterm = class extends bricks.JsWidget { } console.debug('---1--domoff event, destory this widget'); if (this.socket){ - 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; + this.close_websocket(); } console.debug('---2--domoff event, destory this widget'); if (this.term){ - this.fitAddon.dispose(); - this.term.dispose(); - this.term = null; + this.close_terminal(); } console.debug('---3--domoff event, destory this widget'); }