2018-09-25 18:16:18 -07:00
|
|
|
"use strict";
|
2023-03-20 21:46:20 -04:00
|
|
|
//
|
|
|
|
// redirectOverlays.js
|
|
|
|
//
|
|
|
|
// Created by Wayne Chen on September 25th, 2018
|
|
|
|
// Copyright 2018 High Fidelity, Inc.
|
|
|
|
// Copyright 2023 Overte e.V.
|
|
|
|
//
|
|
|
|
// Overlays
|
|
|
|
//
|
|
|
|
// Distributed under the Apache License, Version 2.0.
|
|
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
|
2018-09-25 18:16:18 -07:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
var ERROR_MESSAGE_MAP = [
|
|
|
|
"Oops! Protocol version mismatch.",
|
|
|
|
"Oops! Not authorized to join domain.",
|
|
|
|
"Oops! Connection timed out.",
|
2018-10-12 11:28:54 -07:00
|
|
|
"Oops! The domain is full.",
|
2018-09-25 18:16:18 -07:00
|
|
|
"Oops! Something went wrong."
|
|
|
|
];
|
|
|
|
|
|
|
|
var PROTOCOL_VERSION_MISMATCH = 1;
|
|
|
|
var NOT_AUTHORIZED = 3;
|
2018-10-12 11:28:54 -07:00
|
|
|
var DOMAIN_FULL = 4;
|
2018-09-25 18:16:18 -07:00
|
|
|
var TIMEOUT = 5;
|
2018-10-12 11:28:54 -07:00
|
|
|
var hardRefusalErrors = [
|
|
|
|
PROTOCOL_VERSION_MISMATCH,
|
|
|
|
NOT_AUTHORIZED,
|
|
|
|
TIMEOUT,
|
|
|
|
DOMAIN_FULL
|
|
|
|
];
|
2018-09-25 18:16:18 -07:00
|
|
|
var timer = null;
|
2018-10-04 23:11:27 -07:00
|
|
|
var isErrorState = false;
|
2018-09-25 18:16:18 -07:00
|
|
|
|
|
|
|
function getOopsText() {
|
2018-09-26 13:48:15 -07:00
|
|
|
var error = Window.getLastDomainConnectionError();
|
2018-09-25 18:21:51 -07:00
|
|
|
var errorMessageMapIndex = hardRefusalErrors.indexOf(error);
|
2018-09-27 17:16:18 -07:00
|
|
|
if (error === -1) {
|
|
|
|
// not an error.
|
|
|
|
return "";
|
|
|
|
} else if (errorMessageMapIndex >= 0) {
|
2018-09-25 18:21:51 -07:00
|
|
|
return ERROR_MESSAGE_MAP[errorMessageMapIndex];
|
2018-09-25 18:16:18 -07:00
|
|
|
} else {
|
|
|
|
// some other text.
|
2018-10-12 11:28:54 -07:00
|
|
|
return ERROR_MESSAGE_MAP[ERROR_MESSAGE_MAP.length - 1];
|
2018-09-25 18:16:18 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-27 16:56:45 -07:00
|
|
|
var oopsDimensions = {x: 4.2, y: 0.8};
|
2018-09-26 15:12:48 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var redirectOopsText = Entities.addEntity({
|
|
|
|
"type": "Text",
|
|
|
|
"name": "oopsText",
|
|
|
|
"position": {"x": 0, "y": 1.6763916015625, "z": 1.45927095413208},
|
|
|
|
"rotation": {"x": -4.57763671875e-05, "y": 0.4957197904586792, "z": -7.62939453125e-05, "w": 0.8684672117233276},
|
|
|
|
"text": getOopsText(),
|
|
|
|
"textAlpha": 1,
|
|
|
|
"backgroundColor": {"x": 0, "y": 0, "z":0},
|
|
|
|
"backgroundAlpha": 0,
|
|
|
|
"lineHeight": 0.10,
|
|
|
|
"leftMargin": 0.538373570564886,
|
|
|
|
"visible": false,
|
|
|
|
"unlit": true,
|
|
|
|
"ignorePickIntersection": true,
|
|
|
|
"dimensions": oopsDimensions,
|
|
|
|
"grab": {
|
|
|
|
"grabbable": false
|
|
|
|
}
|
|
|
|
}, "local");
|
2018-09-25 18:16:18 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var tryAgainImageNeutral = Entities.addEntity({
|
|
|
|
"type": "Image",
|
|
|
|
"name": "tryAgainImage",
|
|
|
|
"localPosition": {"x": -0.6, "y": -0.6, "z": 0.0},
|
|
|
|
"imageURL": Script.resourcesPath() + "images/interstitialPage/button.png",
|
|
|
|
"alpha": 1,
|
|
|
|
"visible": false,
|
|
|
|
"emissive": true,
|
|
|
|
"ignorePickIntersection": false,
|
|
|
|
"grab": {
|
|
|
|
"grabbable": false
|
|
|
|
},
|
|
|
|
"rotation": Entities.getEntityProperties(redirectOopsText, ["rotation"]).rotation,
|
|
|
|
"parentID": redirectOopsText
|
|
|
|
}, "local");
|
2018-10-01 16:11:27 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var tryAgainImageHover = Entities.addEntity({
|
|
|
|
"type": "Image",
|
|
|
|
"name": "tryAgainImageHover",
|
|
|
|
"localPosition": {"x": -0.6, "y": -0.6, "z": 0.0},
|
|
|
|
"imageURL": Script.resourcesPath() + "images/interstitialPage/button_hover.png",
|
|
|
|
"alpha": 1,
|
|
|
|
"visible": false,
|
|
|
|
"emissive": true,
|
|
|
|
"ignorePickIntersection": false,
|
|
|
|
"grab": {
|
|
|
|
"grabbable": false
|
|
|
|
},
|
|
|
|
"rotation": Entities.getEntityProperties(redirectOopsText, ["rotation"]).rotation,
|
|
|
|
"parentID": redirectOopsText
|
|
|
|
}, "local");
|
2018-09-25 18:16:18 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var tryAgainText = Entities.addEntity({
|
|
|
|
"type": "Text",
|
|
|
|
"name": "tryAgainText",
|
|
|
|
"localPosition": {"x": -0.6, "y": -0.962, "z": 0.0},
|
|
|
|
"text": "Try Again",
|
|
|
|
"textAlpha": 1,
|
|
|
|
"backgroundAlpha": 0.00393,
|
|
|
|
"lineHeight": 0.08,
|
|
|
|
"visible": false,
|
|
|
|
"unlit": true,
|
|
|
|
"ignorePickIntersection": true,
|
|
|
|
"grab": {
|
|
|
|
"grabbable": false
|
|
|
|
},
|
|
|
|
"rotation": Entities.getEntityProperties(redirectOopsText, ["rotation"]).rotation,
|
|
|
|
"parentID": redirectOopsText
|
|
|
|
}, "local");
|
2018-10-01 16:11:27 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var backImageNeutral = Entities.addEntity({
|
|
|
|
"type": "Image",
|
|
|
|
"name": "backImage",
|
|
|
|
"localPosition": {"x": 0.6, "y": -0.6, "z": 0.0},
|
|
|
|
"imageURL": Script.resourcesPath() + "images/interstitialPage/button.png",
|
|
|
|
"alpha": 1,
|
|
|
|
"visible": false,
|
|
|
|
"emissive": true,
|
|
|
|
"ignorePickIntersection": false,
|
|
|
|
"grab": {
|
|
|
|
"grabbable": false
|
|
|
|
},
|
|
|
|
"rotation": Entities.getEntityProperties(redirectOopsText, ["rotation"]).rotation,
|
|
|
|
"parentID": redirectOopsText
|
|
|
|
}, "local");
|
2018-09-25 18:16:18 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var backImageHover = Entities.addEntity({
|
|
|
|
"type": "Image",
|
|
|
|
"name": "backImageHover",
|
|
|
|
"localPosition": {"x": 0.6, "y": -0.6, "z": 0.0},
|
|
|
|
"imageURL": Script.resourcesPath() + "images/interstitialPage/button_hover.png",
|
|
|
|
"alpha": 1,
|
|
|
|
"visible": false,
|
|
|
|
"emissive": true,
|
|
|
|
"ignorePickIntersection": false,
|
|
|
|
"grab": {
|
|
|
|
"grabbable": false
|
|
|
|
},
|
|
|
|
"rotation": Entities.getEntityProperties(redirectOopsText, ["rotation"]).rotation,
|
|
|
|
"parentID": redirectOopsText
|
|
|
|
}, "local");
|
2018-10-01 16:11:27 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var backText = Entities.addEntity({
|
|
|
|
"type": "Text",
|
|
|
|
"name": "backText",
|
|
|
|
"localPosition": {"x": 0.6, "y": -0.962, "z": 0.0},
|
|
|
|
"text": "Back",
|
|
|
|
"textAlpha": 1,
|
|
|
|
"backgroundAlpha": 0.00393,
|
|
|
|
"lineHeight": 0.08,
|
|
|
|
"visible": false,
|
|
|
|
"unlit": true,
|
|
|
|
"ignorePickIntersection": true,
|
|
|
|
"grab": {
|
|
|
|
"grabbable": false
|
|
|
|
},
|
|
|
|
"rotation": Entities.getEntityProperties(redirectOopsText, ["rotation"]).rotation,
|
|
|
|
"parentID": redirectOopsText
|
|
|
|
}, "local");
|
2018-10-01 16:11:27 -07:00
|
|
|
|
2018-09-26 13:48:15 -07:00
|
|
|
function toggleOverlays(isInErrorState) {
|
2018-10-04 23:11:27 -07:00
|
|
|
isErrorState = isInErrorState;
|
2018-09-26 13:48:15 -07:00
|
|
|
if (!isInErrorState) {
|
|
|
|
var properties = {
|
2023-03-20 21:46:20 -04:00
|
|
|
"visible": false
|
2018-09-26 13:48:15 -07:00
|
|
|
};
|
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
Entities.editEntity(redirectOopsText, properties);
|
|
|
|
Entities.editEntity(tryAgainImageNeutral, properties);
|
|
|
|
Entities.editEntity(tryAgainImageHover, properties);
|
|
|
|
Entities.editEntity(backImageNeutral, properties);
|
|
|
|
Entities.editEntity(backImageHover, properties);
|
|
|
|
Entities.editEntity(tryAgainText, properties);
|
|
|
|
Entities.editEntity(backText, properties);
|
2018-09-26 13:48:15 -07:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 17:16:18 -07:00
|
|
|
var oopsText = getOopsText();
|
|
|
|
// if oopsText === "", it was a success.
|
|
|
|
var overlaysVisible = (oopsText !== "");
|
2018-10-04 23:11:27 -07:00
|
|
|
// for catching init or if error state were to be different.
|
|
|
|
isErrorState = overlaysVisible;
|
2018-09-25 18:16:18 -07:00
|
|
|
var properties = {
|
2023-03-20 21:46:20 -04:00
|
|
|
"visible": overlaysVisible
|
2018-09-25 18:16:18 -07:00
|
|
|
};
|
2018-09-26 07:41:18 -07:00
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var textWidth = Entities.textSize(redirectOopsText, oopsText).width;
|
2018-09-26 15:12:48 -07:00
|
|
|
var textOverlayWidth = oopsDimensions.x;
|
2018-09-26 13:48:15 -07:00
|
|
|
|
2018-09-25 18:16:18 -07:00
|
|
|
var oopsTextProperties = {
|
2023-03-20 21:46:20 -04:00
|
|
|
"visible": overlaysVisible,
|
|
|
|
"text": oopsText,
|
|
|
|
"textAlpha": overlaysVisible,
|
2018-09-27 21:20:06 -07:00
|
|
|
// either visible or invisible. 0 doesn't work in Mac.
|
2023-03-20 21:46:20 -04:00
|
|
|
"backgroundAlpha": overlaysVisible * 0.00393,
|
|
|
|
"leftMargin": (textOverlayWidth - textWidth) / 2
|
2018-09-25 18:16:18 -07:00
|
|
|
};
|
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var tryAgainTextWidth = Entities.textSize(tryAgainText, "Try Again").width;
|
|
|
|
var tryAgainImageWidth = Entities.getEntityProperties(tryAgainImageNeutral, ["dimensions"]).dimensions.x;
|
2018-10-01 16:11:27 -07:00
|
|
|
|
|
|
|
var tryAgainTextProperties = {
|
2023-03-20 21:46:20 -04:00
|
|
|
"visible": overlaysVisible,
|
|
|
|
"leftMargin": (tryAgainImageWidth - tryAgainTextWidth) / 2
|
2018-10-01 16:11:27 -07:00
|
|
|
};
|
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
var backTextWidth = Entities.textSize(backText, "Back").width;
|
|
|
|
var backImageWidth = Entities.getEntityProperties(backImageNeutral, ["dimensions"]).dimensions.x;
|
2018-10-01 16:11:27 -07:00
|
|
|
|
|
|
|
var backTextProperties = {
|
2023-03-20 21:46:20 -04:00
|
|
|
"visible": overlaysVisible,
|
|
|
|
"leftMargin": (backImageWidth - backTextWidth) / 2
|
2018-10-01 16:11:27 -07:00
|
|
|
};
|
|
|
|
|
2023-03-20 21:46:20 -04:00
|
|
|
Entities.editEntity(redirectOopsText, oopsTextProperties);
|
|
|
|
Entities.editEntity(tryAgainImageNeutral, properties);
|
|
|
|
Entities.editEntity(backImageNeutral, properties);
|
|
|
|
Entities.editEntity(tryAgainImageHover, {"visible": false});
|
|
|
|
Entities.editEntity(backImageHover, {"visible": false});
|
|
|
|
Entities.editEntity(tryAgainText, tryAgainTextProperties);
|
|
|
|
Entities.editEntity(backText, backTextProperties);
|
2018-09-26 13:48:15 -07:00
|
|
|
|
2018-09-25 18:16:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function clickedOnOverlay(overlayID, event) {
|
2018-09-26 16:40:43 -07:00
|
|
|
if (event.isRightButton) {
|
|
|
|
// don't allow right-clicks.
|
|
|
|
return;
|
|
|
|
}
|
2018-10-01 16:11:27 -07:00
|
|
|
if (tryAgainImageHover === overlayID) {
|
2018-09-25 18:16:18 -07:00
|
|
|
location.goToLastAddress();
|
2018-10-03 17:40:42 -07:00
|
|
|
} else if (backImageHover === overlayID && location.canGoBack()) {
|
2018-09-25 18:16:18 -07:00
|
|
|
location.goBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup() {
|
2018-09-26 07:41:18 -07:00
|
|
|
Script.clearInterval(timer);
|
2018-09-25 18:16:18 -07:00
|
|
|
timer = null;
|
2023-03-20 21:46:20 -04:00
|
|
|
Entities.deleteEntity(redirectOopsText);
|
|
|
|
Entities.deleteEntity(tryAgainImageNeutral);
|
|
|
|
Entities.deleteEntity(backImageNeutral);
|
|
|
|
Entities.deleteEntity(tryAgainImageHover);
|
|
|
|
Entities.deleteEntity(backImageHover);
|
|
|
|
Entities.deleteEntity(tryAgainText);
|
|
|
|
Entities.deleteEntity(backText);
|
2018-09-25 18:16:18 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 13:48:15 -07:00
|
|
|
toggleOverlays(true);
|
|
|
|
|
2018-09-25 18:16:18 -07:00
|
|
|
Overlays.mouseReleaseOnOverlay.connect(clickedOnOverlay);
|
|
|
|
Overlays.hoverEnterOverlay.connect(function(overlayID, event) {
|
2018-10-04 23:11:27 -07:00
|
|
|
if (!isErrorState) {
|
|
|
|
// don't allow hover overlay events to get caught if it's not in error state anymore.
|
|
|
|
return;
|
|
|
|
}
|
2018-10-03 17:40:42 -07:00
|
|
|
if (overlayID === backImageNeutral && location.canGoBack()) {
|
2023-03-20 21:46:20 -04:00
|
|
|
Entities.editEntity(backImageNeutral, {"visible": false});
|
|
|
|
Entities.editEntity(backImageHover, {"visible": true});
|
2018-10-01 16:11:27 -07:00
|
|
|
}
|
|
|
|
if (overlayID === tryAgainImageNeutral) {
|
2023-03-20 21:46:20 -04:00
|
|
|
Entities.editEntity(tryAgainImageNeutral, {"visible": false});
|
|
|
|
Entities.editEntity(tryAgainImageHover, {"visible": true});
|
2018-09-25 18:16:18 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Overlays.hoverLeaveOverlay.connect(function(overlayID, event) {
|
2018-10-04 23:11:27 -07:00
|
|
|
if (!isErrorState) {
|
|
|
|
// don't allow hover overlay events to get caught if it's not in error state anymore.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (overlayID === backImageHover) {
|
2023-03-20 21:46:20 -04:00
|
|
|
Entities.editEntity(backImageHover, {"visible": false});
|
|
|
|
Entities.editEntity(backImageNeutral, {"visible": true});
|
2018-10-01 16:11:27 -07:00
|
|
|
}
|
2018-10-04 23:11:27 -07:00
|
|
|
if (overlayID === tryAgainImageHover) {
|
2023-03-20 21:46:20 -04:00
|
|
|
Entities.editEntity(tryAgainImageHover, {"visible": false});
|
|
|
|
Entities.editEntity(tryAgainImageNeutral, {"visible": true});
|
2018-09-25 18:16:18 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-09-26 13:48:15 -07:00
|
|
|
Window.redirectErrorStateChanged.connect(toggleOverlays);
|
2018-09-25 18:16:18 -07:00
|
|
|
|
|
|
|
Script.scriptEnding.connect(cleanup);
|
|
|
|
}());
|