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
|
|
@ -57,7 +57,11 @@ export class WebClient {
|
|||
public connect(options: WebSocketConnectOptions) {
|
||||
this.connectionAttemptMade = true;
|
||||
this.options = options;
|
||||
this.socket.connect(this.options);
|
||||
this.socket.connect(options);
|
||||
}
|
||||
|
||||
public testConnect(options: WebSocketConnectOptions) {
|
||||
this.socket.testConnect(options);
|
||||
}
|
||||
|
||||
public disconnect() {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ export class SessionCommands {
|
|||
case WebSocketConnectReason.PASSWORD_RESET:
|
||||
SessionCommands.updateStatus(StatusEnum.CONNECTING, 'Connecting...');
|
||||
break;
|
||||
case WebSocketConnectReason.TEST_CONNECTION:
|
||||
webClient.testConnect({ ...options });
|
||||
return;
|
||||
default:
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Attempt: ' + reason);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,14 @@ export class SessionPersistence {
|
|||
ServerDispatch.connectionFailed();
|
||||
}
|
||||
|
||||
static testConnectionSuccessful() {
|
||||
ServerDispatch.testConnectionSuccessful();
|
||||
}
|
||||
|
||||
static testConnectionFailed() {
|
||||
ServerDispatch.testConnectionFailed();
|
||||
}
|
||||
|
||||
static updateBuddyList(buddyList) {
|
||||
ServerDispatch.updateBuddyList(buddyList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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