Skip to content

Commit

Permalink
feat: move binary detection back to the parser
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darrachequesne committed Oct 15, 2020
1 parent 2d2a31e commit 669592d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 48 deletions.
11 changes: 0 additions & 11 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,6 @@ export class Server extends EventEmitter {
return this;
}

/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Server} self
*/
public binary(binary: boolean): Server {
this.sockets.binary(binary);
return this;
}

/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
* receive messages (because of network slowness or other issues, or because they’re connected through long polling
Expand Down
18 changes: 1 addition & 17 deletions lib/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Server } from "./index";
import { Client } from "./client";
import { EventEmitter } from "events";
import { PacketType } from "socket.io-parser";
import hasBin from "has-binary2";
import debugModule from "debug";
import { Adapter, Room, SocketId } from "socket.io-adapter";

Expand Down Expand Up @@ -172,11 +171,7 @@ export class Namespace extends EventEmitter {
// set up packet object
args.unshift(ev);
const packet = {
type: (this.flags.binary !== undefined
? this.flags.binary
: hasBin(args))
? PacketType.BINARY_EVENT
: PacketType.EVENT,
type: PacketType.EVENT,
data: args
};

Expand Down Expand Up @@ -248,17 +243,6 @@ export class Namespace extends EventEmitter {
return this;
}

/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Namespace} self
*/
public binary(binary: boolean): Namespace {
this.flags.binary = binary;
return this;
}

/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
* receive messages (because of network slowness or other issues, or because they’re connected through long polling
Expand Down
20 changes: 2 additions & 18 deletions lib/socket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EventEmitter } from "events";
import { PacketType } from "socket.io-parser";
import hasBin from "has-binary2";
import url from "url";
import debugModule from "debug";
import { Server } from "./index";
Expand Down Expand Up @@ -136,11 +135,7 @@ export class Socket extends EventEmitter {
}
args.unshift(ev);
const packet: any = {
type: (this.flags.binary !== undefined
? this.flags.binary
: hasBin(args))
? PacketType.BINARY_EVENT
: PacketType.EVENT,
type: PacketType.EVENT,
data: args
};

Expand Down Expand Up @@ -356,7 +351,7 @@ export class Socket extends EventEmitter {

self.packet({
id: id,
type: hasBin(args) ? PacketType.BINARY_ACK : PacketType.ACK,
type: PacketType.ACK,
data: args
});

Expand Down Expand Up @@ -460,17 +455,6 @@ export class Socket extends EventEmitter {
return this;
}

/**
* Sets the binary flag
*
* @param {Boolean} binary - encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Socket} self
*/
public binary(binary: boolean): Socket {
this.flags.binary = binary;
return this;
}

/**
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
* receive messages (because of network slowness or other issues, or because they’re connected through long polling
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
"base64id": "~2.0.0",
"debug": "~4.1.0",
"engine.io": "~4.0.0",
"has-binary2": "~1.0.2",
"socket.io-adapter": "~2.0.1",
"socket.io-client": "3.0.0-rc1",
"socket.io-parser": "4.0.1-rc1"
"socket.io-parser": "4.0.1-rc2"
},
"devDependencies": {
"@types/cookie": "^0.4.0",
Expand Down

0 comments on commit 669592d

Please sign in to comment.