From 6b9e3e458e7158f291ae4d6e1eccd7deb674bb89 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Jun 2024 17:37:12 +0200 Subject: [PATCH] refactor: improve types --- lib/server.ts | 7 ++++--- lib/socket.ts | 6 +++--- lib/userver.ts | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/server.ts b/lib/server.ts index 99b3f471..ba096f2e 100644 --- a/lib/server.ts +++ b/lib/server.ts @@ -160,7 +160,8 @@ function parseSessionId(data: string) { export abstract class BaseServer extends EventEmitter { public opts: ServerOptions; - protected clients: any; + // TODO for the next major release: use a Map instead + protected clients: Record; public clientsCount: number; protected middlewares: Middleware[] = []; @@ -590,7 +591,7 @@ export abstract class BaseServer extends EventEmitter { debug("upgrading existing transport"); const transport = new WebTransport(session, stream, reader); - client.maybeUpgrade(transport); + client._maybeUpgrade(transport); } } @@ -857,7 +858,7 @@ export class Server extends BaseServer { const transport = this.createTransport(req._query.transport, req); transport.perMessageDeflate = this.opts.perMessageDeflate; - client.maybeUpgrade(transport); + client._maybeUpgrade(transport); } } else { const closeConnection = (errorCode, errorContext) => diff --git a/lib/socket.ts b/lib/socket.ts index acdd0a61..0febe90e 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -26,8 +26,8 @@ export class Socket extends EventEmitter { public transport: Transport; private server: Server; - private upgrading = false; - private upgraded = false; + /* private */ upgrading = false; + /* private */ upgraded = false; private writeBuffer: Packet[] = []; private packetsFn: SendCallback[] = []; private sentCallbackFn: SendCallback[][] = []; @@ -264,7 +264,7 @@ export class Socket extends EventEmitter { * @param {Transport} transport * @api private */ - private maybeUpgrade(transport) { + /* private */ _maybeUpgrade(transport: Transport) { debug( 'might upgrade socket transport from "%s" to "%s"', this.transport.name, diff --git a/lib/userver.ts b/lib/userver.ts index 98380fbd..9d1eeb77 100644 --- a/lib/userver.ts +++ b/lib/userver.ts @@ -137,6 +137,7 @@ export class uServer extends BaseServer { if (req._query.sid) { debug("setting new request for existing client"); + // @ts-ignore this.clients[req._query.sid].transport.onRequest(req); } else { const closeConnection = (errorCode, errorContext) => @@ -194,7 +195,7 @@ export class uServer extends BaseServer { } else { debug("upgrading existing transport"); transport = this.createTransport(req._query.transport, req); - client.maybeUpgrade(transport); + client._maybeUpgrade(transport); } } else { transport = await this.handshake(