diff --git a/domain-server/resources/web/settings/js/settings.js b/domain-server/resources/web/settings/js/settings.js
index cd3878f4b0..e44f3578a3 100644
--- a/domain-server/resources/web/settings/js/settings.js
+++ b/domain-server/resources/web/settings/js/settings.js
@@ -44,6 +44,45 @@ var Settings = {
DATA_ROW_INDEX: 'data-row-index'
};
+var Strings = {
+ LOADING_SETTINGS_ERROR: "There was a problem loading the domain settings.\nPlease refresh the page to try again.",
+
+ CHOOSE_DOMAIN_BUTTON: "Choose from my domains",
+ CREATE_DOMAIN_BUTTON: "Create new domain ID",
+ CREATE_DOMAIN_SUCCESS_JUST_CONNECTED: "We connnected your High Fidelity account and created a new domain ID for this machine.",
+ CREATE_DOMAIN_SUCCESS: "We created a new domain ID for this machine.",
+
+ // When a place modification fails, they will be brought back to the previous
+ // dialog with new path still set, allowing them to retry immediately, and without
+ // having to type the new path in again.
+ EDIT_PLACE_TITLE: "Modify Viewpoint or Path",
+ EDIT_PLACE_ERROR: "Failed to update place path. Please try again.",
+ EDIT_PLACE_CONFIRM_BUTTON: "Save",
+ EDIT_PLACE_CONFIRM_BUTTON_PENDING: "Saving...",
+ EDIT_PLACE_CANCEL_BUTTON: "Cancel",
+
+ REMOVE_PLACE_TITLE: "Are you sure you want to remove {{place}}?",
+ REMOVE_PLACE_ERROR: "Failed to remove place. Please try again.",
+ REMOVE_PLACE_DELETE_BUTTON: "Delete",
+ REMOVE_PLACE_DELETE_BUTTON_PENDING: "Deleting...",
+ REMOVE_PLACE_CANCEL_BUTTON: "Cancel",
+
+ ADD_PLACE_TITLE: "Choose a place",
+ ADD_PLACE_MESSAGE: "Choose the High Fidelity place to point at this domain server.",
+ ADD_PLACE_CONFIRM_BUTTON: "Choose place",
+ ADD_PLACE_CONFIRM_BUTTON_PENDING: "Saving...",
+ ADD_PLACE_CANCEL_BUTTON: "Cancel",
+ ADD_PLACE_UNKNOWN_ERROR: "There was an error adding this place name.",
+
+ ADD_PLACE_NO_PLACES_MESSAGE: "
You do not have any places in your High Fidelity account."
+ + "
Go to your places page to create a new one. Once your place is created re-open this dialog to select it.
",
+ ADD_PLACE_NO_PLACES_BUTTON: "Create new place",
+ ADD_PLACE_UNABLE_TO_LOAD_ERROR: "We were unable to load your place names. Please try again later.",
+ ADD_PLACE_LOADING_DIALOG: "Loading your places...",
+};
+
+var DomainInfo = null;
+
var viewHelpers = {
getFormGroup: function(keypath, setting, values, isAdvanced) {
form_group = "
'"
-
_.each(setting.options, function(option) {
form_group += ""
- })
+ });
form_group += ""
@@ -142,11 +180,12 @@ var qs = (function(a) {
var b = {};
for (var i = 0; i < a.length; ++i)
{
- var p=a[i].split('=', 2);
- if (p.length == 1)
- b[p[0]] = "";
- else
- b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
+ var p=a[i].split('=', 2);
+ if (p.length == 1) {
+ b[p[0]] = "";
+ } else {
+ b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
+ }
}
return b;
})(window.location.search.substr(1).split('&'));
@@ -160,6 +199,10 @@ $(document).ready(function(){
* Author: LV
*/
+ $.ajaxSetup({
+ timeout: 20000,
+ });
+
$('[data-clampedwidth]').each(function () {
var elem = $(this);
var parentPanel = elem.data('clampedwidth');
@@ -346,7 +389,7 @@ $(document).ready(function(){
swal({
title: '',
type: 'error',
- text: "There was a problem loading the domain settings.\nPlease refresh the page to try again.",
+ text: Strings.LOADING_SETTINGS_ERROR
});
}
});
@@ -440,26 +483,27 @@ function postSettings(jsonSettings) {
});
}
+function accessTokenIsSet() {
+ return Settings.data.values.metaverse.access_token.length > 0;
+}
+
function setupHFAccountButton() {
- // figure out how we should handle the HF connect button
- var accessToken = Settings.data.values.metaverse.access_token;
- // setup an object for the settings we want our button to have
- var buttonSetting = {
- type: 'button',
- name: 'connected_account',
- label: 'Connected Account',
- }
-
- var hasAccessToken = accessToken.length > 0;
+ var hasAccessToken = accessTokenIsSet();
+ var el;
if (hasAccessToken) {
- buttonSetting.help = "Click the button above to clear your OAuth token and disconnect your High Fidelity account.";
- buttonSetting.classes = "btn-danger";
- buttonSetting.button_label = "Disconnect High Fidelity Account";
- buttonSetting.html_id = Settings.DISCONNECT_ACCOUNT_BTN_ID;
+ el = "High Fidelity Account Connected";
+ el += "";
+ el = $(el);
} else {
- buttonSetting.help = "Click the button above to connect your High Fidelity account.";
+ // setup an object for the settings we want our button to have
+ var buttonSetting = {
+ type: 'button',
+ name: 'connected_account',
+ label: 'Connected Account',
+ }
+ buttonSetting.help = "";
buttonSetting.classes = "btn-primary";
buttonSetting.button_label = "Connect High Fidelity Account";
buttonSetting.html_id = Settings.CONNECT_ACCOUNT_BTN_ID;
@@ -469,14 +513,13 @@ function setupHFAccountButton() {
// since we do not have an access token we change hide domain ID and auto networking settings
// without an access token niether of them can do anything
$("[data-keypath='metaverse.id']").hide();
- $("[data-keypath='metaverse.automatic_networking']").hide();
// use the existing getFormGroup helper to ask for a button
- var buttonGroup = viewHelpers.getFormGroup('', buttonSetting, Settings.data.values);
+ el = viewHelpers.getFormGroup('', buttonSetting, Settings.data.values);
+ }
// add the button group to the top of the metaverse panel
- $('#metaverse .panel-body').prepend(buttonGroup);
- }
+ $('#metaverse .panel-body').prepend(el);
}
@@ -593,21 +636,20 @@ function showDomainCreationAlert(justConnected) {
function createNewDomainID(description, justConnected) {
// get the JSON object ready that we'll use to create a new domain
var domainJSON = {
- "private_description": description
+ "label": description
//"access_token": $(Settings.ACCESS_TOKEN_SELECTOR).val()
}
- //$.post(Settings.METAVERSE_URL + "/api/v1/domains", domainJSON, function(data){
- $.post("/api/domain", domainJSON, function(data){
+ $.post("/api/domains", domainJSON, function(data){
// we successfully created a domain ID, set it on that field
var domainID = data.domain_id;
console.log("Setting domain id to ", data, domainID);
$(Settings.DOMAIN_ID_SELECTOR).val(domainID).change();
if (justConnected) {
- var successText = "We connnected your High Fidelity account and created a new domain ID for this machine."
+ var successText = Strings.CREATE_DOMAIN_SUCCESS_JUST_CONNECTED
} else {
- var successText = "We created a new domain ID for this machine."
+ var successText = Strings.CREATE_DOMAIN_SUCCESS;
}
successText += "Click the button below to save your new settings and restart your domain-server.";
@@ -656,6 +698,258 @@ function createNewDomainID(description, justConnected) {
});
}
+function createDomainSpinner() {
+ var spinner = '
You do not have any domains in your High Fidelity account." +
- "
Go to your domains page to create a new one. Once your domain is created re-open this dialog to select it.
"
+ },
+ error: function() {
+ bootbox.alert("Failed to retrieve your domains from the High Fidelity Metaverse");
+ },
+ complete: function() {
+ // remove the spinner from the choose button
+ clickedButton.html("Choose from my domains")
+ clickedButton.removeAttr('disabled')
}
+ });
- bootbox.dialog({
- title: "Choose matching domain",
- message: modal_body,
- buttons: modal_buttons
- })
-
- // remove the spinner from the choose button
- clickedButton.html("Choose from my domains")
- clickedButton.removeAttr('disabled')
- })
-
- } else {
- bootbox.alert({
- message: "You must have an access token to query your High Fidelity domains.
" +
+ } else {
+ bootbox.alert({
+ message: "You must have an access token to query your High Fidelity domains.
" +
"Please follow the instructions on the settings page to add an access token.",
- title: "Access token required"
- })
+ title: "Access token required"
+ })
+ }
}
-}
function createTemporaryDomain() {
swal({
@@ -1135,6 +1514,14 @@ function reloadSettings(callback) {
// call our method to setup the place names table
setupPlacesTable();
+ setupDomainNetworkingSettings();
+ setupDomainLabelSetting();
+
+ if (Settings.data.values.metaverse.id.length > 0) {
+ // now, ask the API for what places, if any, point to this domain
+ reloadDomainInfo();
+ }
+
// setup any bootstrap switches
$('.toggle-checkbox').bootstrapSwitch();
diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp
index 8853704aef..1fb83611ef 100644
--- a/domain-server/src/DomainServer.cpp
+++ b/domain-server/src/DomainServer.cpp
@@ -1747,7 +1747,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
const QString URI_ENTITY_FILE_UPLOAD = "/content/upload";
const QString URI_RESTART = "/restart";
const QString URI_API_PLACES = "/api/places";
- const QString URI_API_DOMAIN = "/api/domain";
+ const QString URI_API_DOMAINS = "/api/domains";
const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
@@ -1907,7 +1907,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
connection->respond(HTTPConnection::StatusCode200);
restart();
return true;
- } else if (url.path() == URI_API_DOMAIN) {
+ } else if (url.path() == URI_API_DOMAINS) {
QUrl url { BASE_METAVERSE_URL + "/api/v1/domains" };
auto accessTokenVariant = valueForKeyPath(_settingsManager.getSettingsMap(), ACCESS_TOKEN_KEY_PATH);
@@ -1923,7 +1923,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
connect(reply, &QNetworkReply::finished, this, [reply, connection]() {
if (reply->error() != QNetworkReply::NoError) {
- connection->respond(HTTPConnection::StatusCode500);
+ qDebug() << reply << reply->errorString() << reply->readAll();
+ connection->respond(HTTPConnection::StatusCode500, reply->readAll());
return;
}
@@ -2059,7 +2060,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
return true;
}
- } else if (url.path() == URI_API_DOMAIN) {
+ } else if (url.path() == URI_API_DOMAINS) {
auto accessTokenVariant = valueForKeyPath(_settingsManager.getSettingsMap(), ACCESS_TOKEN_KEY_PATH);
if (!accessTokenVariant) {
connection->respond(HTTPConnection::StatusCode400, "User access token has not been set");
@@ -2092,7 +2093,9 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
auto responseData = reply->readAll();
if (reply->error() != QNetworkReply::NoError) {
connection->respond(HTTPConnection::StatusCode500,
- "Error communicating with Metaverse");
+ responseData);
+
+ //"Error communicating with Metaverse");
return;
}
@@ -2121,7 +2124,76 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
return true;
}
} else if (connection->requestOperation() == QNetworkAccessManager::PutOperation) {
- if (url.path() == URI_API_PLACES) {
+ if (url.path() == URI_API_DOMAINS) {
+ QVariantMap& settingsMap = _settingsManager.getSettingsMap();
+ auto domainSetting = valueForKeyPath(settingsMap, METAVERSE_DOMAIN_ID_KEY_PATH);
+ if (domainSetting == nullptr) {
+ connection->respond(HTTPConnection::StatusCode400, "Domain id has not been set");
+ return true;
+ }
+
+ auto accessTokenVariant = valueForKeyPath(_settingsManager.getSettingsMap(), ACCESS_TOKEN_KEY_PATH);
+ if (!accessTokenVariant->isValid()) {
+ connection->respond(HTTPConnection::StatusCode400, "User access token has not been set");
+ return true;
+ }
+
+ auto domainID = valueForKeyPath(settingsMap, METAVERSE_DOMAIN_ID_KEY_PATH)->toString();
+
+ auto params = connection->parseUrlEncodedForm();
+
+ QJsonObject domainObj;
+
+ auto it = params.find("network_address");
+ if (it != params.end()) {
+ QString address = it.value();
+ domainObj["network_address"] = address.isEmpty() ? QJsonValue::Null : QJsonValue(address);
+ }
+
+ it = params.find("network_port");
+ if (it != params.end()) {
+ QString port = it.value();
+ domainObj["network_port"] = port.isEmpty() ? QJsonValue::Null : QJsonValue(port);
+ }
+
+ it = params.find("private_description");
+ if (it != params.end()) {
+ domainObj["private_description"] = it.value();
+ }
+
+
+ QJsonObject root { { "domain", domainObj } };
+ QJsonDocument doc(root);
+ qDebug() << "Sending " << doc.toJson() << connection->requestContent();
+
+ QUrl url { BASE_METAVERSE_URL + "/api/v1/domains/" + domainID };
+
+ url.setQuery("access_token=" + accessTokenVariant->toString());
+
+ QNetworkRequest req(url);
+ req.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
+ req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
+ QNetworkReply* reply = NetworkAccessManager::getInstance().put(req, doc.toJson());
+
+ connect(reply, &QNetworkReply::finished, this, [reply, connection]() {
+ if (reply->error() != QNetworkReply::NoError) {
+ auto data = reply->readAll();
+ qDebug() << "Got error response from metaverse server: " << data;
+ connection->respond(HTTPConnection::StatusCode400, data);
+ return;
+ }
+
+ static const char* CONTENT_TYPE_JSON { "application/json" };
+ connection->respond(HTTPConnection::StatusCode200, reply->readAll());
+ });
+ return true;
+ } else if (url.path() == URI_API_PLACES) {
+ auto accessTokenVariant = valueForKeyPath(_settingsManager.getSettingsMap(), ACCESS_TOKEN_KEY_PATH);
+ if (!accessTokenVariant->isValid()) {
+ connection->respond(HTTPConnection::StatusCode400, "User access token has not been set");
+ return true;
+ }
+
auto params = connection->parseUrlEncodedForm();
auto it = params.find("place_id");
@@ -2147,7 +2219,6 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
domain_id = it.value();
}
-
QJsonObject root {
{
"place",
@@ -2162,11 +2233,6 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
QUrl url { BASE_METAVERSE_URL + "/api/v1/places/" + place_id };
- auto accessTokenVariant = valueForKeyPath(_settingsManager.getSettingsMap(), ACCESS_TOKEN_KEY_PATH);
- if (!accessTokenVariant->isValid()) {
- connection->respond(HTTPConnection::StatusCode400, "User access token has not been set");
- }
-
url.setQuery("access_token=" + accessTokenVariant->toString());
QNetworkRequest req(url);
diff --git a/libraries/networking/src/NetworkingConstants.h b/libraries/networking/src/NetworkingConstants.h
index a512ae8887..b91b75625c 100644
--- a/libraries/networking/src/NetworkingConstants.h
+++ b/libraries/networking/src/NetworkingConstants.h
@@ -15,7 +15,7 @@
#include
namespace NetworkingConstants {
- const QUrl METAVERSE_SERVER_URL = QUrl("https://metaverse.highfidelity.com");
+ const QUrl METAVERSE_SERVER_URL = QUrl("https://staging.highfidelity.com");
}
#endif // hifi_NetworkingConstants_h