Use human-readable names for websockets

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2021-12-01 11:15:32 -08:00 committed by GitHub
parent bec88d5940
commit 57daf0762a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View File

@ -749,7 +749,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;

View File

@ -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,

View File

@ -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,

View File

@ -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();
}