diff --git a/lib/browser.js b/lib/browser.js index 5a5e506..29ca084 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -9,7 +9,7 @@ var after = require('after'); var utf8 = require('./utf8'); var base64encoder; -if (global && global.ArrayBuffer) { +if (typeof ArrayBuffer !== 'undefined') { base64encoder = require('base64-arraybuffer'); } @@ -101,9 +101,9 @@ exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) { ? undefined : packet.data.buffer || packet.data; - if (global.ArrayBuffer && data instanceof ArrayBuffer) { + if (typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) { return encodeArrayBuffer(packet, supportsBinary, callback); - } else if (Blob && data instanceof global.Blob) { + } else if (typeof Blob !== 'undefined' && data instanceof Blob) { return encodeBlob(packet, supportsBinary, callback); } @@ -189,7 +189,7 @@ function encodeBlob(packet, supportsBinary, callback) { exports.encodeBase64Packet = function(packet, callback) { var message = 'b' + exports.packets[packet.type]; - if (Blob && packet.data instanceof global.Blob) { + if (typeof Blob !== 'undefined' && packet.data instanceof Blob) { var fr = new FileReader(); fr.onload = function() { var b64 = fr.result.split(',')[1]; @@ -210,7 +210,7 @@ exports.encodeBase64Packet = function(packet, callback) { } b64data = String.fromCharCode.apply(null, basic); } - message += global.btoa(b64data); + message += btoa(b64data); return callback(message); };