@@ -6,6 +6,14 @@ import { Server } from "./server";
6
6
7
7
const debug = debugModule ( "engine:socket" ) ;
8
8
9
+ type PacketType = "error" | "message" | "open" | "ping" | "pong" ;
10
+
11
+ export interface Packet {
12
+ type : PacketType ;
13
+ options : { compress : boolean } ;
14
+ data ?: any ;
15
+ }
16
+
9
17
export class Socket extends EventEmitter {
10
18
public readonly protocol : number ;
11
19
public readonly request : IncomingMessage ;
@@ -115,7 +123,7 @@ export class Socket extends EventEmitter {
115
123
* @param {Object } packet
116
124
* @api private
117
125
*/
118
- private onPacket ( packet ) {
126
+ private onPacket ( packet : Packet ) {
119
127
if ( "open" !== this . readyState ) {
120
128
return debug ( "packet received with closed socket" ) ;
121
129
}
@@ -440,7 +448,7 @@ export class Socket extends EventEmitter {
440
448
* @param {Object } options
441
449
* @api private
442
450
*/
443
- private sendPacket ( type , data ?, options ?, callback ?) {
451
+ private sendPacket ( type : PacketType , data ?, options ?, callback ?) {
444
452
if ( "function" === typeof options ) {
445
453
callback = options ;
446
454
options = null ;
@@ -452,10 +460,11 @@ export class Socket extends EventEmitter {
452
460
if ( "closing" !== this . readyState && "closed" !== this . readyState ) {
453
461
debug ( 'sending packet "%s" (%s)' , type , data ) ;
454
462
455
- const packet : any = {
456
- type : type ,
457
- options : options
463
+ const packet : Packet = {
464
+ type,
465
+ options
458
466
} ;
467
+
459
468
if ( data ) packet . data = data ;
460
469
461
470
// exports packetCreate event
0 commit comments