Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 13 additions & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function map(ary, each, done) {
* @api public
*/

exports.decodePayload = function (data, binaryType, callback) {
exports.decodePayload = function (data, binaryType, utf8decode, callback) {
if (typeof data !== 'string') {
return exports.decodePayloadAsBinary(data, binaryType, callback);
}
Expand All @@ -379,12 +379,24 @@ exports.decodePayload = function (data, binaryType, callback) {
binaryType = null;
}

if (typeof utf8decode === 'function') {
callback = utf8decode;
utf8decode = null;
}

var packet;
if (data === '') {
// parser error - ignoring payload
return callback(err, 0, 1);
}

if (utf8decode) {
data = tryDecode(data);
if (data === false) {
return callback(err, 0, 1);
}
}

var length = '', n, msg;

for (var i = 0, l = data.length; i < l; i++) {
Expand Down
14 changes: 13 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function map(ary, each, done) {
* @api public
*/

exports.decodePayload = function (data, binaryType, callback) {
exports.decodePayload = function (data, binaryType, utf8decode, callback) {
if (typeof data !== 'string') {
return exports.decodePayloadAsBinary(data, binaryType, callback);
}
Expand All @@ -275,11 +275,23 @@ exports.decodePayload = function (data, binaryType, callback) {
binaryType = null;
}

if (typeof utf8decode === 'function') {
callback = utf8decode;
utf8decode = null;
}

if (data === '') {
// parser error - ignoring payload
return callback(err, 0, 1);
}

if (utf8decode) {
data = tryDecode(data);
if (data === false) {
return callback(err, 0, 1);
}
}

var length = '', n, msg, packet;

for (var i = 0, l = data.length; i < l; i++) {
Expand Down