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
|
// 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();
|
await deleteAllLogs();
|
||||||
window.restart();
|
window.restart();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -67,6 +67,7 @@ export class CDSSocketManager {
|
||||||
const url = `${this.options.url}/discovery/${publicKeyHex}/${codeHashHex}`;
|
const url = `${this.options.url}/discovery/${publicKeyHex}/${codeHashHex}`;
|
||||||
|
|
||||||
return connectWebSocket<CDSSocket>({
|
return connectWebSocket<CDSSocket>({
|
||||||
|
name: 'CDSSocket',
|
||||||
url,
|
url,
|
||||||
version,
|
version,
|
||||||
proxyAgent: this.proxyAgent,
|
proxyAgent: this.proxyAgent,
|
||||||
|
|
|
@ -129,6 +129,7 @@ export class SocketManager extends EventListener {
|
||||||
this.setStatus(SocketStatus.CONNECTING);
|
this.setStatus(SocketStatus.CONNECTING);
|
||||||
|
|
||||||
const process = this.connectResource({
|
const process = this.connectResource({
|
||||||
|
name: 'authenticated',
|
||||||
path: '/v1/websocket/',
|
path: '/v1/websocket/',
|
||||||
query: { login: username, password },
|
query: { login: username, password },
|
||||||
resourceOptions: {
|
resourceOptions: {
|
||||||
|
@ -253,6 +254,7 @@ export class SocketManager extends EventListener {
|
||||||
handler: IRequestHandler
|
handler: IRequestHandler
|
||||||
): Promise<WebSocketResource> {
|
): Promise<WebSocketResource> {
|
||||||
return this.connectResource({
|
return this.connectResource({
|
||||||
|
name: 'provisioning',
|
||||||
path: '/v1/websocket/provisioning/',
|
path: '/v1/websocket/provisioning/',
|
||||||
resourceOptions: {
|
resourceOptions: {
|
||||||
handleRequest: (req: IncomingWebSocketRequest): void => {
|
handleRequest: (req: IncomingWebSocketRequest): void => {
|
||||||
|
@ -426,6 +428,7 @@ export class SocketManager extends EventListener {
|
||||||
log.info('SocketManager: connecting unauthenticated socket');
|
log.info('SocketManager: connecting unauthenticated socket');
|
||||||
|
|
||||||
const process = this.connectResource({
|
const process = this.connectResource({
|
||||||
|
name: 'unauthenticated',
|
||||||
path: '/v1/websocket/',
|
path: '/v1/websocket/',
|
||||||
resourceOptions: {
|
resourceOptions: {
|
||||||
keepalive: { path: '/v1/keepalive' },
|
keepalive: { path: '/v1/keepalive' },
|
||||||
|
@ -464,10 +467,12 @@ export class SocketManager extends EventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private connectResource({
|
private connectResource({
|
||||||
|
name,
|
||||||
path,
|
path,
|
||||||
resourceOptions,
|
resourceOptions,
|
||||||
query = {},
|
query = {},
|
||||||
}: {
|
}: {
|
||||||
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
resourceOptions: WebSocketResourceOptions;
|
resourceOptions: WebSocketResourceOptions;
|
||||||
query?: Record<string, string>;
|
query?: Record<string, string>;
|
||||||
|
@ -481,6 +486,7 @@ export class SocketManager extends EventListener {
|
||||||
const url = `${this.options.url}${path}?${qs.encode(queryWithDefaults)}`;
|
const url = `${this.options.url}${path}?${qs.encode(queryWithDefaults)}`;
|
||||||
|
|
||||||
return connectWebSocket({
|
return connectWebSocket({
|
||||||
|
name,
|
||||||
url,
|
url,
|
||||||
certificateAuthority: this.options.certificateAuthority,
|
certificateAuthority: this.options.certificateAuthority,
|
||||||
version: this.options.version,
|
version: this.options.version,
|
||||||
|
|
|
@ -22,6 +22,7 @@ export type IResource = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ConnectOptionsType<Resource extends IResource> = Readonly<{
|
export type ConnectOptionsType<Resource extends IResource> = Readonly<{
|
||||||
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
certificateAuthority: string;
|
certificateAuthority: string;
|
||||||
version: string;
|
version: string;
|
||||||
|
@ -32,6 +33,7 @@ export type ConnectOptionsType<Resource extends IResource> = Readonly<{
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export function connect<Resource extends IResource>({
|
export function connect<Resource extends IResource>({
|
||||||
|
name,
|
||||||
url,
|
url,
|
||||||
certificateAuthority,
|
certificateAuthority,
|
||||||
version,
|
version,
|
||||||
|
@ -109,14 +111,14 @@ export function connect<Resource extends IResource>({
|
||||||
});
|
});
|
||||||
|
|
||||||
return new AbortableProcess<Resource>(
|
return new AbortableProcess<Resource>(
|
||||||
`WebSocket.connect(${url})`,
|
`WebSocket.connect(${name})`,
|
||||||
{
|
{
|
||||||
abort() {
|
abort() {
|
||||||
if (resource) {
|
if (resource) {
|
||||||
log.warn(`WebSocket: closing socket ${url}`);
|
log.warn(`WebSocket: closing socket ${name}`);
|
||||||
resource.close(3000, 'aborted');
|
resource.close(3000, 'aborted');
|
||||||
} else {
|
} else {
|
||||||
log.warn(`WebSocket: aborting connection ${url}`);
|
log.warn(`WebSocket: aborting connection ${name}`);
|
||||||
Timers.clearTimeout(timer);
|
Timers.clearTimeout(timer);
|
||||||
client.abort();
|
client.abort();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue