Skip to content

Commit

Permalink
refactor: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Jun 18, 2024
1 parent f521cba commit 6b9e3e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Socket>;
public clientsCount: number;
protected middlewares: Middleware[] = [];

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) =>
Expand Down
6 changes: 3 additions & 3 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[][] = [];
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/userver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6b9e3e4

Please sign in to comment.