Skip to content

Commit 669592d

Browse files
committedOct 15, 2020
feat: move binary detection back to the parser
See socketio/socket.io-parser@285e7cd Breaking change: the Socket#binary() method is removed, as this use case is now covered by the ability to provide your own parser.
1 parent 2d2a31e commit 669592d

File tree

4 files changed

+4
-48
lines changed

4 files changed

+4
-48
lines changed
 

‎lib/index.ts

-11
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,6 @@ export class Server extends EventEmitter {
595595
return this;
596596
}
597597

598-
/**
599-
* Sets the binary flag
600-
*
601-
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
602-
* @return {Server} self
603-
*/
604-
public binary(binary: boolean): Server {
605-
this.sockets.binary(binary);
606-
return this;
607-
}
608-
609598
/**
610599
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
611600
* receive messages (because of network slowness or other issues, or because they’re connected through long polling

‎lib/namespace.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Server } from "./index";
33
import { Client } from "./client";
44
import { EventEmitter } from "events";
55
import { PacketType } from "socket.io-parser";
6-
import hasBin from "has-binary2";
76
import debugModule from "debug";
87
import { Adapter, Room, SocketId } from "socket.io-adapter";
98

@@ -172,11 +171,7 @@ export class Namespace extends EventEmitter {
172171
// set up packet object
173172
args.unshift(ev);
174173
const packet = {
175-
type: (this.flags.binary !== undefined
176-
? this.flags.binary
177-
: hasBin(args))
178-
? PacketType.BINARY_EVENT
179-
: PacketType.EVENT,
174+
type: PacketType.EVENT,
180175
data: args
181176
};
182177

@@ -248,17 +243,6 @@ export class Namespace extends EventEmitter {
248243
return this;
249244
}
250245

251-
/**
252-
* Sets the binary flag
253-
*
254-
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
255-
* @return {Namespace} self
256-
*/
257-
public binary(binary: boolean): Namespace {
258-
this.flags.binary = binary;
259-
return this;
260-
}
261-
262246
/**
263247
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
264248
* receive messages (because of network slowness or other issues, or because they’re connected through long polling

‎lib/socket.ts

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { EventEmitter } from "events";
22
import { PacketType } from "socket.io-parser";
3-
import hasBin from "has-binary2";
43
import url from "url";
54
import debugModule from "debug";
65
import { Server } from "./index";
@@ -136,11 +135,7 @@ export class Socket extends EventEmitter {
136135
}
137136
args.unshift(ev);
138137
const packet: any = {
139-
type: (this.flags.binary !== undefined
140-
? this.flags.binary
141-
: hasBin(args))
142-
? PacketType.BINARY_EVENT
143-
: PacketType.EVENT,
138+
type: PacketType.EVENT,
144139
data: args
145140
};
146141

@@ -356,7 +351,7 @@ export class Socket extends EventEmitter {
356351

357352
self.packet({
358353
id: id,
359-
type: hasBin(args) ? PacketType.BINARY_ACK : PacketType.ACK,
354+
type: PacketType.ACK,
360355
data: args
361356
});
362357

@@ -460,17 +455,6 @@ export class Socket extends EventEmitter {
460455
return this;
461456
}
462457

463-
/**
464-
* Sets the binary flag
465-
*
466-
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
467-
* @return {Socket} self
468-
*/
469-
public binary(binary: boolean): Socket {
470-
this.flags.binary = binary;
471-
return this;
472-
}
473-
474458
/**
475459
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
476460
* receive messages (because of network slowness or other issues, or because they’re connected through long polling

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
"base64id": "~2.0.0",
3838
"debug": "~4.1.0",
3939
"engine.io": "~4.0.0",
40-
"has-binary2": "~1.0.2",
4140
"socket.io-adapter": "~2.0.1",
4241
"socket.io-client": "3.0.0-rc1",
43-
"socket.io-parser": "4.0.1-rc1"
42+
"socket.io-parser": "4.0.1-rc2"
4443
},
4544
"devDependencies": {
4645
"@types/cookie": "^0.4.0",

0 commit comments

Comments
 (0)
Please sign in to comment.