adding 404 redirect toggle with interstitial

This commit is contained in:
Wayne Chen 2018-09-19 09:55:15 -07:00
parent 8b3fff120a
commit 795580f4e1
3 changed files with 45 additions and 24 deletions

View file

@ -18,11 +18,15 @@
#include <DomainHandler.h>
#include <AddressManager.h>
#include <NodeList.h>
#include <SettingHandle.h>
// Because the connection monitor is created at startup, the time we wait on initial load
// should be longer to allow the application to initialize.
static const int ON_INITIAL_LOAD_REDIRECT_AFTER_DISCONNECTED_FOR_X_MS = 10000;
static const int REDIRECT_AFTER_DISCONNECTED_FOR_X_MS = 5000;
static const int ON_INITIAL_LOAD_DISPLAY_AFTER_DISCONNECTED_FOR_X_MS = 10000;
static const int DISPLAY_AFTER_DISCONNECTED_FOR_X_MS = 5000;
Setting::Handle<bool> enableInterstitialMode{ "enableInterstitialMode", false };
void ConnectionMonitor::init() {
// Connect to domain disconnected message
@ -37,20 +41,36 @@ void ConnectionMonitor::init() {
_timer.setSingleShot(true);
if (!domainHandler.isConnected()) {
_timer.start(ON_INITIAL_LOAD_REDIRECT_AFTER_DISCONNECTED_FOR_X_MS);
if (enableInterstitialMode.get()) {
_timer.start(ON_INITIAL_LOAD_REDIRECT_AFTER_DISCONNECTED_FOR_X_MS);
} else {
_timer.start(ON_INITIAL_LOAD_DISPLAY_AFTER_DISCONNECTED_FOR_X_MS);
}
}
connect(&_timer, &QTimer::timeout, this, [this]() {
qDebug() << "ConnectionMonitor: Redirecting to 404 error domain";
// set in a timeout error
emit setRedirectErrorState(REDIRECT_HIFI_ADDRESS, 5);
if (enableInterstitialMode.get()) {
qDebug() << "ConnectionMonitor: Redirecting to 404 error domain";
emit setRedirectErrorState(REDIRECT_HIFI_ADDRESS, 5);
} else {
qDebug() << "ConnectionMonitor: Showing connection failure window";
DependencyManager::get<DialogsManager>()->setDomainConnectionFailureVisibility(true);
}
});
}
void ConnectionMonitor::startTimer() {
_timer.start(REDIRECT_AFTER_DISCONNECTED_FOR_X_MS);
if (enableInterstitialMode.get()) {
_timer.start(REDIRECT_AFTER_DISCONNECTED_FOR_X_MS);
} else {
_timer.start(DISPLAY_AFTER_DISCONNECTED_FOR_X_MS);
}
}
void ConnectionMonitor::stopTimer() {
_timer.stop();
if (!enableInterstitialMode.get()) {
DependencyManager::get<DialogsManager>()->setDomainConnectionFailureVisibility(false);
}
}

View file

@ -140,8 +140,7 @@ public:
* </table>
* @typedef {number} location.LookupTrigger
*/
enum LookupTrigger
{
enum LookupTrigger {
UserInput,
Back,
Forward,
@ -207,9 +206,8 @@ public slots:
// functions and signals that should be exposed are moved to a scripting interface class.
//
// we currently expect this to be called from NodeList once handleLookupString has been called with a path
bool goToViewpointForPath(const QString& viewpointString, const QString& pathString) {
return handleViewpoint(viewpointString, false, DomainPathResponse, false, pathString);
}
bool goToViewpointForPath(const QString& viewpointString, const QString& pathString)
{ return handleViewpoint(viewpointString, false, DomainPathResponse, false, pathString); }
/**jsdoc
* Go back to the previous location in your navigation history, if there is one.
@ -231,8 +229,7 @@ public slots:
* location history is correctly maintained.
*/
void goToLocalSandbox(QString path = "", LookupTrigger trigger = LookupTrigger::StartupFromSettings) {
handleUrl(SANDBOX_HIFI_ADDRESS + path, trigger);
}
handleUrl(SANDBOX_HIFI_ADDRESS + path, trigger); }
/**jsdoc
* Go to the default "welcome" metaverse address.
@ -364,8 +361,7 @@ signals:
* location.locationChangeRequired.connect(onLocationChangeRequired);
*/
void locationChangeRequired(const glm::vec3& newPosition,
bool hasOrientationChange,
const glm::quat& newOrientation,
bool hasOrientationChange, const glm::quat& newOrientation,
bool shouldFaceLocation);
/**jsdoc
@ -448,11 +444,8 @@ private:
bool handleNetworkAddress(const QString& lookupString, LookupTrigger trigger, bool& hostChanged);
void handlePath(const QString& path, LookupTrigger trigger, bool wasPathOnly = false);
bool handleViewpoint(const QString& viewpointString,
bool shouldFace,
LookupTrigger trigger,
bool definitelyPathOnly = false,
const QString& pathString = QString());
bool handleViewpoint(const QString& viewpointString, bool shouldFace, LookupTrigger trigger,
bool definitelyPathOnly = false, const QString& pathString = QString());
bool handleUsername(const QString& lookupString);
bool handleDomainID(const QString& host);

View file

@ -14,6 +14,7 @@
#include <math.h>
#include <PathUtils.h>
#include <SettingHandle.h>
#include <QtCore/QJsonDocument>
#include <QtCore/QDataStream>
@ -29,6 +30,8 @@
#include "UserActivityLogger.h"
#include "NetworkLogging.h"
Setting::Handle<bool> enableInterstitialMode{ "enableInterstitialMode", false };
DomainHandler::DomainHandler(QObject* parent) :
QObject(parent),
_sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)),
@ -485,14 +488,19 @@ void DomainHandler::processDomainServerConnectionDeniedPacket(QSharedPointer<Rec
#if defined(Q_OS_ANDROID)
emit domainConnectionRefused(reasonMessage, (int)reasonCode, extraInfo);
#else
if (reasonCode == ConnectionRefusedReason::ProtocolMismatch || reasonCode == ConnectionRefusedReason::NotAuthorized) {
// ingest the error - this is a "hard" connection refusal.
setRedirectErrorState(_errorDomainURL, (int)reasonCode);
} else {
if (enableInterstitialMode.get()) {
if (reasonCode == ConnectionRefusedReason::ProtocolMismatch || reasonCode == ConnectionRefusedReason::NotAuthorized) {
// ingest the error - this is a "hard" connection refusal.
setRedirectErrorState(_errorDomainURL, (int)reasonCode);
} else {
emit domainConnectionRefused(reasonMessage, (int)reasonCode, extraInfo);
}
_lastDomainConnectionError = (int)reasonCode;
}
else {
emit domainConnectionRefused(reasonMessage, (int)reasonCode, extraInfo);
}
_lastDomainConnectionError = (int)reasonCode;
#endif
#endif
}
auto accountManager = DependencyManager::get<AccountManager>();