Merge pull request #472 from synth-tech/xhrfactory

Implementation of factory to supply XHR, allowing customisation of XHR requests
This commit is contained in:
Markus Schütz 2018-01-17 11:02:07 +01:00 committed by GitHub
commit 07eef56512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 41 additions and 12 deletions

View File

@ -4,6 +4,7 @@
"*.vs": "cpp",
"*.fs": "cpp"
},
"files.trimTrailingWhitespace": false,
"editor.fontSize": 16,
"editor.autoIndent": false,
"editor.detectIndentation": false,

View File

@ -261,7 +261,7 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct
hurl += '&offset=[' + offset.x + ',' + offset.y + ',' + offset.z + ']';
}
var xhr = new XMLHttpRequest();
var xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', hurl, true);
var that = this;

View File

@ -203,7 +203,7 @@ Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function
// var hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
var hurl = node.pcoGeometry.octreeDir + '/' + node.getHierarchyPath() + '/' + node.name + '.hrc';
var xhr = new XMLHttpRequest();
var xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', hurl, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');

View File

@ -615,7 +615,35 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){
};
};
Potree.XHRFactory = {
config: {
withCredentials: false,
customHeaders: [
{ header: null, value: null }
]
},
createXMLHttpRequest: function () {
let xhr = new XMLHttpRequest();
if (this.config.customHeaders &&
Array.isArray(this.config.customHeaders) &&
this.config.customHeaders.length > 0) {
let baseOpen = xhr.open;
let customHeaders = this.config.customHeaders;
xhr.open = function () {
baseOpen.apply(this, [].slice.call(arguments));
customHeaders.forEach(function (customHeader) {
if (!!customHeader.header && !!customHeader.value) {
xhr.setRequestHeader(customHeader.header, customHeader.value);
}
});
};
}
return xhr;
}
};

View File

@ -70,7 +70,7 @@ Potree.PointCloudArena4DGeometryNode.prototype.load = function () {
Potree.PointCloudArena4DGeometryNode.nodesLoading++;
let url = this.pcoGeometry.url + '?node=' + this.number;
let xhr = new XMLHttpRequest();
let xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
@ -183,7 +183,7 @@ Potree.PointCloudArena4DGeometry = function () {
Potree.PointCloudArena4DGeometry.prototype = Object.create(THREE.EventDispatcher.prototype);
Potree.PointCloudArena4DGeometry.load = function (url, callback) {
let xhr = new XMLHttpRequest();
let xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url + '?info', true);
xhr.onreadystatechange = function () {
@ -233,7 +233,7 @@ Potree.PointCloudArena4DGeometry.load = function (url, callback) {
Potree.PointCloudArena4DGeometry.prototype.loadHierarchy = function () {
let url = this.url + '?tree';
let xhr = new XMLHttpRequest();
let xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';

View File

@ -23,7 +23,7 @@ Potree.BinaryLoader.prototype.load = function (node) {
url += '.bin';
}
let xhr = new XMLHttpRequest();
let xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');

View File

@ -22,7 +22,7 @@ Potree.GreyhoundBinaryLoader = class{
let scope = this;
let url = node.getURL();
let xhr = new XMLHttpRequest();
let xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');

View File

@ -46,7 +46,7 @@ class GreyhoundUtils {
}
static fetch (url, cb) {
var xhr = new XMLHttpRequest();
var xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
@ -61,7 +61,7 @@ class GreyhoundUtils {
};
static fetchBinary (url, cb) {
var xhr = new XMLHttpRequest();
var xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = function () {

View File

@ -35,7 +35,7 @@ Potree.LasLazLoader = class LasLazLoader {
let scope = this;
let xhr = new XMLHttpRequest();
let xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');

View File

@ -20,7 +20,7 @@ Potree.POCLoader.load = function load (url, callback) {
try {
let pco = new Potree.PointCloudOctreeGeometry();
pco.url = url;
let xhr = new XMLHttpRequest();
let xhr = Potree.XHRFactory.createXMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {

View File

@ -42,7 +42,7 @@ Potree.utils = class {
};
static pathExists (url) {
let req = new XMLHttpRequest();
let req = Potree.XHRFactory.createXMLHttpRequest();
req.open('GET', url, false);
req.send(null);
if (req.status !== 200) {