adding serverless file + redirection if conn fail

This commit is contained in:
Wayne Chen 2018-08-28 15:50:14 -07:00
parent 467fe56103
commit 8a9ad421e7
6 changed files with 42 additions and 1 deletions

View file

@ -341,6 +341,8 @@ else()
set(INTERFACE_EXEC_DIR "$<TARGET_FILE_DIR:${TARGET_NAME}>")
set(RESOURCES_DEV_DIR "${INTERFACE_EXEC_DIR}/resources")
message(STATUS "${RESOURCES_DEV_DIR}")
# copy the resources files beside the executable
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
@ -360,6 +362,9 @@ else()
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${PROJECT_SOURCE_DIR}/resources/serverless/tutorial.json"
"${RESOURCES_DEV_DIR}/serverless/tutorial.json"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${PROJECT_SOURCE_DIR}/resources/serverless/redirect.json"
"${RESOURCES_DEV_DIR}/serverless/redirect.json"
# copy JSDoc files beside the executable
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${CMAKE_SOURCE_DIR}/tools/jsdoc/out"

File diff suppressed because one or more lines are too long

View file

@ -1193,7 +1193,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
getOverlays().deleteOverlay(getTabletHomeButtonID());
getOverlays().deleteOverlay(getTabletFrameID());
});
#if defined(Q_OS_ANDROID)
connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &Application::domainConnectionRefused);
#else
connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &Application::domainConnectionRedirect);
#endif
// We could clear ATP assets only when changing domains, but it's possible that the domain you are connected
// to has gone down and switched to a new content set, so when you reconnect the cached ATP assets will no longer be valid.
@ -2313,6 +2317,35 @@ void Application::domainConnectionRefused(const QString& reasonMessage, int reas
}
}
void Application::domainConnectionRedirect(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) {
DomainHandler::ConnectionRefusedReason reasonCode = static_cast<DomainHandler::ConnectionRefusedReason>(reasonCodeInt);
auto addressManager = DependencyManager::get<AddressManager>();
if (reasonCode == DomainHandler::ConnectionRefusedReason::TooManyUsers && !extraInfo.isEmpty()) {
addressManager->handleLookupString(extraInfo);
return;
}
switch (reasonCode) {
case DomainHandler::ConnectionRefusedReason::ProtocolMismatch:
case DomainHandler::ConnectionRefusedReason::TooManyUsers:
case DomainHandler::ConnectionRefusedReason::Unknown: {
QString message = "Unable to connect to the location you are visiting.\n";
message += reasonMessage;
//OffscreenUi::asyncWarning("", message);
addressManager->handleLookupString(REDIRECT_HIFI_ADDRESS);
getMyAvatar()->setWorldVelocity(glm::vec3(0.0f));
// in (w, x, y, z) component-structure for the constructor
getMyAvatar()->setWorldOrientation(glm::quat(0.8775935173034668f, 0.0f, 0.4794054925441742f, 0.0f));
break;
}
default:
// nothing to do.
break;
}
}
QString Application::getUserAgent() {
if (QThread::currentThread() != thread()) {
QString userAgent;

View file

@ -471,6 +471,7 @@ private slots:
void updateDisplayMode();
void setDisplayPlugin(DisplayPluginPointer newPlugin);
void domainConnectionRefused(const QString& reasonMessage, int reason, const QString& extraInfo);
void domainConnectionRedirect(const QString& reasonMessage, int reason, const QString& extraInfo);
void addAssetToWorldCheckModelSize();

View file

@ -31,6 +31,7 @@
#include "udt/PacketHeaders.h"
const QString DEFAULT_HIFI_ADDRESS = "file:///~/serverless/tutorial.json";
const QString REDIRECT_HIFI_ADDRESS = "file:///~/serverless/redirect.json";
const QString ADDRESS_MANAGER_SETTINGS_GROUP = "AddressManager";
const QString SETTINGS_CURRENT_ADDRESS_KEY = "address";
@ -709,7 +710,6 @@ bool AddressManager::handleViewpoint(const QString& viewpointString, bool should
// We use _newHostLookupPath to determine if the client has already stored its last address
// before moving to a new host thanks to the information in the same lookup URL.
if (definitelyPathOnly || (!pathString.isEmpty() && pathString != _newHostLookupPath)
|| trigger == Back || trigger == Forward) {
addCurrentAddressToHistory(trigger);

View file

@ -23,6 +23,7 @@
#include "AccountManager.h"
extern const QString DEFAULT_HIFI_ADDRESS;
extern const QString REDIRECT_HIFI_ADDRESS;
const QString SANDBOX_HIFI_ADDRESS = "hifi://localhost";
const QString INDEX_PATH = "/";