Skip to content

Commit

Permalink
Bundle release 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharieTFR committed Dec 7, 2020
1 parent 4291a96 commit 0857af4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
72 changes: 66 additions & 6 deletions dist/vast-client-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2375,19 +2375,79 @@ function onceWrap(target, event, handler) {
return onceWrapper;
}

// This mock module is loaded in stead of the original NodeURLHandler module
// when bundling the library for environments which are not node.
// This allows us to avoid bundling useless node components and have a smaller build.
var DEFAULT_TIMEOUT = 120000;

var uri = require('url');

var fs = require('fs');

var http = require('http');

var https = require('https');

var DOMParser = require('xmldom').DOMParser;

function get(url, options, cb) {
cb(new Error('Please bundle the library for node to use the node urlHandler'));
url = uri.parse(url);
var httpModule = url.protocol === 'https:' ? https : http;

if (url.protocol === 'file:') {
fs.readFile(uri.fileURLToPath(url.href), 'utf8', function (err, data) {
if (err) {
return cb(err);
}

var xml = new DOMParser().parseFromString(data);
cb(null, xml, {
byteLength: Buffer.from(data).byteLength
});
});
} else {
var timeoutId;
var data = '';
var timeout = options.timeout || DEFAULT_TIMEOUT;
var req = httpModule.get(url.href, function (res) {
res.on('data', function (chunk) {
data += chunk;
clearTimeout(timeoutId);
timeoutId = startTimeout();
});
res.on('end', function () {
clearTimeout(timeoutId);
var xml = new DOMParser().parseFromString(data);
cb(null, xml, {
byteLength: Buffer.from(data).byteLength,
statusCode: res.statusCode
});
});
});
req.on('error', function (err) {
clearTimeout(timeoutId);

if (req.aborted) {
cb(new Error("NodeURLHandler: Request timed out after ".concat(timeout, " ms.")), null, {
statusCode: 408 // Request timeout

});
} else {
cb(err);
}
});

var startTimeout = function startTimeout() {
return setTimeout(function () {
return req.abort();
}, timeout);
};

timeoutId = startTimeout();
}
}

var nodeURLHandler = {
get: get
};

var DEFAULT_TIMEOUT = 120000;

function xhr() {
try {
var request = new window.XMLHttpRequest();
Expand Down
Loading

0 comments on commit 0857af4

Please sign in to comment.