Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve websocket tester by telling the user that opening a websocket… #211

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/app/websocket-test/websockettest.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ as-split-area {

.success {
color: green;
fill: green;
font-weight: bold;
}

.error {
color: red;
fill: red;
font-weight: bold;
}
15 changes: 10 additions & 5 deletions src/app/websocket-test/websockettest.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ <h1>Websocket Tester</h1>
<li>Websocket responding with pong</li>
</ol>
<h2>Troubleshooting</h2>
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 }}
</as-split-area>

<as-split-area [size]="50" class="split-area-2">
Expand All @@ -38,6 +38,11 @@ <h1>Testing {{ target }}:</h1>
Check successfully completed and websocket reachable.
<cds-icon shape="success-standard" inverse class="success"></cds-icon>
</div>

<div *ngIf="error">
{{ error }}
<cds-icon shape="error-standard" inverse class="error"></cds-icon>
</div>
</as-split-area>
</as-split>
</div>
26 changes: 22 additions & 4 deletions src/app/websocket-test/websockettest.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class WebsocketTestComponent implements OnInit {
endpoint: string;

completed: boolean;
error: string;

mermaidString = 'sequenceDiagram';
markdownString = '';
Expand Down Expand Up @@ -44,35 +45,52 @@ 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(
from: string,
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```';
}
}
Loading