mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Fixed a bug in fake xhr's getResponseHeader function. Plus some compat fixes for th android
This commit is contained in:
@@ -42,6 +42,8 @@ Tomahawk.apiVersion = "0.2.2";
|
|||||||
//Statuses considered a success for HTTP request
|
//Statuses considered a success for HTTP request
|
||||||
var httpSuccessStatuses = [200, 201];
|
var httpSuccessStatuses = [200, 201];
|
||||||
|
|
||||||
|
Tomahawk.error = console.error;
|
||||||
|
|
||||||
// install RSVP error handler for uncaught(!) errors
|
// install RSVP error handler for uncaught(!) errors
|
||||||
RSVP.on('error', function (reason) {
|
RSVP.on('error', function (reason) {
|
||||||
var resolverName = "";
|
var resolverName = "";
|
||||||
@@ -49,9 +51,9 @@ RSVP.on('error', function (reason) {
|
|||||||
resolverName = Tomahawk.resolver.instance.settings.name + " - ";
|
resolverName = Tomahawk.resolver.instance.settings.name + " - ";
|
||||||
}
|
}
|
||||||
if (reason) {
|
if (reason) {
|
||||||
console.error(resolverName + 'Uncaught error:', reason);
|
Tomahawk.error(resolverName + 'Uncaught error:', reason);
|
||||||
} else {
|
} else {
|
||||||
console.error(resolverName + 'Uncaught error: error thrown from RSVP but it was empty');
|
Tomahawk.error(resolverName + 'Uncaught error: error thrown from RSVP but it was empty');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -303,11 +305,12 @@ Tomahawk.Resolver = {
|
|||||||
return RSVP.Promise.resolve(this.testConfig(config)).then(function (results) {
|
return RSVP.Promise.resolve(this.testConfig(config)).then(function (results) {
|
||||||
results = results || Tomahawk.ConfigTestResultType.Success;
|
results = results || Tomahawk.ConfigTestResultType.Success;
|
||||||
return results;
|
return results;
|
||||||
|
}, function (error) {
|
||||||
|
return error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// help functions
|
// help functions
|
||||||
|
|
||||||
Tomahawk.valueForSubNode = function (node, tag) {
|
Tomahawk.valueForSubNode = function (node, tag) {
|
||||||
@@ -378,48 +381,6 @@ Tomahawk.retrievedMetadata = function (metadataId, metadata, error) {
|
|||||||
delete Tomahawk.retrieveMetadataCallbacks[metadataId];
|
delete Tomahawk.retrieveMetadataCallbacks[metadataId];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal counter used to identify asyncRequest callback from native code.
|
|
||||||
*/
|
|
||||||
Tomahawk.asyncRequestIdCounter = 0;
|
|
||||||
/**
|
|
||||||
* Internal map used to map asyncRequestIds to the respective javascript
|
|
||||||
* callback functions.
|
|
||||||
*/
|
|
||||||
Tomahawk.asyncRequestCallbacks = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pass the natively retrieved reply back to the javascript callback
|
|
||||||
* and augment the fake XMLHttpRequest object.
|
|
||||||
*
|
|
||||||
* Internal use only!
|
|
||||||
*/
|
|
||||||
Tomahawk.nativeAsyncRequestDone = function (reqId, xhr) {
|
|
||||||
// Check that we have a matching callback stored.
|
|
||||||
if (!Tomahawk.asyncRequestCallbacks.hasOwnProperty(reqId)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the real callback
|
|
||||||
if (xhr.readyState == 4 && httpSuccessStatuses.indexOf(xhr.status) != -1) {
|
|
||||||
// Call the real callback
|
|
||||||
if (Tomahawk.asyncRequestCallbacks[reqId].callback) {
|
|
||||||
Tomahawk.asyncRequestCallbacks[reqId].callback(xhr);
|
|
||||||
}
|
|
||||||
} else if (xhr.readyState === 4) {
|
|
||||||
Tomahawk.log("Failed to do nativeAsyncRequest");
|
|
||||||
Tomahawk.log("Status Code was: " + xhr.status);
|
|
||||||
if (Tomahawk.asyncRequestCallbacks[reqId].errorHandler) {
|
|
||||||
Tomahawk.asyncRequestCallbacks[reqId].errorHandler(xhr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callbacks are only used once.
|
|
||||||
delete Tomahawk.asyncRequestCallbacks[reqId];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is externalized from Tomahawk.asyncRequest, so that other clients
|
* This method is externalized from Tomahawk.asyncRequest, so that other clients
|
||||||
* (like tomahawk-android) can inject their own logic that determines whether or not to do a request
|
* (like tomahawk-android) can inject their own logic that determines whether or not to do a request
|
||||||
@@ -434,9 +395,9 @@ var shouldDoNativeRequest = function (options) {
|
|||||||
|| extraHeaders.hasOwnProperty("User-Agent")));
|
|| extraHeaders.hasOwnProperty("User-Agent")));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Possible options:
|
* Possible options:
|
||||||
|
* - url: The URL to call
|
||||||
* - method: The HTTP request method (default: GET)
|
* - method: The HTTP request method (default: GET)
|
||||||
* - username: The username for HTTP Basic Auth
|
* - username: The username for HTTP Basic Auth
|
||||||
* - password: The password for HTTP Basic Auth
|
* - password: The password for HTTP Basic Auth
|
||||||
@@ -454,7 +415,7 @@ var doRequest = function(options) {
|
|||||||
return this.responseHeaders;
|
return this.responseHeaders;
|
||||||
};
|
};
|
||||||
xhr.getResponseHeader = function (header) {
|
xhr.getResponseHeader = function (header) {
|
||||||
return this.responseHeaders[header];
|
return this.responseHeaders[header.toLowerCase()];
|
||||||
};
|
};
|
||||||
|
|
||||||
return xhr;
|
return xhr;
|
||||||
@@ -746,7 +707,6 @@ Tomahawk.base64Encode = function (b) {
|
|||||||
return window.btoa(b);
|
return window.btoa(b);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Tomahawk.PluginManager = {
|
Tomahawk.PluginManager = {
|
||||||
wrapperPrefix: '_adapter_',
|
wrapperPrefix: '_adapter_',
|
||||||
objects: {},
|
objects: {},
|
||||||
@@ -777,8 +737,6 @@ Tomahawk.PluginManager = {
|
|||||||
methodName = this.wrapperPrefix + methodName;
|
methodName = this.wrapperPrefix + methodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var pluginManager = this;
|
|
||||||
if (!this.objects[objectId]) {
|
if (!this.objects[objectId]) {
|
||||||
Tomahawk.log("Object not found! objectId: " + objectId + " methodName: " + methodName);
|
Tomahawk.log("Object not found! objectId: " + objectId + " methodName: " + methodName);
|
||||||
} else {
|
} else {
|
||||||
@@ -799,20 +757,21 @@ Tomahawk.PluginManager = {
|
|||||||
invoke: function (requestId, objectId, methodName, params) {
|
invoke: function (requestId, objectId, methodName, params) {
|
||||||
RSVP.Promise.resolve(this.invokeSync(requestId, objectId, methodName, params))
|
RSVP.Promise.resolve(this.invokeSync(requestId, objectId, methodName, params))
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
Tomahawk.reportScriptJobResults({
|
var params = {
|
||||||
requestId: requestId,
|
requestId: requestId,
|
||||||
data: result
|
data: result
|
||||||
});
|
};
|
||||||
|
Tomahawk.reportScriptJobResults(encodeParamsToNativeFunctions(params));
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
Tomahawk.reportScriptJobResults({
|
var params = {
|
||||||
requestId: requestId,
|
requestId: requestId,
|
||||||
error: error
|
error: error
|
||||||
});
|
};
|
||||||
|
Tomahawk.reportScriptJobResults(encodeParamsToNativeFunctions(params));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var encodeParamsToNativeFunctions = function(param) {
|
var encodeParamsToNativeFunctions = function(param) {
|
||||||
return param;
|
return param;
|
||||||
};
|
};
|
||||||
@@ -826,7 +785,7 @@ Tomahawk.NativeScriptJobManager = {
|
|||||||
var requestId = this.idCounter++;
|
var requestId = this.idCounter++;
|
||||||
var deferred = RSVP.defer();
|
var deferred = RSVP.defer();
|
||||||
this.deferreds[requestId] = deferred;
|
this.deferreds[requestId] = deferred;
|
||||||
Tomahawk.invokeNativeScriptJob(requestId, methodName, encodeParamsToNativeFunctions(params));;
|
Tomahawk.invokeNativeScriptJob(requestId, methodName, encodeParamsToNativeFunctions(params));
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
},
|
},
|
||||||
reportNativeScriptJobResult: function(requestId, result) {
|
reportNativeScriptJobResult: function(requestId, result) {
|
||||||
@@ -1495,9 +1454,7 @@ Tomahawk.Collection = {
|
|||||||
return new RSVP.Promise(function (resolve, reject) {
|
return new RSVP.Promise(function (resolve, reject) {
|
||||||
that.cachedDbs[id].changeVersion(that.cachedDbs[id].version, "", null,
|
that.cachedDbs[id].changeVersion(that.cachedDbs[id].version, "", null,
|
||||||
function (err) {
|
function (err) {
|
||||||
if (console.error) {
|
Tomahawk.error("Error trying to change db version!", err);
|
||||||
console.error("Error!: %o", err);
|
|
||||||
}
|
|
||||||
reject();
|
reject();
|
||||||
}, function () {
|
}, function () {
|
||||||
delete that.cachedDbs[id];
|
delete that.cachedDbs[id];
|
||||||
|
Reference in New Issue
Block a user