@@ -191,6 +191,10 @@ export class Server extends EventEmitter {
191
191
*/
192
192
constructor ( opts ?: Partial < ServerOptions > ) ;
193
193
constructor ( srv ?: http . Server | number , opts ?: Partial < ServerOptions > ) ;
194
+ constructor (
195
+ srv : undefined | Partial < ServerOptions > | http . Server | number ,
196
+ opts ?: Partial < ServerOptions >
197
+ ) ;
194
198
constructor (
195
199
srv : undefined | Partial < ServerOptions > | http . Server | number ,
196
200
opts : Partial < ServerOptions > = { }
@@ -222,9 +226,10 @@ export class Server extends EventEmitter {
222
226
* @return self when setting or value when getting
223
227
* @public
224
228
*/
225
- public serveClient ( v : boolean ) : Server ;
229
+ public serveClient ( v : boolean ) : this ;
226
230
public serveClient ( ) : boolean ;
227
- public serveClient ( v ?: boolean ) : Server | boolean {
231
+ public serveClient ( v ?: boolean ) : this | boolean ;
232
+ public serveClient ( v ?: boolean ) : this | boolean {
228
233
if ( ! arguments . length ) return this . _serveClient ;
229
234
this . _serveClient = v ! ;
230
235
return this ;
@@ -234,7 +239,7 @@ export class Server extends EventEmitter {
234
239
* Executes the middleware for an incoming namespace not already created on the server.
235
240
*
236
241
* @param name - name of incoming namespace
237
- * @param { Object } auth - the auth parameters
242
+ * @param auth - the auth parameters
238
243
* @param fn - callback
239
244
*
240
245
* @private
@@ -243,7 +248,7 @@ export class Server extends EventEmitter {
243
248
name : string ,
244
249
auth : object ,
245
250
fn : ( nsp : Namespace | false ) => void
246
- ) {
251
+ ) : void {
247
252
if ( this . parentNsps . size === 0 ) return fn ( false ) ;
248
253
249
254
const keysIterator = this . parentNsps . keys ( ) ;
@@ -272,9 +277,10 @@ export class Server extends EventEmitter {
272
277
* @return {Server|String } self when setting or value when getting
273
278
* @public
274
279
*/
275
- public path ( v : string ) : Server ;
280
+ public path ( v : string ) : this ;
276
281
public path ( ) : string ;
277
- public path ( v ?: string ) : Server | string {
282
+ public path ( v ?: string ) : this | string ;
283
+ public path ( v ?: string ) : this | string {
278
284
if ( ! arguments . length ) return this . _path ;
279
285
280
286
this . _path = v ! . replace ( / \/ $ / , "" ) ;
@@ -293,9 +299,10 @@ export class Server extends EventEmitter {
293
299
* @param v
294
300
* @public
295
301
*/
296
- public connectTimeout ( v : number ) : Server ;
302
+ public connectTimeout ( v : number ) : this ;
297
303
public connectTimeout ( ) : number ;
298
- public connectTimeout ( v ?: number ) : Server | number {
304
+ public connectTimeout ( v ?: number ) : this | number ;
305
+ public connectTimeout ( v ?: number ) : this | number {
299
306
if ( v === undefined ) return this . _connectTimeout ;
300
307
this . _connectTimeout = v ;
301
308
return this ;
@@ -309,8 +316,9 @@ export class Server extends EventEmitter {
309
316
* @public
310
317
*/
311
318
public adapter ( ) : typeof Adapter | undefined ;
312
- public adapter ( v : typeof Adapter ) : Server ;
313
- public adapter ( v ?: typeof Adapter ) : typeof Adapter | undefined | Server {
319
+ public adapter ( v : typeof Adapter ) : this;
320
+ public adapter ( v ?: typeof Adapter ) : typeof Adapter | undefined | this;
321
+ public adapter ( v ?: typeof Adapter ) : typeof Adapter | undefined | this {
314
322
if ( ! arguments . length ) return this . _adapter ;
315
323
this . _adapter = v ;
316
324
for ( const nsp of this . _nsps . values ( ) ) {
@@ -330,7 +338,7 @@ export class Server extends EventEmitter {
330
338
public listen (
331
339
srv : http . Server | number ,
332
340
opts : Partial < ServerOptions > = { }
333
- ) : Server {
341
+ ) : this {
334
342
return this . attach ( srv , opts ) ;
335
343
}
336
344
@@ -345,7 +353,7 @@ export class Server extends EventEmitter {
345
353
public attach (
346
354
srv : http . Server | number ,
347
355
opts : Partial < ServerOptions > = { }
348
- ) : Server {
356
+ ) : this {
349
357
if ( "function" == typeof srv ) {
350
358
const msg =
351
359
"You are trying to attach socket.io to an express " +
@@ -385,7 +393,10 @@ export class Server extends EventEmitter {
385
393
* @param opts - options passed to engine.io
386
394
* @private
387
395
*/
388
- private initEngine ( srv : http . Server , opts : Partial < EngineAttachOptions > ) {
396
+ private initEngine (
397
+ srv : http . Server ,
398
+ opts : Partial < EngineAttachOptions >
399
+ ) : void {
389
400
// initialize engine
390
401
debug ( "creating engine.io instance with opts %j" , opts ) ;
391
402
this . eio = engine . attach ( srv , opts ) ;
@@ -406,7 +417,7 @@ export class Server extends EventEmitter {
406
417
* @param srv http server
407
418
* @private
408
419
*/
409
- private attachServe ( srv : http . Server ) {
420
+ private attachServe ( srv : http . Server ) : void {
410
421
debug ( "attaching client serving req handler" ) ;
411
422
412
423
const evs = srv . listeners ( "request" ) . slice ( 0 ) ;
@@ -429,7 +440,7 @@ export class Server extends EventEmitter {
429
440
* @param res
430
441
* @private
431
442
*/
432
- private serve ( req : http . IncomingMessage , res : http . ServerResponse ) {
443
+ private serve ( req : http . IncomingMessage , res : http . ServerResponse ) : void {
433
444
const filename = req . url ! . replace ( this . _path , "" ) ;
434
445
const isMap = dotMapRegex . test ( filename ) ;
435
446
const type = isMap ? "map" : "source" ;
@@ -474,7 +485,7 @@ export class Server extends EventEmitter {
474
485
filename : string ,
475
486
req : http . IncomingMessage ,
476
487
res : http . ServerResponse
477
- ) {
488
+ ) : void {
478
489
const readStream = createReadStream (
479
490
path . join ( __dirname , "../client-dist/" , filename )
480
491
) ;
@@ -513,7 +524,7 @@ export class Server extends EventEmitter {
513
524
* @return self
514
525
* @public
515
526
*/
516
- public bind ( engine ) : Server {
527
+ public bind ( engine ) : this {
517
528
this . engine = engine ;
518
529
this . engine . on ( "connection" , this . onconnection . bind ( this ) ) ;
519
530
return this ;
@@ -526,7 +537,7 @@ export class Server extends EventEmitter {
526
537
* @return self
527
538
* @private
528
539
*/
529
- private onconnection ( conn ) : Server {
540
+ private onconnection ( conn ) : this {
530
541
debug ( "incoming connection with id %s" , conn . id ) ;
531
542
const client = new Client ( this , conn ) ;
532
543
if ( conn . protocol === 3 ) {
@@ -540,13 +551,13 @@ export class Server extends EventEmitter {
540
551
* Looks up a namespace.
541
552
*
542
553
* @param {String|RegExp|Function } name nsp name
543
- * @param [fn] optional, nsp `connection` ev handler
554
+ * @param fn optional, nsp `connection` ev handler
544
555
* @public
545
556
*/
546
557
public of (
547
558
name : string | RegExp | ParentNspNameMatchFn ,
548
559
fn ?: ( socket : Socket ) => void
549
- ) {
560
+ ) : Namespace {
550
561
if ( typeof name === "function" || name instanceof RegExp ) {
551
562
const parentNsp = new ParentNamespace ( this ) ;
552
563
debug ( "initializing parent namespace %s" , parentNsp . name ) ;
@@ -605,7 +616,7 @@ export class Server extends EventEmitter {
605
616
*/
606
617
public use (
607
618
fn : ( socket : Socket , next : ( err ?: ExtendedError ) => void ) => void
608
- ) : Server {
619
+ ) : this {
609
620
this . sockets . use ( fn ) ;
610
621
return this ;
611
622
}
@@ -617,7 +628,7 @@ export class Server extends EventEmitter {
617
628
* @return self
618
629
* @public
619
630
*/
620
- public to ( name : Room ) : Server {
631
+ public to ( name : Room ) : this {
621
632
this . sockets . to ( name ) ;
622
633
return this ;
623
634
}
@@ -629,7 +640,7 @@ export class Server extends EventEmitter {
629
640
* @return self
630
641
* @public
631
642
*/
632
- public in ( name : Room ) : Server {
643
+ public in ( name : Room ) : this {
633
644
this . sockets . in ( name ) ;
634
645
return this ;
635
646
}
@@ -640,7 +651,7 @@ export class Server extends EventEmitter {
640
651
* @return self
641
652
* @public
642
653
*/
643
- public send ( ...args : readonly any [ ] ) : Server {
654
+ public send ( ...args : readonly any [ ] ) : this {
644
655
this . sockets . emit ( "message" , ...args ) ;
645
656
return this ;
646
657
}
@@ -651,7 +662,7 @@ export class Server extends EventEmitter {
651
662
* @return self
652
663
* @public
653
664
*/
654
- public write ( ...args : readonly any [ ] ) : Server {
665
+ public write ( ...args : readonly any [ ] ) : this {
655
666
this . sockets . emit ( "message" , ...args ) ;
656
667
return this ;
657
668
}
@@ -672,7 +683,7 @@ export class Server extends EventEmitter {
672
683
* @return self
673
684
* @public
674
685
*/
675
- public compress ( compress : boolean ) : Server {
686
+ public compress ( compress : boolean ) : this {
676
687
this . sockets . compress ( compress ) ;
677
688
return this ;
678
689
}
@@ -685,7 +696,7 @@ export class Server extends EventEmitter {
685
696
* @return self
686
697
* @public
687
698
*/
688
- public get volatile ( ) : Server {
699
+ public get volatile ( ) : this {
689
700
this . sockets . volatile ;
690
701
return this ;
691
702
}
@@ -696,7 +707,7 @@ export class Server extends EventEmitter {
696
707
* @return self
697
708
* @public
698
709
*/
699
- public get local ( ) : Server {
710
+ public get local ( ) : this {
700
711
this . sockets . local ;
701
712
return this ;
702
713
}
0 commit comments