Use human-readable names for websockets

This commit is contained in:
Fedor Indutny 2021-12-01 19:55:17 +01:00 committed by GitHub
parent 27f4dc6177
commit 84407cb005
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

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