From 27795119ee68dfe643d1e6d95af612ffb4ba80ad Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Mon, 24 Apr 2017 13:49:16 +0200 Subject: [PATCH] move binary detection to the parser --- index.js | 5 +++++ package.json | 1 + 2 files changed, 6 insertions(+) diff --git a/index.js b/index.js index 65ee2ad..ea206ea 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ var debug = require('debug')('socket.io-parser'); var Emitter = require('component-emitter'); +var hasBin = require('has-binary2'); var binary = require('./binary'); var isBuf = require('./is-buffer'); @@ -123,6 +124,10 @@ function Encoder() {} */ Encoder.prototype.encode = function(obj, callback){ + if ((obj.type === exports.EVENT || obj.type === exports.ACK) && hasBin(obj.data)) { + obj.type = obj.type === exports.EVENT ? exports.BINARY_EVENT : exports.BINARY_ACK; + } + debug('encoding packet %j', obj); if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) { diff --git a/package.json b/package.json index a10abc8..74dd27a 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dependencies": { "debug": "2.3.3", "component-emitter": "1.2.1", + "has-binary2": "1.0.1", "isarray": "2.0.1" }, "devDependencies": {