content/hifi-content/wayne/404redirectionScripts/oopsEntityScript.js
2022-02-14 02:04:11 +01:00

38 lines
1.3 KiB
JavaScript

(function() {
var PROTOCOL_MISMATCH = 1;
var NOT_AUTHORIZED = 3;
var TIMEOUT = 5;
var entityScriptID = Uuid.NULL;
this.preload = function(entityID) {
entityScriptID = entityID;
};
function pingError() {
var error = Window.getLastDomainConnectionError();
var newModel = "";
var hostedSite = Script.resourcesPath() + "meshes/redirect/";
if (error === PROTOCOL_MISMATCH) {
newModel = "oopsDialog_protocol";
} else if (error === NOT_AUTHORIZED) {
newModel = "oopsDialog_auth";
} else if (error === TIMEOUT) {
newModel = "oopsDialog_timeout";
} else {
newModel = "oopsDialog_vague";
}
var props = Entities.getEntityProperties(this.entityID, ["modelURL"]);
var newModelURL = hostedSite + newModel + ".fbx";
if(props.modelURL !== newModelURL) {
var newFileURL = newModelURL + "/" + newModel + ".png";
var newTextures = {"file16": newFileURL, "file17": newFileURL};
Entities.editEntity(entityScriptID, {modelURL: newModelURL, originalTextures: JSON.stringify(newTextures)});
}
};
var ping = Script.setInterval(pingError, 100);
function cleanup() {
Script.clearInterval(ping);
};
Script.scriptEnding.connect(cleanup);
});