@@ -8,6 +8,10 @@ import { Packet, PacketType, RawData } from "engine.io-parser";
8
8
9
9
const debug = debugModule ( "engine:socket" ) ;
10
10
11
+ export interface SendOptions {
12
+ compress ?: boolean ;
13
+ }
14
+
11
15
export class Socket extends EventEmitter {
12
16
public readonly protocol : number ;
13
17
// TODO for the next major release: do not keep the reference to the first HTTP request, as it stays in memory
@@ -432,11 +436,7 @@ export class Socket extends EventEmitter {
432
436
* @return {Socket } for chaining
433
437
* @api public
434
438
*/
435
- public send (
436
- data : RawData ,
437
- options ?: { compress : boolean } ,
438
- callback ?: ( ) => void
439
- ) {
439
+ public send ( data : RawData , options ?: SendOptions , callback ?: ( ) => void ) {
440
440
this . sendPacket ( "message" , data , options , callback ) ;
441
441
return this ;
442
442
}
@@ -448,11 +448,7 @@ export class Socket extends EventEmitter {
448
448
* @param options
449
449
* @param callback
450
450
*/
451
- public write (
452
- data : RawData ,
453
- options ?: { compress : boolean } ,
454
- callback ?: ( ) => void
455
- ) {
451
+ public write ( data : RawData , options ?: SendOptions , callback ?: ( ) => void ) {
456
452
this . sendPacket ( "message" , data , options , callback ) ;
457
453
return this ;
458
454
}
@@ -470,20 +466,23 @@ export class Socket extends EventEmitter {
470
466
private sendPacket (
471
467
type : PacketType ,
472
468
data ?: RawData ,
473
- options : { compress : boolean } = { compress : true } ,
469
+ options : SendOptions = { } ,
474
470
callback ?: ( ) => void
475
471
) {
476
472
if ( "function" === typeof options ) {
477
473
callback = options ;
478
- options = null ;
474
+ options = { } ;
479
475
}
480
476
481
477
if ( "closing" !== this . readyState && "closed" !== this . readyState ) {
482
478
debug ( 'sending packet "%s" (%s)' , type , data ) ;
483
479
480
+ // compression is enabled by default
481
+ options . compress = options . compress !== false ;
482
+
484
483
const packet : Packet = {
485
484
type,
486
- options,
485
+ options : options as { compress : boolean } ,
487
486
} ;
488
487
489
488
if ( data ) packet . data = data ;
0 commit comments