Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add the hasBinary flag
  • Loading branch information
Andrews54757 committed Jan 26, 2017
commit 7eccc4d9ae4028e92555672cc6ae1a585c67d994
26 changes: 24 additions & 2 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,17 @@ Socket.prototype.emit = function(ev){
if (~exports.events.indexOf(ev)) {
emit.apply(this, arguments);
} else {
var args = Array.prototype.slice.call(arguments);
var args = Array.prototype.slice.call(arguments),
type = parser.EVENT;

if (this.flags.hasBinary === undefined) {
hasBin(args) && (type = parser.BINARY_EVENT);
} else {
this.flags.hasBinary && (type = parser.BINARY_EVENT);
}

var packet = {
type: hasBin(args) ? parser.BINARY_EVENT : parser.EVENT,
type: type,
data: args
};

Expand Down Expand Up @@ -481,6 +489,20 @@ Socket.prototype.compress = function(compress){
return this;
};

/**
* Sets the hasBinary flag
*
* @param {Boolean} Encode as if it has binary data if `true`, Encode as if it doesnt have binary data if `false`
* @return {Socket} self
* @api public
*/

Socket.prototype.hasBinary = function (bool) {
this.flags = this.flags || {};
this.flags.hasBinary = bool;
return this;
};

/**
* Dispatch incoming event to socket listeners.
*
Expand Down