Use human-readable names for websockets
This commit is contained in:
parent
27f4dc6177
commit
84407cb005
4 changed files with 17 additions and 4 deletions
|
@ -756,7 +756,11 @@ export async function startApp(): Promise<void> {
|
|||
}
|
||||
|
||||
// This one should always be last - it could restart the app
|
||||
if (window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5')) {
|
||||
if (
|
||||
window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5') ||
|
||||
(window.isAfterVersion(lastVersion, 'v5.24.0-alpha') &&
|
||||
window.isBeforeVersion(lastVersion, 'v5.25.0'))
|
||||
) {
|
||||
await deleteAllLogs();
|
||||
window.restart();
|
||||
return;
|
||||
|
|
|
@ -67,6 +67,7 @@ export class CDSSocketManager {
|
|||
const url = `${this.options.url}/discovery/${publicKeyHex}/${codeHashHex}`;
|
||||
|
||||
return connectWebSocket<CDSSocket>({
|
||||
name: 'CDSSocket',
|
||||
url,
|
||||
version,
|
||||
proxyAgent: this.proxyAgent,
|
||||
|
|
|
@ -129,6 +129,7 @@ export class SocketManager extends EventListener {
|
|||
this.setStatus(SocketStatus.CONNECTING);
|
||||
|
||||
const process = this.connectResource({
|
||||
name: 'authenticated',
|
||||
path: '/v1/websocket/',
|
||||
query: { login: username, password },
|
||||
resourceOptions: {
|
||||
|
@ -253,6 +254,7 @@ export class SocketManager extends EventListener {
|
|||
handler: IRequestHandler
|
||||
): Promise<WebSocketResource> {
|
||||
return this.connectResource({
|
||||
name: 'provisioning',
|
||||
path: '/v1/websocket/provisioning/',
|
||||
resourceOptions: {
|
||||
handleRequest: (req: IncomingWebSocketRequest): void => {
|
||||
|
@ -426,6 +428,7 @@ export class SocketManager extends EventListener {
|
|||
log.info('SocketManager: connecting unauthenticated socket');
|
||||
|
||||
const process = this.connectResource({
|
||||
name: 'unauthenticated',
|
||||
path: '/v1/websocket/',
|
||||
resourceOptions: {
|
||||
keepalive: { path: '/v1/keepalive' },
|
||||
|
@ -464,10 +467,12 @@ export class SocketManager extends EventListener {
|
|||
}
|
||||
|
||||
private connectResource({
|
||||
name,
|
||||
path,
|
||||
resourceOptions,
|
||||
query = {},
|
||||
}: {
|
||||
name: string;
|
||||
path: string;
|
||||
resourceOptions: WebSocketResourceOptions;
|
||||
query?: Record<string, string>;
|
||||
|
@ -481,6 +486,7 @@ export class SocketManager extends EventListener {
|
|||
const url = `${this.options.url}${path}?${qs.encode(queryWithDefaults)}`;
|
||||
|
||||
return connectWebSocket({
|
||||
name,
|
||||
url,
|
||||
certificateAuthority: this.options.certificateAuthority,
|
||||
version: this.options.version,
|
||||
|
|
|
@ -22,6 +22,7 @@ export type IResource = {
|
|||
};
|
||||
|
||||
export type ConnectOptionsType<Resource extends IResource> = Readonly<{
|
||||
name: string;
|
||||
url: string;
|
||||
certificateAuthority: string;
|
||||
version: string;
|
||||
|
@ -32,6 +33,7 @@ export type ConnectOptionsType<Resource extends IResource> = Readonly<{
|
|||
}>;
|
||||
|
||||
export function connect<Resource extends IResource>({
|
||||
name,
|
||||
url,
|
||||
certificateAuthority,
|
||||
version,
|
||||
|
@ -109,14 +111,14 @@ export function connect<Resource extends IResource>({
|
|||
});
|
||||
|
||||
return new AbortableProcess<Resource>(
|
||||
`WebSocket.connect(${url})`,
|
||||
`WebSocket.connect(${name})`,
|
||||
{
|
||||
abort() {
|
||||
if (resource) {
|
||||
log.warn(`WebSocket: closing socket ${url}`);
|
||||
log.warn(`WebSocket: closing socket ${name}`);
|
||||
resource.close(3000, 'aborted');
|
||||
} else {
|
||||
log.warn(`WebSocket: aborting connection ${url}`);
|
||||
log.warn(`WebSocket: aborting connection ${name}`);
|
||||
Timers.clearTimeout(timer);
|
||||
client.abort();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue