Skip to content

Commit

Permalink
refactor: add additional typings
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Oct 15, 2020
1 parent 91cd255 commit 2a05042
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
7 changes: 4 additions & 3 deletions lib/client.ts
Expand Up @@ -4,14 +4,15 @@ import { IncomingMessage } from "http";
import { Server } from "./index";
import { Socket } from "./socket";
import { SocketId } from "socket.io-adapter";
import { ParentNamespace } from "./parent-namespace";

const debug = debugModule("socket.io:client");

export class Client {
public readonly conn;

private readonly id: string;
private readonly server;
private readonly server: Server;
private readonly encoder: Encoder;
private readonly decoder: Decoder;
private sockets: Map<SocketId, Socket> = new Map();
Expand Down Expand Up @@ -83,7 +84,7 @@ export class Client {
return this.doConnect(name, auth);
}

this.server._checkNamespace(name, auth, dynamicNsp => {
this.server._checkNamespace(name, auth, (dynamicNsp: ParentNamespace) => {
if (dynamicNsp) {
debug("dynamic namespace %s was created", dynamicNsp.name);
this.doConnect(name, auth);
Expand Down Expand Up @@ -113,7 +114,7 @@ export class Client {
}
const nsp = this.server.of(name);

const socket = nsp.add(this, auth, () => {
const socket = nsp._add(this, auth, () => {
this.sockets.set(socket.id, socket);
this.nsps.set(nsp.name, socket);
});
Expand Down
20 changes: 15 additions & 5 deletions lib/index.ts
Expand Up @@ -170,12 +170,16 @@ export class Server extends EventEmitter {
) => void),
ParentNamespace
> = new Map();
private _adapter;
private _adapter: any;
private _serveClient: boolean;
private eio;
private engine;
private _path: string;
private _connectTimeout: number;

/**
* @private
*/
_connectTimeout: number;
private httpServer: http.Server;

/**
Expand Down Expand Up @@ -211,7 +215,9 @@ export class Server extends EventEmitter {
* @return {Server|Boolean} self when setting or value when getting
* @public
*/
public serveClient(v?: boolean) {
public serveClient(v: boolean): Server;
public serveClient(): boolean;
public serveClient(v?: boolean): Server | boolean {
if (!arguments.length) return this._serveClient;
this._serveClient = v;
const resolvePath = function(file) {
Expand Down Expand Up @@ -280,7 +286,9 @@ export class Server extends EventEmitter {
* @return {Server|String} self when setting or value when getting
* @public
*/
public path(v?: string) {
public path(v: string): Server;
public path(): string;
public path(v?: string): Server | string {
if (!arguments.length) return this._path;
this._path = v.replace(/\/$/, "");
return this;
Expand All @@ -306,7 +314,9 @@ export class Server extends EventEmitter {
* @return {Server|Adapter} self when setting or value when getting
* @public
*/
public adapter(v) {
public adapter(): any;
public adapter(v: any);
public adapter(v?): Server | any {
if (!arguments.length) return this._adapter;
this._adapter = v;
for (const nsp of this._nsps.values()) {
Expand Down
4 changes: 2 additions & 2 deletions lib/namespace.ts
Expand Up @@ -15,7 +15,7 @@ export class Namespace extends EventEmitter {
public adapter: Adapter;

/** @private */
readonly server;
readonly server: Server;

/** @private */
_fns: Array<(socket: Socket, next: (err: Error) => void) => void> = [];
Expand Down Expand Up @@ -126,7 +126,7 @@ export class Namespace extends EventEmitter {
* @return {Socket}
* @private
*/
private add(client: Client, query, fn?: () => void): Socket {
_add(client: Client, query, fn?: () => void): Socket {
debug("adding socket to nsp %s", this.name);
const socket = new Socket(this, client, query);
this.run(socket, err => {
Expand Down

0 comments on commit 2a05042

Please sign in to comment.