Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69603b9

Browse files
refactor: make the compress option optional
The compress option was inadvertently made mandatory in [1].[1]:6d87a40
1 parentae1ea77 commit69603b9

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
constdebug=debugModule("engine:socket");
1010

11+
exportinterfaceSendOptions{
12+
compress?:boolean;
13+
}
14+
1115
exportclassSocketextendsEventEmitter{
1216
publicreadonlyprotocol: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-
publicsend(
436-
data:RawData,
437-
options?:{compress:boolean},
438-
callback?:()=>void
439-
){
439+
publicsend(data:RawData,options?:SendOptions,callback?:()=>void){
440440
this.sendPacket("message",data,options,callback);
441441
returnthis;
442442
}
@@ -448,11 +448,7 @@ export class Socket extends EventEmitter {
448448
*@param options
449449
*@param callback
450450
*/
451-
publicwrite(
452-
data:RawData,
453-
options?:{compress:boolean},
454-
callback?:()=>void
455-
){
451+
publicwrite(data:RawData,options?:SendOptions,callback?:()=>void){
456452
this.sendPacket("message",data,options,callback);
457453
returnthis;
458454
}
@@ -470,20 +466,23 @@ export class Socket extends EventEmitter {
470466
privatesendPacket(
471467
type:PacketType,
472468
data?:RawData,
473-
options:{compress:boolean}={compress:true},
469+
options:SendOptions={},
474470
callback?:()=>void
475471
){
476472
if("function"===typeofoptions){
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
constpacket:Packet={
485484
type,
486-
options,
485+
options:optionsas{compress:boolean},
487486
};
488487

489488
if(data)packet.data=data;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp