diff options
author | Xiaochao Ma <maxiaochao@inspur.com> | 2022-03-08 15:13:00 +0300 |
---|---|---|
committer | Xiaochao Ma <maxiaochao@inspur.com> | 2022-03-09 03:48:48 +0300 |
commit | 78372d6345cf5f1e04d6a8d56c416a7aec70b998 (patch) | |
tree | 273eb1624c271750d5936b089ea9d3f4a7f358cd /src/views/Operations | |
parent | 19b2cfba7323b8327266063411e4fae4c966b17e (diff) | |
download | webui-vue-78372d6345cf5f1e04d6a8d56c416a7aec70b998.tar.xz |
SOL: fix socket close exception
When the sol page is opened, a socket is opened;
when the sol page is closed, the socket is not closed
(console print is also exception).
It only closes when you log out.
Fix this condition to 'close socket when SOL page is exited'.
test:
Enter the SOL page-->console print'websocket console0/ opened'
-->close the SOL page
-->console print'websocket console0/ closed. code: 1000 reason: '
Signed-off-by: Xiaochao Ma <maxiaochao@inspur.com>
Change-Id: I0f406c2085aec303d6e5139d57b31ed6f244a155
Diffstat (limited to 'src/views/Operations')
-rw-r--r-- | src/views/Operations/SerialOverLan/SerialOverLanConsole.vue | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue b/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue index ce8549df..694083fd 100644 --- a/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue +++ b/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue @@ -85,37 +85,38 @@ export default { }, beforeDestroy() { window.removeEventListener('resize', this.resizeConsoleWindow); + this.closeTerminal(); }, methods: { openTerminal() { const token = this.$store.getters['authentication/token']; - const ws = new WebSocket(`wss://${window.location.host}/console0`, [ + this.ws = new WebSocket(`wss://${window.location.host}/console0`, [ token, ]); // Refer https://github.com/xtermjs/xterm.js/ for xterm implementation and addons. - const term = new Terminal({ + this.term = new Terminal({ fontSize: 15, fontFamily: 'SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace', }); - const attachAddon = new AttachAddon(ws); - term.loadAddon(attachAddon); + const attachAddon = new AttachAddon(this.ws); + this.term.loadAddon(attachAddon); const fitAddon = new FitAddon(); - term.loadAddon(fitAddon); + this.term.loadAddon(fitAddon); const SOL_THEME = { background: '#19273c', cursor: 'rgba(83, 146, 255, .5)', scrollbar: 'rgba(83, 146, 255, .5)', }; - term.setOption('theme', SOL_THEME); + this.term.setOption('theme', SOL_THEME); - term.open(this.$refs.panel); + this.term.open(this.$refs.panel); fitAddon.fit(); this.resizeConsoleWindow = throttle(() => { @@ -124,10 +125,10 @@ export default { window.addEventListener('resize', this.resizeConsoleWindow); try { - ws.onopen = function () { + this.ws.onopen = function () { console.log('websocket console0/ opened'); }; - ws.onclose = function (event) { + this.ws.onclose = function (event) { console.log( 'websocket console0/ closed. code: ' + event.code + @@ -139,6 +140,13 @@ export default { console.log(error); } }, + closeTerminal() { + console.log('closeTerminal'); + this.term.dispose(); + this.term = null; + this.ws.close(); + this.ws = null; + }, openConsoleWindow() { window.open( '#/console/serial-over-lan-console', |