From 4391c547df23d8e782555cee3bbf231fb5ce5415 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan-Gerrit=20G=C3=B6bel?=
<86782124+jggoebel@users.noreply.github.com>
Date: Thu, 10 Oct 2024 16:27:02 +0200
Subject: [PATCH] Improve websocket tester by telling the user that opening a
websocket has failed (#211)
---
.../websockettest.component.css | 7 +++++
.../websockettest.component.html | 15 +++++++----
.../websocket-test/websockettest.component.ts | 26 ++++++++++++++++---
3 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/src/app/websocket-test/websockettest.component.css b/src/app/websocket-test/websockettest.component.css
index a783587..6b72d5c 100644
--- a/src/app/websocket-test/websockettest.component.css
+++ b/src/app/websocket-test/websockettest.component.css
@@ -4,5 +4,12 @@ as-split-area {
.success {
color: green;
+ fill: green;
+ font-weight: bold;
+}
+
+.error {
+ color: red;
+ fill: red;
font-weight: bold;
}
diff --git a/src/app/websocket-test/websockettest.component.html b/src/app/websocket-test/websockettest.component.html
index d7f3361..4a08aac 100644
--- a/src/app/websocket-test/websockettest.component.html
+++ b/src/app/websocket-test/websockettest.component.html
@@ -20,11 +20,11 @@
Websocket Tester
Websocket responding with pong
Troubleshooting
- If the /healthz endopoint is not responding you should check if the shell
- proxy is up and running. Also verify that {{ endpoint }} is the correct
- URL to the proxy. If the endpoint responds with 200 but the websocket is
- not being opened, you should verify that no firewall is in place that
- disallows the usage of websockets for {{ endpoint }}
+ If the /healthz endpoint is not responding you should check if the shell
+ proxy is up and running. Also verify that {{ target }} is the correct URL
+ to the proxy. If the endpoint responds with 200 but the websocket is not
+ being opened, you should verify that no firewall is in place that
+ disallows the usage of websockets for {{ target }}
@@ -38,6 +38,11 @@ Testing {{ target }}:
Check successfully completed and websocket reachable.
+
+
+ {{ error }}
+
+
diff --git a/src/app/websocket-test/websockettest.component.ts b/src/app/websocket-test/websockettest.component.ts
index 5ed0487..a9918cc 100644
--- a/src/app/websocket-test/websockettest.component.ts
+++ b/src/app/websocket-test/websockettest.component.ts
@@ -15,6 +15,7 @@ export class WebsocketTestComponent implements OnInit {
endpoint: string;
completed: boolean;
+ error: string;
mermaidString = 'sequenceDiagram';
markdownString = '';
@@ -44,26 +45,41 @@ export class WebsocketTestComponent implements OnInit {
},
error: (msg) => {
console.log(msg);
+ this.error = 'The Health Endpoint delivered a status other than 200.';
this.addMermaidString(this.target, 'you', msg.code);
},
});
}
testWSConnection() {
- this.addMermaidString('you', this.target, 'open websocket', '+');
const socket = new WebSocket(this.wsEndpoint);
+
+ socket.onerror = () => {
+ this.error = 'The Websocket could not be opened.';
+ this.addMermaidString(
+ 'you',
+ this.target,
+ 'opening websocket failed',
+ '',
+ 'x',
+ );
+ };
+
socket.onmessage = (event) => {
if (event.data == 'pong') {
this.addMermaidString(this.target, 'you', 'pong', '-');
- this.completed = true;
}
};
socket.onopen = () => {
- this.addMermaidString(this.target, 'you', 'websocket opened');
+ this.addMermaidString('you', this.target, 'open websocket', '+');
socket.send('ping');
this.addMermaidString('you', this.target, 'ping');
};
+
+ socket.onclose = (event) => {
+ this.completed = true;
+ };
}
addMermaidString(
@@ -71,8 +87,10 @@ export class WebsocketTestComponent implements OnInit {
to: string,
content: string,
opChar: string = '',
+ arrowChar: string = '>>',
) {
- this.mermaidString += '\n ' + from + '->>' + opChar + to + ': ' + content;
+ this.mermaidString +=
+ '\n ' + from + '-' + arrowChar + opChar + to + ': ' + content;
this.markdownString = '```mermaid\n' + this.mermaidString + '\n```';
}
}