@@ -4,6 +4,7 @@ import { IncomingMessage } from "http";
4
4
import { Transport } from "./transport" ;
5
5
import { Server } from "./server" ;
6
6
import { setTimeout , clearTimeout } from "timers" ;
7
+ import { Packet , PacketType , RawData } from "engine.io-parser" ;
7
8
8
9
const debug = debugModule ( "engine:socket" ) ;
9
10
@@ -18,7 +19,7 @@ export class Socket extends EventEmitter {
18
19
private server : Server ;
19
20
private upgrading : boolean ;
20
21
private upgraded : boolean ;
21
- private writeBuffer : any [ ] ;
22
+ private writeBuffer : Packet [ ] ;
22
23
private packetsFn : any [ ] ;
23
24
private sentCallbackFn : any [ ] ;
24
25
private cleanupFn : any [ ] ;
@@ -116,7 +117,7 @@ export class Socket extends EventEmitter {
116
117
* @param {Object } packet
117
118
* @api private
118
119
*/
119
- private onPacket ( packet ) {
120
+ private onPacket ( packet : Packet ) {
120
121
if ( "open" !== this . readyState ) {
121
122
return debug ( "packet received with closed socket" ) ;
122
123
}
@@ -417,7 +418,7 @@ export class Socket extends EventEmitter {
417
418
/**
418
419
* Sends a message packet.
419
420
*
420
- * @param {String } message
421
+ * @param {Object } data
421
422
* @param {Object } options
422
423
* @param {Function } callback
423
424
* @return {Socket } for chaining
@@ -436,12 +437,14 @@ export class Socket extends EventEmitter {
436
437
/**
437
438
* Sends a packet.
438
439
*
439
- * @param {String } packet type
440
- * @param {String } optional, data
440
+ * @param {String } type - packet type
441
+ * @param {String } data
441
442
* @param {Object } options
443
+ * @param {Function } callback
444
+ *
442
445
* @api private
443
446
*/
444
- private sendPacket ( type , data ?, options ?, callback ?) {
447
+ private sendPacket ( type : PacketType , data ?: RawData , options ?, callback ?) {
445
448
if ( "function" === typeof options ) {
446
449
callback = options ;
447
450
options = null ;
@@ -453,10 +456,11 @@ export class Socket extends EventEmitter {
453
456
if ( "closing" !== this . readyState && "closed" !== this . readyState ) {
454
457
debug ( 'sending packet "%s" (%s)' , type , data ) ;
455
458
456
- const packet : any = {
457
- type : type ,
458
- options : options
459
+ const packet : Packet = {
460
+ type,
461
+ options
459
462
} ;
463
+
460
464
if ( data ) packet . data = data ;
461
465
462
466
// exports packetCreate event
0 commit comments