mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
test connection UI (#4596)
* test connection UI * cleanup Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
parent
00a2a8ab71
commit
0ff59e6d1e
11 changed files with 169 additions and 22 deletions
|
|
@ -38,6 +38,16 @@ export class WebSocketService {
|
|||
this.socket = this.createWebSocket(`${protocol}://${host}:${port}`);
|
||||
}
|
||||
|
||||
public testConnect(options: WebSocketConnectOptions, protocol: string = 'wss'): void {
|
||||
if (window.location.hostname === 'localhost') {
|
||||
protocol = 'ws';
|
||||
}
|
||||
|
||||
const { host, port } = options;
|
||||
|
||||
this.testWebSocket(`${protocol}://${host}:${port}`);
|
||||
}
|
||||
|
||||
public disconnect(): void {
|
||||
if (this.socket) {
|
||||
this.socket.close();
|
||||
|
|
@ -92,4 +102,21 @@ export class WebSocketService {
|
|||
|
||||
return socket;
|
||||
}
|
||||
|
||||
private testWebSocket(url: string): void {
|
||||
const socket = new WebSocket(url);
|
||||
socket.binaryType = 'arraybuffer';
|
||||
|
||||
const connectionTimer = setTimeout(() => socket.close(), this.webClient.clientOptions.keepalive);
|
||||
|
||||
socket.onopen = () => {
|
||||
clearTimeout(connectionTimer);
|
||||
SessionPersistence.testConnectionSuccessful();
|
||||
socket.close();
|
||||
};
|
||||
|
||||
socket.onerror = () => {
|
||||
SessionPersistence.testConnectionFailed();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue