Skip to content

Commit

Permalink
[refactor] Remove any reference to the global variable
Browse files Browse the repository at this point in the history
Related socketio#99
  • Loading branch information
darrachequesne committed Oct 31, 2018
1 parent ecf0c14 commit dfaf8c4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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];
Expand All @@ -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);
};

Expand Down

0 comments on commit dfaf8c4

Please sign in to comment.