Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a05042

Browse files
refactor: add additional typings
1 parent 91cd255 commit 2a05042

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

lib/client.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { IncomingMessage } from "http";
44
import { Server } from "./index";
55
import { Socket } from "./socket";
66
import { SocketId } from "socket.io-adapter";
7+
import { ParentNamespace } from "./parent-namespace";
78

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

1011
export class Client {
1112
public readonly conn;
1213

1314
private readonly id: string;
14-
private readonly server;
15+
private readonly server: Server;
1516
private readonly encoder: Encoder;
1617
private readonly decoder: Decoder;
1718
private sockets: Map<SocketId, Socket> = new Map();
@@ -83,7 +84,7 @@ export class Client {
8384
return this.doConnect(name, auth);
8485
}
8586

86-
this.server._checkNamespace(name, auth, dynamicNsp => {
87+
this.server._checkNamespace(name, auth, (dynamicNsp: ParentNamespace) => {
8788
if (dynamicNsp) {
8889
debug("dynamic namespace %s was created", dynamicNsp.name);
8990
this.doConnect(name, auth);
@@ -113,7 +114,7 @@ export class Client {
113114
}
114115
const nsp = this.server.of(name);
115116

116-
const socket = nsp.add(this, auth, () => {
117+
const socket = nsp._add(this, auth, () => {
117118
this.sockets.set(socket.id, socket);
118119
this.nsps.set(nsp.name, socket);
119120
});

lib/index.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ export class Server extends EventEmitter {
170170
) => void),
171171
ParentNamespace
172172
> = new Map();
173-
private _adapter;
173+
private _adapter: any;
174174
private _serveClient: boolean;
175175
private eio;
176176
private engine;
177177
private _path: string;
178-
private _connectTimeout: number;
178+
179+
/**
180+
* @private
181+
*/
182+
_connectTimeout: number;
179183
private httpServer: http.Server;
180184

181185
/**
@@ -211,7 +215,9 @@ export class Server extends EventEmitter {
211215
* @return {Server|Boolean} self when setting or value when getting
212216
* @public
213217
*/
214-
public serveClient(v?: boolean) {
218+
public serveClient(v: boolean): Server;
219+
public serveClient(): boolean;
220+
public serveClient(v?: boolean): Server | boolean {
215221
if (!arguments.length) return this._serveClient;
216222
this._serveClient = v;
217223
const resolvePath = function(file) {
@@ -280,7 +286,9 @@ export class Server extends EventEmitter {
280286
* @return {Server|String} self when setting or value when getting
281287
* @public
282288
*/
283-
public path(v?: string) {
289+
public path(v: string): Server;
290+
public path(): string;
291+
public path(v?: string): Server | string {
284292
if (!arguments.length) return this._path;
285293
this._path = v.replace(/\/$/, "");
286294
return this;
@@ -306,7 +314,9 @@ export class Server extends EventEmitter {
306314
* @return {Server|Adapter} self when setting or value when getting
307315
* @public
308316
*/
309-
public adapter(v) {
317+
public adapter(): any;
318+
public adapter(v: any);
319+
public adapter(v?): Server | any {
310320
if (!arguments.length) return this._adapter;
311321
this._adapter = v;
312322
for (const nsp of this._nsps.values()) {

lib/namespace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Namespace extends EventEmitter {
1515
public adapter: Adapter;
1616

1717
/** @private */
18-
readonly server;
18+
readonly server: Server;
1919

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

0 commit comments

Comments
 (0)