error state signal for 404/interstitial

This commit is contained in:
Wayne Chen 2018-09-26 13:48:15 -07:00
parent 4a87773986
commit db41a1c16b
8 changed files with 78 additions and 33 deletions

View file

@ -172,7 +172,7 @@ bool SafeLanding::isEntityLoadingComplete() {
bool isVisuallyReady = true; bool isVisuallyReady = true;
Settings settings; Settings settings;
bool enableInterstitial = settings.value("enableIntersitialMode", false).toBool(); bool enableInterstitial = DependencyManager::get<NodeList>()->getDomainHandler().getInterstitialModeEnabled();
if (enableInterstitial) { if (enableInterstitial) {
isVisuallyReady = (entity->isVisuallyReady() || !entityTree->renderableForEntityId(entityMapIter->first)); isVisuallyReady = (entity->isVisuallyReady() || !entityTree->renderableForEntityId(entityMapIter->first));

View file

@ -39,6 +39,7 @@ WindowScriptingInterface::WindowScriptingInterface() {
connect(&domainHandler, &DomainHandler::disconnectedFromDomain, this, &WindowScriptingInterface::disconnectedFromDomain); connect(&domainHandler, &DomainHandler::disconnectedFromDomain, this, &WindowScriptingInterface::disconnectedFromDomain);
connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &WindowScriptingInterface::domainConnectionRefused); connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &WindowScriptingInterface::domainConnectionRefused);
connect(&domainHandler, &DomainHandler::redirectErrorStateChanged, this, &WindowScriptingInterface::redirectErrorStateChanged);
connect(qApp, &Application::svoImportRequested, [this](const QString& urlString) { connect(qApp, &Application::svoImportRequested, [this](const QString& urlString) {
static const QMetaMethod svoImportRequestedSignal = static const QMetaMethod svoImportRequestedSignal =

View file

@ -611,6 +611,14 @@ signals:
*/ */
void domainConnectionRefused(const QString& reasonMessage, int reasonCode, const QString& extraInfo); void domainConnectionRefused(const QString& reasonMessage, int reasonCode, const QString& extraInfo);
/**jsdoc
* Triggered when you try to visit a domain but are redirected into the error state.
* @function Window.redirectErrorStateChanged
* @param {boolean} isInErrorState - If <code>true</code>, the user has been redirected to the error URL.
* @returns {Signal}
*/
void redirectErrorStateChanged(bool isInErrorState);
/**jsdoc /**jsdoc
* Triggered when a still snapshot has been taken by calling {@link Window.takeSnapshot|takeSnapshot} with * Triggered when a still snapshot has been taken by calling {@link Window.takeSnapshot|takeSnapshot} with
* <code>includeAnimated = false</code> or {@link Window.takeSecondaryCameraSnapshot|takeSecondaryCameraSnapshot}. * <code>includeAnimated = false</code> or {@link Window.takeSecondaryCameraSnapshot|takeSecondaryCameraSnapshot}.

View file

@ -123,6 +123,7 @@ void DomainHandler::hardReset() {
softReset(); softReset();
_isInErrorState = false; _isInErrorState = false;
emit redirectErrorStateChanged(_isInErrorState);
qCDebug(networking) << "Hard reset in NodeList DomainHandler."; qCDebug(networking) << "Hard reset in NodeList DomainHandler.";
_pendingDomainID = QUuid(); _pendingDomainID = QUuid();
@ -362,6 +363,7 @@ void DomainHandler::setRedirectErrorState(QUrl errorUrl, QString reasonMessage,
if (getInterstitialModeEnabled()) { if (getInterstitialModeEnabled()) {
_errorDomainURL = errorUrl; _errorDomainURL = errorUrl;
_isInErrorState = true; _isInErrorState = true;
emit redirectErrorStateChanged(_isInErrorState);
emit redirectToErrorDomainURL(_errorDomainURL); emit redirectToErrorDomainURL(_errorDomainURL);
} else { } else {
emit domainConnectionRefused(reasonMessage, reasonCode, extraInfo); emit domainConnectionRefused(reasonMessage, reasonCode, extraInfo);

View file

@ -187,8 +187,6 @@ private slots:
signals: signals:
void domainURLChanged(QUrl domainURL); void domainURLChanged(QUrl domainURL);
void domainConnectionErrorChanged(int reasonCode);
// NOTE: the emission of completedSocketDiscovery does not mean a connection to DS is established // NOTE: the emission of completedSocketDiscovery does not mean a connection to DS is established
// It means that, either from DNS lookup or ICE, we think we have a socket we can talk to DS on // It means that, either from DNS lookup or ICE, we think we have a socket we can talk to DS on
void completedSocketDiscovery(); void completedSocketDiscovery();
@ -205,6 +203,7 @@ signals:
void domainConnectionRefused(QString reasonMessage, int reason, const QString& extraInfo); void domainConnectionRefused(QString reasonMessage, int reason, const QString& extraInfo);
void redirectToErrorDomainURL(QUrl errorDomainURL); void redirectToErrorDomainURL(QUrl errorDomainURL);
void redirectErrorStateChanged(bool isInErrorState);
void limitOfSilentDomainCheckInsReached(); void limitOfSilentDomainCheckInsReached();

View file

@ -38,7 +38,7 @@ var DEFAULT_SCRIPTS_SEPARATE = [
//"system/chat.js" //"system/chat.js"
]; ];
if (Settings.getValue("enableInterstitialMode", false)) { if (Window.interstitialModeEnabled) {
DEFAULT_SCRIPTS_SEPARATE.push("system/interstitialPage.js"); DEFAULT_SCRIPTS_SEPARATE.push("system/interstitialPage.js");
DEFAULT_SCRIPTS_SEPARATE.push("system/redirectOverlays.js"); DEFAULT_SCRIPTS_SEPARATE.push("system/redirectOverlays.js");
} }

View file

@ -37,6 +37,8 @@
var tablet = null; var tablet = null;
var button = null; var button = null;
var errorConnectingToDomain = false;
// Tips have a character limit of 69 // Tips have a character limit of 69
var userTips = [ var userTips = [
"Tip: Visit TheSpot to explore featured domains!", "Tip: Visit TheSpot to explore featured domains!",
@ -188,6 +190,16 @@
var connectionToDomainFailed = false; var connectionToDomainFailed = false;
function getOopsText() {
var error = Window.getLastDomainConnectionError();
var errorMessageMapIndex = hardRefusalErrors.indexOf(error);
if (errorMessageMapIndex >= 0) {
return ERROR_MESSAGE_MAP[errorMessageMapIndex];
} else {
// some other text.
return ERROR_MESSAGE_MAP[4];
}
}
function getAnchorLocalYOffset() { function getAnchorLocalYOffset() {
var loadingSpherePosition = Overlays.getProperty(loadingSphereID, "position"); var loadingSpherePosition = Overlays.getProperty(loadingSphereID, "position");
@ -235,6 +247,13 @@
} }
} }
function toggleInterstitialPage(isInErrorState) {
errorConnectingToDomain = isInErrorState;
if (!errorConnectingToDomain) {
domainChanged(location);
}
}
function startAudio() { function startAudio() {
sample = Audio.playSound(tune, { sample = Audio.playSound(tune, {
localOnly: true, localOnly: true,
@ -347,10 +366,12 @@
Overlays.editOverlay(loadingBarPlacard, properties); Overlays.editOverlay(loadingBarPlacard, properties);
Overlays.editOverlay(loadingBarProgress, loadingBarProperties); Overlays.editOverlay(loadingBarProgress, loadingBarProperties);
if (errorConnectingToDomain) {
Menu.setIsOptionChecked("Show Overlays", physicsEnabled); Menu.setIsOptionChecked("Show Overlays", physicsEnabled);
if (!HMD.active) { if (!HMD.active) {
toolbar.writeProperty("visible", physicsEnabled); toolbar.writeProperty("visible", physicsEnabled);
} }
}
resetValues(); resetValues();
@ -359,7 +380,6 @@
} }
} }
function scaleInterstitialPage(sensorToWorldScale) { function scaleInterstitialPage(sensorToWorldScale) {
var yOffset = getAnchorLocalYOffset(); var yOffset = getAnchorLocalYOffset();
var localPosition = { var localPosition = {
@ -399,14 +419,19 @@
Overlays.editOverlay(loadingBarProgress, properties); Overlays.editOverlay(loadingBarProgress, properties);
if ((physicsEnabled && (currentProgress >= (TOTAL_LOADING_PROGRESS - EPSILON)))) { if (errorConnectingToDomain) {
updateOverlays(errorConnectingToDomain);
endAudio();
currentDomain = "no domain";
timer = null;
return;
} else if ((physicsEnabled && (currentProgress >= (TOTAL_LOADING_PROGRESS - EPSILON)))) {
updateOverlays((physicsEnabled || connectionToDomainFailed)); updateOverlays((physicsEnabled || connectionToDomainFailed));
endAudio(); endAudio();
currentDomain = "no domain"; currentDomain = "no domain";
timer = null; timer = null;
return; return;
} }
timer = Script.setTimeout(update, BASIC_TIMER_INTERVAL_MS); timer = Script.setTimeout(update, BASIC_TIMER_INTERVAL_MS);
} }
var whiteColor = {red: 255, green: 255, blue: 255}; var whiteColor = {red: 255, green: 255, blue: 255};
@ -430,6 +455,7 @@
connectionToDomainFailed = !location.isConnected; connectionToDomainFailed = !location.isConnected;
}, 1200); }, 1200);
}); });
Window.redirectErrorStateChanged.connect(toggleInterstitialPage);
MyAvatar.sensorToWorldScaleChanged.connect(scaleInterstitialPage); MyAvatar.sensorToWorldScaleChanged.connect(scaleInterstitialPage);
MyAvatar.sessionUUIDChanged.connect(function() { MyAvatar.sessionUUIDChanged.connect(function() {

View file

@ -13,11 +13,10 @@
var TIMEOUT = 5; var TIMEOUT = 5;
var hardRefusalErrors = [PROTOCOL_VERSION_MISMATCH, var hardRefusalErrors = [PROTOCOL_VERSION_MISMATCH,
NOT_AUTHORIZED, TIMEOUT]; NOT_AUTHORIZED, TIMEOUT];
var error = -1;
var timer = null; var timer = null;
function getOopsText() { function getOopsText() {
error = Window.getLastDomainConnectionError(); var error = Window.getLastDomainConnectionError();
var errorMessageMapIndex = hardRefusalErrors.indexOf(error); var errorMessageMapIndex = hardRefusalErrors.indexOf(error);
if (errorMessageMapIndex >= 0) { if (errorMessageMapIndex >= 0) {
return ERROR_MESSAGE_MAP[errorMessageMapIndex]; return ERROR_MESSAGE_MAP[errorMessageMapIndex];
@ -29,58 +28,68 @@
var redirectOopsText = Overlays.addOverlay("text3d", { var redirectOopsText = Overlays.addOverlay("text3d", {
name: "oopsText", name: "oopsText",
localPosition: {x: 0.5691902160644531, y: 0.6403706073760986, z: 6.68358039855957}, localPosition: {x: 0.2691902160644531, y: 0.6403706073760986, z: 3.18358039855957},
localRotation: Quat.fromPitchYawRollDegrees(0.0, 180.0, 0.0),
text: getOopsText(), text: getOopsText(),
textAlpha: 1, textAlpha: 1,
backgroundAlpha: 0, backgroundAlpha: 0,
color: {x: 255, y: 255, z: 255},
lineHeight: 0.10, lineHeight: 0.10,
leftMargin: 0.538373570564886,
visible: false, visible: false,
emissive: true, emissive: true,
ignoreRayIntersection: false, ignoreRayIntersection: false,
drawInFront: true, dimensions: {x: 4.2, y: 1},
grabbable: false, grabbable: false,
orientation: {x: 0.0, y: 0.5, z: 0.0, w: 0.87},
parentID: MyAvatar.SELF_ID, parentID: MyAvatar.SELF_ID,
parentJointIndex: MyAvatar.getJointIndex("Head") parentJointIndex: MyAvatar.getJointIndex("Head")
}); });
var tryAgainImage = Overlays.addOverlay("image3d", { var tryAgainImage = Overlays.addOverlay("image3d", {
name: "tryAgainImage", name: "tryAgainImage",
localPosition: {x: -0.15, y: -0.4, z: 0.0}, localPosition: {x: -0.6, y: -0.4, z: 0.0},
url: Script.resourcesPath() + "images/interstitialPage/button_tryAgain.png", url: Script.resourcesPath() + "images/interstitialPage/button_tryAgain.png",
alpha: 1, alpha: 1,
visible: false, visible: false,
emissive: true, emissive: true,
ignoreRayIntersection: false, ignoreRayIntersection: false,
drawInFront: true,
grabbable: false, grabbable: false,
orientation: {x: 0.0, y: 0.5, z: 0, w: 0.87}, orientation: Overlays.getProperty(redirectOopsText, "orientation"),
parentID: redirectOopsText parentID: redirectOopsText
}); });
var backImage = Overlays.addOverlay("image3d", { var backImage = Overlays.addOverlay("image3d", {
name: "backImage", name: "backImage",
localPosition: {x: 1.0, y: -0.4, z: 0.0}, localPosition: {x: 0.6, y: -0.4, z: 0.0},
url: Script.resourcesPath() + "images/interstitialPage/button_back.png", url: Script.resourcesPath() + "images/interstitialPage/button_back.png",
alpha: 1, alpha: 1,
visible: false, visible: false,
emissive: true, emissive: true,
ignoreRayIntersection: false, ignoreRayIntersection: false,
drawInFront: true,
grabbable: false, grabbable: false,
orientation: {x: 0.0, y: 0.5, z: 0, w: 0.87}, orientation: Overlays.getProperty(redirectOopsText, "orientation"),
parentID: redirectOopsText parentID: redirectOopsText
}); });
var TARGET_UPDATE_HZ = 60; var TARGET_UPDATE_HZ = 60;
var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ; var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ;
function toggleOverlays() { function toggleOverlays(isInErrorState) {
if (!isInErrorState) {
var properties = {
visible: false
};
Overlays.editOverlay(redirectOopsText, properties);
Overlays.editOverlay(tryAgainImage, properties);
Overlays.editOverlay(backImage, properties);
return;
}
var overlaysVisible = false; var overlaysVisible = false;
error = Window.getLastDomainConnectionError(); var error = Window.getLastDomainConnectionError();
var errorMessageMapIndex = hardRefusalErrors.indexOf(error); var errorMessageMapIndex = hardRefusalErrors.indexOf(error);
var oopsText = ""; var oopsText = "";
if (error === -1 || !Window.isPhysicsEnabled() || location.isConnected) { if (error === -1) {
overlaysVisible = false; overlaysVisible = false;
} else if (errorMessageMapIndex >= 0) { } else if (errorMessageMapIndex >= 0) {
overlaysVisible = true; overlaysVisible = true;
@ -93,28 +102,27 @@
visible: overlaysVisible visible: overlaysVisible
}; };
var textWidth = Overlays.textSize(redirectOopsText, oopsText).width;
var textOverlayWidth = Overlays.getProperty(redirectOopsText, "dimensions").x;
var oopsTextProperties = { var oopsTextProperties = {
visible: overlaysVisible, visible: overlaysVisible,
text: oopsText text: oopsText,
leftMargin: (textOverlayWidth - textWidth) / 2
}; };
Overlays.editOverlay(redirectOopsText, oopsTextProperties); Overlays.editOverlay(redirectOopsText, oopsTextProperties);
Overlays.editOverlay(tryAgainImage, properties); Overlays.editOverlay(tryAgainImage, properties);
Overlays.editOverlay(backImage, properties); Overlays.editOverlay(backImage, properties);
} }
function clickedOnOverlay(overlayID, event) { function clickedOnOverlay(overlayID, event) {
var properties = {
visible: false
};
if (tryAgainImage === overlayID) { if (tryAgainImage === overlayID) {
location.goToLastAddress(); location.goToLastAddress();
} else if (backImage === overlayID) { } else if (backImage === overlayID) {
location.goBack(); location.goBack();
} }
Overlays.editOverlay(redirectOopsText, properties);
Overlays.editOverlay(tryAgainImage, properties);
Overlays.editOverlay(backImage, properties);
} }
function cleanup() { function cleanup() {
@ -125,6 +133,8 @@
Overlays.deleteOverlay(backImage); Overlays.deleteOverlay(backImage);
} }
toggleOverlays(true);
var whiteColor = {red: 255, green: 255, blue: 255}; var whiteColor = {red: 255, green: 255, blue: 255};
var greyColor = {red: 125, green: 125, blue: 125}; var greyColor = {red: 125, green: 125, blue: 125};
Overlays.mouseReleaseOnOverlay.connect(clickedOnOverlay); Overlays.mouseReleaseOnOverlay.connect(clickedOnOverlay);
@ -140,8 +150,7 @@
} }
}); });
timer = Script.setInterval(toggleOverlays, 500); Window.redirectErrorStateChanged.connect(toggleOverlays);
// Script.update.connect(toggleOverlays);
Script.scriptEnding.connect(cleanup); Script.scriptEnding.connect(cleanup);
}()); }());