From 4052747eb213d1d1158af1a44f157f663090eb24 Mon Sep 17 00:00:00 2001 From: Victor Soto Date: Tue, 29 Dec 2020 10:08:58 +0100 Subject: [PATCH] fix(binary): fix binary events being marked as regular events (#76) So that the emitter can send binary payloads to a Socket.IO server (only applies to `socket.io@2.1.0...2.x`). Note: we should remove this in the future, as it is not needed for a Socket.IO v3 server. Related: - https://github.com/socketio/socket.io-parser/commit/dc4f475a452f28fd6fd2ecfecf869c133bf0978d - https://github.com/socketio/socket.io/commit/f48a06c040280b44f90fd225c888910544fd63b5 Co-authored-by: Victor Soto --- index.js | 3 ++- package.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 412f5f9..5ba3b3a 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ var client = require('redis').createClient; var parser = require('socket.io-parser'); var msgpack = require('notepack.io'); +var hasBin = require('has-binary2'); var debug = require('debug')('socket.io-emitter'); /** @@ -123,7 +124,7 @@ Emitter.prototype.of = function(nsp){ Emitter.prototype.emit = function(){ // packet var args = Array.prototype.slice.call(arguments); - var packet = { type: parser.EVENT, data: args, nsp: this.nsp }; + var packet = { type: hasBin(args) ? parser.BINARY_EVENT : parser.EVENT, data: args, nsp: this.nsp }; var opts = { rooms: this._rooms, diff --git a/package.json b/package.json index 0166686..acc5861 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ }, "dependencies": { "debug": "~3.1.0", + "has-binary2": "~1.0.2", "notepack.io": "~2.1.0", "redis": "2.6.3", "socket.io-parser": "3.1.2"