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 c7998d5 commit 1789094
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
5 changes: 2 additions & 3 deletions lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as parser from "socket.io-parser";
import { Decoder, Encoder } from "socket.io-parser";
import { on } from "./on";
import * as bind from "component-bind";
import * as indexOf from "indexof";
import * as Backoff from "backo2";

const debug = require("debug")("socket.io-client:manager");
Expand Down Expand Up @@ -595,7 +594,7 @@ export class Manager extends Emitter {
}

function onConnecting() {
if (!~indexOf(self.connecting, socket)) {
if (!~self.connecting.indexOf(socket)) {
self.connecting.push(socket);
}
}
Expand All @@ -610,7 +609,7 @@ export class Manager extends Emitter {
* @private
*/
_destroy(socket) {
const index = indexOf(this.connecting, socket);
const index = this.connecting.indexOf(socket);
if (~index) this.connecting.splice(index, 1);
if (this.connecting.length) return;

Expand Down
19 changes: 2 additions & 17 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Packet, PacketType } from "socket.io-parser";
import * as Emitter from "component-emitter";
import { on } from "./on";
import * as bind from "component-bind";
import * as hasBin from "has-binary2";
import { Manager } from "./manager";

const debug = require("debug")("socket.io-client:socket");
Expand Down Expand Up @@ -132,9 +131,7 @@ export class Socket extends Emitter {

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 @@ -282,7 +279,7 @@ export class Socket extends Emitter {
debug("sending ack %j", args);

self.packet({
type: hasBin(args) ? PacketType.BINARY_ACK : PacketType.ACK,
type: PacketType.ACK,
id: id,
data: args,
});
Expand Down Expand Up @@ -409,16 +406,4 @@ export class Socket extends Emitter {
this.flags.compress = compress;
return this;
}

/**
* Sets the binary flag
*
* @param {Boolean} binary - whether the emitted data contains binary
* @return {Socket} self
* @public
*/
public binary(binary: boolean): Socket {
this.flags.binary = binary;
return this;
}
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
"component-emitter": "~1.3.0",
"debug": "~4.1.0",
"engine.io-client": "~4.0.0",
"has-binary2": "~1.0.2",
"indexof": "0.0.1",
"parseuri": "0.0.6",
"socket.io-parser": "4.0.1-rc1"
"socket.io-parser": "4.0.1-rc2"
},
"devDependencies": {
"@babel/core": "^7.11.6",
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"allowJs": false,
"target": "es2017",
"module": "commonjs",
"declaration": true,
"allowSyntheticDefaultImports": true
"declaration": true
},
"include": [
"./lib/**/*"
Expand Down

0 comments on commit 1789094

Please sign in to comment.