From 669592d120409a5cf00f128070dee6d22259ba4f Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 15 Oct 2020 10:45:56 +0200 Subject: [PATCH] feat: move binary detection back to the parser See https://github.com/socketio/socket.io-parser/commit/285e7cd0d837adfc911c999e7294788681226ae1 Breaking change: the Socket#binary() method is removed, as this use case is now covered by the ability to provide your own parser. --- lib/index.ts | 11 ----------- lib/namespace.ts | 18 +----------------- lib/socket.ts | 20 ++------------------ package.json | 3 +-- 4 files changed, 4 insertions(+), 48 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 10905a8dfb..bd101d211d 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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 diff --git a/lib/namespace.ts b/lib/namespace.ts index 8b099a000b..0512f8ba0b 100644 --- a/lib/namespace.ts +++ b/lib/namespace.ts @@ -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"; @@ -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 }; @@ -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 diff --git a/lib/socket.ts b/lib/socket.ts index 0ddbd9eff6..092f12336f 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -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"; @@ -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 }; @@ -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 }); @@ -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 diff --git a/package.json b/package.json index 16ffd70b3d..9c377f5ad0 100644 --- a/package.json +++ b/package.json @@ -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",