Skip to content

Commit 69603b9

Browse files
refactor: make the compress option optional
The compress option was inadvertently made mandatory in [1]. [1]: 6d87a40
1 parent ae1ea77 commit 69603b9

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lib/socket.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { Packet, PacketType, RawData } from "engine.io-parser";
88

99
const debug = debugModule("engine:socket");
1010

11+
export interface SendOptions {
12+
compress?: boolean;
13+
}
14+
1115
export class Socket extends EventEmitter {
1216
public readonly protocol: number;
1317
// 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 {
432436
* @return {Socket} for chaining
433437
* @api public
434438
*/
435-
public send(
436-
data: RawData,
437-
options?: { compress: boolean },
438-
callback?: () => void
439-
) {
439+
public send(data: RawData, options?: SendOptions, callback?: () => void) {
440440
this.sendPacket("message", data, options, callback);
441441
return this;
442442
}
@@ -448,11 +448,7 @@ export class Socket extends EventEmitter {
448448
* @param options
449449
* @param callback
450450
*/
451-
public write(
452-
data: RawData,
453-
options?: { compress: boolean },
454-
callback?: () => void
455-
) {
451+
public write(data: RawData, options?: SendOptions, callback?: () => void) {
456452
this.sendPacket("message", data, options, callback);
457453
return this;
458454
}
@@ -470,20 +466,23 @@ export class Socket extends EventEmitter {
470466
private sendPacket(
471467
type: PacketType,
472468
data?: RawData,
473-
options: { compress: boolean } = { compress: true },
469+
options: SendOptions = {},
474470
callback?: () => void
475471
) {
476472
if ("function" === typeof options) {
477473
callback = options;
478-
options = null;
474+
options = {};
479475
}
480476

481477
if ("closing" !== this.readyState && "closed" !== this.readyState) {
482478
debug('sending packet "%s" (%s)', type, data);
483479

480+
// compression is enabled by default
481+
options.compress = options.compress !== false;
482+
484483
const packet: Packet = {
485484
type,
486-
options,
485+
options: options as { compress: boolean },
487486
};
488487

489488
if (data) packet.data = data;

0 commit comments

Comments
 (0)