mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 08:14:48 +02:00
Lots of changes; marketplaces.js working now
This commit is contained in:
parent
de2548d926
commit
01073ca18d
7 changed files with 1747 additions and 1711 deletions
|
@ -252,12 +252,6 @@ bool ContextOverlayInterface::destroyContextOverlay(const EntityItemID& entityIt
|
|||
void ContextOverlayInterface::contextOverlays_mousePressOnOverlay(const OverlayID& overlayID, const PointerEvent& event) {
|
||||
if (overlayID == _contextOverlayID && event.getButton() == PointerEvent::PrimaryButton) {
|
||||
qCDebug(context_overlay) << "Clicked Context Overlay. Entity ID:" << _currentEntityWithContextOverlay << "Overlay ID:" << overlayID;
|
||||
Setting::Handle<bool> _settingSwitch{ "commerce", true };
|
||||
if (_settingSwitch.get()) {
|
||||
openInspectionCertificate();
|
||||
} else {
|
||||
openMarketplace();
|
||||
}
|
||||
emit contextOverlayClicked(_currentEntityWithContextOverlay);
|
||||
_contextOverlayJustClicked = true;
|
||||
}
|
||||
|
@ -390,34 +384,6 @@ void ContextOverlayInterface::requestOwnershipVerification(const QUuid& entityID
|
|||
}
|
||||
}
|
||||
|
||||
static const QString INSPECTION_CERTIFICATE_QML_PATH = "hifi/commerce/inspectionCertificate/InspectionCertificate.qml";
|
||||
void ContextOverlayInterface::openInspectionCertificate() {
|
||||
// lets open the tablet to the inspection certificate QML
|
||||
if (!_currentEntityWithContextOverlay.isNull() && _entityMarketplaceID.length() > 0) {
|
||||
setLastInspectedEntity(_currentEntityWithContextOverlay);
|
||||
auto tablet = dynamic_cast<TabletProxy*>(_tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
tablet->loadQMLSource(INSPECTION_CERTIFICATE_QML_PATH);
|
||||
_hmdScriptingInterface->openTablet();
|
||||
}
|
||||
}
|
||||
|
||||
static const QString MARKETPLACE_BASE_URL = NetworkingConstants::METAVERSE_SERVER_URL().toString() + "/marketplace/items/";
|
||||
|
||||
void ContextOverlayInterface::openMarketplace() {
|
||||
// lets open the tablet and go to the current item in
|
||||
// the marketplace (if the current entity has a
|
||||
// marketplaceID)
|
||||
if (!_currentEntityWithContextOverlay.isNull() && _entityMarketplaceID.length() > 0) {
|
||||
auto tablet = dynamic_cast<TabletProxy*>(_tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
// construct the url to the marketplace item
|
||||
QString url = MARKETPLACE_BASE_URL + _entityMarketplaceID;
|
||||
QString MARKETPLACES_INJECT_SCRIPT_PATH = "file:///" + qApp->applicationDirPath() + "/scripts/system/html/js/marketplacesInject.js";
|
||||
tablet->gotoWebScreen(url, MARKETPLACES_INJECT_SCRIPT_PATH);
|
||||
_hmdScriptingInterface->openTablet();
|
||||
_isInMarketplaceInspectionMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) {
|
||||
_selectionScriptingInterface->addToSelectedItemsList("contextOverlayHighlightList", "entity", entityItemID);
|
||||
}
|
||||
|
|
|
@ -94,8 +94,6 @@ private:
|
|||
|
||||
bool _isInMarketplaceInspectionMode { false };
|
||||
|
||||
void openInspectionCertificate();
|
||||
void openMarketplace();
|
||||
void enableEntityHighlight(const EntityItemID& entityItemID);
|
||||
void disableEntityHighlight(const EntityItemID& entityItemID);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"use strict";
|
||||
/*global Tablet, Script*/
|
||||
/* global Tablet, Script */
|
||||
//
|
||||
// libraries/appUi.js
|
||||
//
|
||||
|
@ -31,53 +31,49 @@ function AppUi(properties) {
|
|||
var that = this;
|
||||
function defaultButton(name, suffix) {
|
||||
var base = that[name] || (that.buttonPrefix + suffix);
|
||||
that[name] = (base.indexOf('/') >= 0) ? base : (that.graphicsDirectory + base); //poor man's merge
|
||||
that[name] = (base.indexOf('/') >= 0) ? base : (that.graphicsDirectory + base); // poor man's merge
|
||||
}
|
||||
|
||||
// Defaults:
|
||||
that.tabletName = "com.highfidelity.interface.tablet.system";
|
||||
that.inject = "";
|
||||
that.graphicsDirectory = "icons/tablet-icons/"; // Where to look for button svgs. See below.
|
||||
that.additionalAppScreens = [];
|
||||
that.checkIsOpen = function checkIsOpen(type, tabletUrl) { // Are we active? Value used to set isOpen.
|
||||
return (type === that.type) && that.currentUrl && (tabletUrl.indexOf(that.currentUrl) >= 0); // Actual url may have prefix or suffix.
|
||||
// Actual url may have prefix or suffix.
|
||||
return (type === that.currentVisibleScreenType) &&
|
||||
that.currentVisibleUrl &&
|
||||
((that.home.indexOf(that.currentVisibleUrl) > -1) ||
|
||||
(that.additionalAppScreens.indexOf(that.currentVisibleUrl) > -1));
|
||||
};
|
||||
that.setCurrentData = function setCurrentData(url) {
|
||||
that.currentUrl = url;
|
||||
that.type = /.qml$/.test(url) ? 'QML' : 'Web';
|
||||
}
|
||||
that.open = function open(optionalUrl) { // How to open the app.
|
||||
that.setCurrentVisibleScreenMetadata = function setCurrentVisibleScreenMetadata(type, url) {
|
||||
that.currentVisibleScreenType = type;
|
||||
that.currentVisibleUrl = url;
|
||||
};
|
||||
that.open = function open(optionalUrl, optionalInject) { // How to open the app.
|
||||
var url = optionalUrl || that.home;
|
||||
that.setCurrentData(url);
|
||||
if (that.isQML()) {
|
||||
var inject = that.inject;
|
||||
if (optionalUrl && optionalInject) {
|
||||
inject = optionalInject;
|
||||
}
|
||||
|
||||
if (that.isQMLUrl(url)) {
|
||||
that.tablet.loadQMLSource(url);
|
||||
} else {
|
||||
that.tablet.gotoWebScreen(url, that.inject);
|
||||
that.tablet.gotoWebScreen(url, inject);
|
||||
}
|
||||
};
|
||||
that.openNewApp = function openNewApp(url, optionalInject) { // Opens some app and replaces the current app
|
||||
if (that.isQML(url)) {
|
||||
that.tablet.pushOntoStack(url);
|
||||
} else {
|
||||
if (optionalInject) {
|
||||
that.tablet.gotoWebScreen(url, optionalInject);
|
||||
} else {
|
||||
that.tablet.gotoWebScreen(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
that.openNewAppOnTop = function openNewAppOnTop(url, optionalInject) { // Opens some app on top of the current app (on desktop, opens new window)
|
||||
if (that.isQML(url)) {
|
||||
// Opens some app on top of the current app (on desktop, opens new window)
|
||||
that.openNewAppOnTop = function openNewAppOnTop(url, optionalInject) {
|
||||
var inject = optionalInject || "";
|
||||
if (that.isQMLUrl(url)) {
|
||||
that.tablet.loadQMLOnTop(url);
|
||||
} else {
|
||||
if (optionalInject) {
|
||||
that.tablet.loadWebScreenOnTop(url, optionalInject);
|
||||
} else {
|
||||
that.tablet.loadWebScreenOnTop(url);
|
||||
}
|
||||
that.tablet.loadWebScreenOnTop(url, inject);
|
||||
}
|
||||
}
|
||||
};
|
||||
that.close = function close() { // How to close the app.
|
||||
that.currentUrl = "";
|
||||
that.currentVisibleUrl = "";
|
||||
// for toolbar-mode: go back to home screen, this will close the window.
|
||||
that.tablet.gotoHomeScreen();
|
||||
};
|
||||
|
@ -91,15 +87,40 @@ function AppUi(properties) {
|
|||
activeIcon: isWaiting ? that.activeMessagesButton : that.activeButton
|
||||
});
|
||||
};
|
||||
that.isQML = function isQML(optionalUrl) { // We set type property in onClick.
|
||||
if (optionalUrl) {
|
||||
var type = /.qml$/.test(optionalUrl) ? 'QML' : 'Web';
|
||||
return type === 'QML';
|
||||
}
|
||||
return that.type === 'QML';
|
||||
that.isQMLUrl = function isQMLUrl(url) {
|
||||
var type = /.qml$/.test(url) ? 'QML' : 'Web';
|
||||
return type === 'QML';
|
||||
};
|
||||
that.eventSignal = function eventSignal() { // What signal to hook onMessage to.
|
||||
return that.isQML() ? that.tablet.fromQml : that.tablet.webEventReceived;
|
||||
that.isCurrentlyOnQMLScreen = function isCurrentlyOnQMLScreen() {
|
||||
return that.currentVisibleScreenType === 'QML';
|
||||
};
|
||||
|
||||
// Handlers
|
||||
that.onScreenChanged = function onScreenChanged(type, url) {
|
||||
// Set isOpen, wireEventBridge, set buttonActive as appropriate,
|
||||
// and finally call onOpened() or onClosed() IFF defined.
|
||||
that.setCurrentVisibleScreenMetadata(type, url);
|
||||
if (that.checkIsOpen(type, url)) {
|
||||
that.wireEventBridge(true);
|
||||
if (!that.isOpen) {
|
||||
that.buttonActive(true);
|
||||
if (that.onOpened) {
|
||||
that.onOpened();
|
||||
}
|
||||
that.isOpen = true;
|
||||
}
|
||||
} else { // Not us. Should we do something for type Home, Menu, and particularly Closed (meaning tablet hidden?
|
||||
that.wireEventBridge(false);
|
||||
if (that.isOpen) {
|
||||
that.buttonActive(false);
|
||||
if (that.onClosed) {
|
||||
that.onClosed();
|
||||
}
|
||||
that.isOpen = false;
|
||||
}
|
||||
}
|
||||
console.debug(that.buttonName + " app reports: Tablet screen changed.\nNew screen type: " + type +
|
||||
"\nNew screen URL: " + url + "\nCurrent app open status: " + that.isOpen + "\n");
|
||||
};
|
||||
|
||||
// Overwrite with the given properties:
|
||||
|
@ -126,65 +147,55 @@ function AppUi(properties) {
|
|||
}
|
||||
that.button = that.tablet.addButton(buttonOptions);
|
||||
that.ignore = function ignore() { };
|
||||
|
||||
// Handlers
|
||||
that.onScreenChanged = function onScreenChanged(type, url) {
|
||||
// Set isOpen, wireEventBridge, set buttonActive as appropriate,
|
||||
// and finally call onOpened() or onClosed() IFF defined.
|
||||
console.debug(that.buttonName, 'onScreenChanged', type, url, that.isOpen);
|
||||
if (that.checkIsOpen(type, url)) {
|
||||
if (!that.isOpen) {
|
||||
that.wireEventBridge(true);
|
||||
that.buttonActive(true);
|
||||
if (that.onOpened) {
|
||||
that.onOpened();
|
||||
}
|
||||
that.isOpen = true;
|
||||
}
|
||||
|
||||
} else { // Not us. Should we do something for type Home, Menu, and particularly Closed (meaning tablet hidden?
|
||||
if (that.isOpen) {
|
||||
that.wireEventBridge(false);
|
||||
that.buttonActive(false);
|
||||
if (that.onClosed) {
|
||||
that.onClosed();
|
||||
}
|
||||
that.isOpen = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
that.hasEventBridge = false;
|
||||
that.hasQmlEventBridge = false;
|
||||
that.hasHtmlEventBridge = false;
|
||||
// HTML event bridge uses strings, not objects. Here we abstract over that.
|
||||
// (Although injected javascript still has to use JSON.stringify/JSON.parse.)
|
||||
that.sendToHtml = function (messageObject) { that.tablet.emitScriptEvent(JSON.stringify(messageObject)); };
|
||||
that.fromHtml = function (messageString) { that.onMessage(JSON.parse(messageString)); };
|
||||
that.sendToHtml = function (messageObject) {
|
||||
that.tablet.emitScriptEvent(JSON.stringify(messageObject));
|
||||
};
|
||||
that.fromHtml = function (messageString) {
|
||||
var parsedMessage = JSON.parse(messageString);
|
||||
parsedMessage.messageSrc = "HTML";
|
||||
that.onMessage(parsedMessage);
|
||||
};
|
||||
that.sendMessage = that.ignore;
|
||||
that.wireEventBridge = function wireEventBridge(on) {
|
||||
// Uniquivocally sets that.sendMessage(messageObject) to do the right thing.
|
||||
// Sets hasEventBridge and wires onMessage to eventSignal as appropriate, IFF onMessage defined.
|
||||
var handler, isQml = that.isQML();
|
||||
// Sets has*EventBridge and wires onMessage to the proper event bridge as appropriate, IFF onMessage defined.
|
||||
var isCurrentlyOnQMLScreen = that.isCurrentlyOnQMLScreen();
|
||||
// Outbound (always, regardless of whether there is an inbound handler).
|
||||
if (on) {
|
||||
that.sendMessage = isQml ? that.tablet.sendToQml : that.sendToHtml;
|
||||
that.sendMessage = isCurrentlyOnQMLScreen ? that.tablet.sendToQml : that.sendToHtml;
|
||||
} else {
|
||||
that.sendMessage = that.ignore;
|
||||
}
|
||||
|
||||
if (!that.onMessage) { return; }
|
||||
if (!that.onMessage) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Inbound
|
||||
handler = isQml ? that.onMessage : that.fromHtml;
|
||||
if (on) {
|
||||
if (!that.hasEventBridge) {
|
||||
console.debug(that.buttonName, 'connecting', that.eventSignal());
|
||||
that.eventSignal().connect(handler);
|
||||
that.hasEventBridge = true;
|
||||
if (isCurrentlyOnQMLScreen && !that.hasQmlEventBridge) {
|
||||
console.debug(that.buttonName, 'connecting', that.tablet.fromQml);
|
||||
that.tablet.fromQml.connect(that.onMessage);
|
||||
that.hasQmlEventBridge = true;
|
||||
} else if (!isCurrentlyOnQMLScreen && !that.hasHtmlEventBridge) {
|
||||
console.debug(that.buttonName, 'connecting', that.tablet.webEventReceived);
|
||||
that.tablet.webEventReceived.connect(that.fromHtml);
|
||||
that.hasHtmlEventBridge = true;
|
||||
}
|
||||
} else {
|
||||
if (that.hasEventBridge) {
|
||||
console.debug(that.buttonName, 'disconnecting', that.eventSignal());
|
||||
that.eventSignal().disconnect(handler);
|
||||
that.hasEventBridge = false;
|
||||
if (that.hasQmlEventBridge) {
|
||||
console.debug(that.buttonName, 'disconnecting', that.tablet.fromQml);
|
||||
that.tablet.fromQml.disconnect(that.onMessage);
|
||||
that.hasQmlEventBridge = false;
|
||||
}
|
||||
if (that.hasHtmlEventBridge) {
|
||||
console.debug(that.buttonName, 'disconnecting', that.tablet.webEventReceived);
|
||||
that.tablet.webEventReceived.disconnect(that.fromHtml);
|
||||
that.hasHtmlEventBridge = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,3 +1,5 @@
|
|||
/* global $, window, MutationObserver */
|
||||
|
||||
//
|
||||
// marketplacesInject.js
|
||||
//
|
||||
|
@ -11,7 +13,6 @@
|
|||
//
|
||||
|
||||
(function () {
|
||||
|
||||
// Event bridge messages.
|
||||
var CLARA_IO_DOWNLOAD = "CLARA.IO DOWNLOAD";
|
||||
var CLARA_IO_STATUS = "CLARA.IO STATUS";
|
||||
|
@ -24,7 +25,7 @@
|
|||
|
||||
var canWriteAssets = false;
|
||||
var xmlHttpRequest = null;
|
||||
var isPreparing = false; // Explicitly track download request status.
|
||||
var isPreparing = false; // Explicitly track download request status.
|
||||
|
||||
var commerceMode = false;
|
||||
var userIsLoggedIn = false;
|
||||
|
@ -33,7 +34,6 @@
|
|||
var messagesWaiting = false;
|
||||
|
||||
function injectCommonCode(isDirectoryPage) {
|
||||
|
||||
// Supporting styles from marketplaces.css.
|
||||
// Glyph font family, size, and spacing adjusted because HiFi-Glyphs cannot be used cross-domain.
|
||||
$("head").append(
|
||||
|
@ -74,7 +74,9 @@
|
|||
(document.referrer !== "") ? window.history.back() : window.location = (marketplaceBaseURL + "/marketplace?");
|
||||
});
|
||||
$("#all-markets").on("click", function () {
|
||||
EventBridge.emitWebEvent(GOTO_DIRECTORY);
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: GOTO_DIRECTORY
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -94,11 +96,11 @@
|
|||
});
|
||||
}
|
||||
|
||||
emitWalletSetupEvent = function() {
|
||||
var emitWalletSetupEvent = function () {
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: "WALLET_SETUP"
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
function maybeAddSetupWalletButton() {
|
||||
if (!$('body').hasClass("walletsetup-injected") && userIsLoggedIn && walletNeedsSetup) {
|
||||
|
@ -285,7 +287,7 @@
|
|||
$(this).closest('.col-xs-3').prev().attr("class", 'col-xs-6');
|
||||
$(this).closest('.col-xs-3').attr("class", 'col-xs-6');
|
||||
|
||||
var priceElement = $(this).find('.price')
|
||||
var priceElement = $(this).find('.price');
|
||||
priceElement.css({
|
||||
"padding": "3px 5px",
|
||||
"height": "40px",
|
||||
|
@ -355,12 +357,12 @@
|
|||
function injectAddScrollbarToCategories() {
|
||||
$('#categories-dropdown').on('show.bs.dropdown', function () {
|
||||
$('body > div.container').css('display', 'none')
|
||||
$('#categories-dropdown > ul.dropdown-menu').css({ 'overflow': 'auto', 'height': 'calc(100vh - 110px)' })
|
||||
$('#categories-dropdown > ul.dropdown-menu').css({ 'overflow': 'auto', 'height': 'calc(100vh - 110px)' });
|
||||
});
|
||||
|
||||
$('#categories-dropdown').on('hide.bs.dropdown', function () {
|
||||
$('body > div.container').css('display', '')
|
||||
$('#categories-dropdown > ul.dropdown-menu').css({ 'overflow': '', 'height': '' })
|
||||
$('body > div.container').css('display', '');
|
||||
$('#categories-dropdown > ul.dropdown-menu').css({ 'overflow': '', 'height': '' });
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -382,7 +384,6 @@
|
|||
mutations.forEach(function (mutation) {
|
||||
injectBuyButtonOnMainPage();
|
||||
});
|
||||
//observer.disconnect();
|
||||
});
|
||||
var config = { attributes: true, childList: true, characterData: true };
|
||||
observer.observe(target, config);
|
||||
|
@ -451,8 +452,8 @@
|
|||
"itemPage",
|
||||
urlParams.get('edition'),
|
||||
type);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
maybeAddPurchasesButton();
|
||||
}
|
||||
}
|
||||
|
@ -503,127 +504,142 @@
|
|||
$(".top-title .col-sm-4").append(downloadContainer);
|
||||
downloadContainer.append(downloadFBX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Automatic download to High Fidelity.
|
||||
function startAutoDownload() {
|
||||
// Automatic download to High Fidelity.
|
||||
function startAutoDownload() {
|
||||
// One file request at a time.
|
||||
if (isPreparing) {
|
||||
console.log("WARNING: Clara.io FBX: Prepare only one download at a time");
|
||||
return;
|
||||
}
|
||||
|
||||
// One file request at a time.
|
||||
if (isPreparing) {
|
||||
console.log("WARNING: Clara.io FBX: Prepare only one download at a time");
|
||||
return;
|
||||
}
|
||||
// User must be able to write to Asset Server.
|
||||
if (!canWriteAssets) {
|
||||
console.log("ERROR: Clara.io FBX: File download cancelled because no permissions to write to Asset Server");
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: WARN_USER_NO_PERMISSIONS
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// User must be able to write to Asset Server.
|
||||
if (!canWriteAssets) {
|
||||
console.log("ERROR: Clara.io FBX: File download cancelled because no permissions to write to Asset Server");
|
||||
EventBridge.emitWebEvent(WARN_USER_NO_PERMISSIONS);
|
||||
return;
|
||||
}
|
||||
// User must be logged in.
|
||||
var loginButton = $("#topnav a[href='/signup']");
|
||||
if (loginButton.length > 0) {
|
||||
loginButton[0].click();
|
||||
return;
|
||||
}
|
||||
|
||||
// User must be logged in.
|
||||
var loginButton = $("#topnav a[href='/signup']");
|
||||
if (loginButton.length > 0) {
|
||||
loginButton[0].click();
|
||||
return;
|
||||
}
|
||||
// Obtain zip file to download for requested asset.
|
||||
// Reference: https://clara.io/learn/sdk/api/export
|
||||
|
||||
// Obtain zip file to download for requested asset.
|
||||
// Reference: https://clara.io/learn/sdk/api/export
|
||||
//var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?zip=true¢erScene=true&alignSceneGround=true&fbxUnit=Meter&fbxVersion=7&fbxEmbedTextures=true&imageFormat=WebGL";
|
||||
// 13 Jan 2017: Specify FBX version 5 and remove some options in order to make Clara.io site more likely to
|
||||
// be successful in generating zip files.
|
||||
var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?fbxUnit=Meter&fbxVersion=5&fbxEmbedTextures=true&imageFormat=WebGL";
|
||||
|
||||
//var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?zip=true¢erScene=true&alignSceneGround=true&fbxUnit=Meter&fbxVersion=7&fbxEmbedTextures=true&imageFormat=WebGL";
|
||||
// 13 Jan 2017: Specify FBX version 5 and remove some options in order to make Clara.io site more likely to
|
||||
// be successful in generating zip files.
|
||||
var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?fbxUnit=Meter&fbxVersion=5&fbxEmbedTextures=true&imageFormat=WebGL";
|
||||
var uuid = location.href.match(/\/view\/([a-z0-9\-]*)/)[1];
|
||||
var url = XMLHTTPREQUEST_URL.replace("{uuid}", uuid);
|
||||
|
||||
var uuid = location.href.match(/\/view\/([a-z0-9\-]*)/)[1];
|
||||
var url = XMLHTTPREQUEST_URL.replace("{uuid}", uuid);
|
||||
xmlHttpRequest = new XMLHttpRequest();
|
||||
var responseTextIndex = 0;
|
||||
var zipFileURL = "";
|
||||
|
||||
xmlHttpRequest = new XMLHttpRequest();
|
||||
var responseTextIndex = 0;
|
||||
var zipFileURL = "";
|
||||
xmlHttpRequest.onreadystatechange = function () {
|
||||
// Messages are appended to responseText; process the new ones.
|
||||
var message = this.responseText.slice(responseTextIndex);
|
||||
var statusMessage = "";
|
||||
|
||||
xmlHttpRequest.onreadystatechange = function () {
|
||||
// Messages are appended to responseText; process the new ones.
|
||||
var message = this.responseText.slice(responseTextIndex);
|
||||
var statusMessage = "";
|
||||
if (isPreparing) { // Ignore messages in flight after finished/cancelled.
|
||||
var lines = message.split(/[\n\r]+/);
|
||||
|
||||
if (isPreparing) { // Ignore messages in flight after finished/cancelled.
|
||||
var lines = message.split(/[\n\r]+/);
|
||||
for (var i = 0, length = lines.length; i < length; i++) {
|
||||
if (lines[i].slice(0, 5) === "data:") {
|
||||
// Parse line.
|
||||
var data;
|
||||
try {
|
||||
data = JSON.parse(lines[i].slice(5));
|
||||
}
|
||||
catch (e) {
|
||||
data = {};
|
||||
}
|
||||
|
||||
for (var i = 0, length = lines.length; i < length; i++) {
|
||||
if (lines[i].slice(0, 5) === "data:") {
|
||||
// Parse line.
|
||||
var data;
|
||||
try {
|
||||
data = JSON.parse(lines[i].slice(5));
|
||||
}
|
||||
catch (e) {
|
||||
data = {};
|
||||
}
|
||||
// Extract status message.
|
||||
if (data.hasOwnProperty("message") && data.message !== null) {
|
||||
statusMessage = data.message;
|
||||
console.log("Clara.io FBX: " + statusMessage);
|
||||
}
|
||||
|
||||
// Extract status message.
|
||||
if (data.hasOwnProperty("message") && data.message !== null) {
|
||||
statusMessage = data.message;
|
||||
console.log("Clara.io FBX: " + statusMessage);
|
||||
}
|
||||
|
||||
// Extract zip file URL.
|
||||
if (data.hasOwnProperty("files") && data.files.length > 0) {
|
||||
zipFileURL = data.files[0].url;
|
||||
if (zipFileURL.slice(-4) !== ".zip") {
|
||||
console.log(JSON.stringify(data)); // Data for debugging.
|
||||
}
|
||||
}
|
||||
// Extract zip file URL.
|
||||
if (data.hasOwnProperty("files") && data.files.length > 0) {
|
||||
zipFileURL = data.files[0].url;
|
||||
if (zipFileURL.slice(-4) !== ".zip") {
|
||||
console.log(JSON.stringify(data)); // Data for debugging.
|
||||
}
|
||||
}
|
||||
|
||||
if (statusMessage !== "") {
|
||||
// Update the UI with the most recent status message.
|
||||
EventBridge.emitWebEvent(CLARA_IO_STATUS + " " + statusMessage);
|
||||
}
|
||||
}
|
||||
|
||||
responseTextIndex = this.responseText.length;
|
||||
};
|
||||
|
||||
// Note: onprogress doesn't have computable total length so can't use it to determine % complete.
|
||||
|
||||
xmlHttpRequest.onload = function () {
|
||||
var statusMessage = "";
|
||||
|
||||
if (!isPreparing) {
|
||||
return;
|
||||
}
|
||||
|
||||
isPreparing = false;
|
||||
|
||||
var HTTP_OK = 200;
|
||||
if (this.status !== HTTP_OK) {
|
||||
statusMessage = "Zip file request terminated with " + this.status + " " + this.statusText;
|
||||
console.log("ERROR: Clara.io FBX: " + statusMessage);
|
||||
EventBridge.emitWebEvent(CLARA_IO_STATUS + " " + statusMessage);
|
||||
} else if (zipFileURL.slice(-4) !== ".zip") {
|
||||
statusMessage = "Error creating zip file for download.";
|
||||
console.log("ERROR: Clara.io FBX: " + statusMessage + ": " + zipFileURL);
|
||||
EventBridge.emitWebEvent(CLARA_IO_STATUS + " " + statusMessage);
|
||||
} else {
|
||||
EventBridge.emitWebEvent(CLARA_IO_DOWNLOAD + " " + zipFileURL);
|
||||
console.log("Clara.io FBX: File download initiated for " + zipFileURL);
|
||||
}
|
||||
|
||||
xmlHttpRequest = null;
|
||||
}
|
||||
|
||||
isPreparing = true;
|
||||
|
||||
console.log("Clara.io FBX: Request zip file for " + uuid);
|
||||
EventBridge.emitWebEvent(CLARA_IO_STATUS + " Initiating download");
|
||||
|
||||
xmlHttpRequest.open("POST", url, true);
|
||||
xmlHttpRequest.setRequestHeader("Accept", "text/event-stream");
|
||||
xmlHttpRequest.send();
|
||||
if (statusMessage !== "") {
|
||||
// Update the UI with the most recent status message.
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: CLARA_IO_STATUS,
|
||||
status: statusMessage
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
responseTextIndex = this.responseText.length;
|
||||
};
|
||||
|
||||
// Note: onprogress doesn't have computable total length so can't use it to determine % complete.
|
||||
|
||||
xmlHttpRequest.onload = function () {
|
||||
var statusMessage = "";
|
||||
|
||||
if (!isPreparing) {
|
||||
return;
|
||||
}
|
||||
|
||||
isPreparing = false;
|
||||
|
||||
var HTTP_OK = 200;
|
||||
if (this.status !== HTTP_OK) {
|
||||
statusMessage = "Zip file request terminated with " + this.status + " " + this.statusText;
|
||||
console.log("ERROR: Clara.io FBX: " + statusMessage);
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: CLARA_IO_STATUS,
|
||||
status: statusMessage
|
||||
}));
|
||||
} else if (zipFileURL.slice(-4) !== ".zip") {
|
||||
statusMessage = "Error creating zip file for download.";
|
||||
console.log("ERROR: Clara.io FBX: " + statusMessage + ": " + zipFileURL);
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: CLARA_IO_STATUS,
|
||||
status: (statusMessage + ": " + zipFileURL)
|
||||
}));
|
||||
} else {
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: CLARA_IO_DOWNLOAD
|
||||
}));
|
||||
console.log("Clara.io FBX: File download initiated for " + zipFileURL);
|
||||
}
|
||||
|
||||
xmlHttpRequest = null;
|
||||
}
|
||||
|
||||
isPreparing = true;
|
||||
|
||||
console.log("Clara.io FBX: Request zip file for " + uuid);
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: CLARA_IO_STATUS,
|
||||
status: "Initiating download"
|
||||
}));
|
||||
|
||||
xmlHttpRequest.open("POST", url, true);
|
||||
xmlHttpRequest.setRequestHeader("Accept", "text/event-stream");
|
||||
xmlHttpRequest.send();
|
||||
}
|
||||
|
||||
function injectClaraCode() {
|
||||
|
@ -663,7 +679,9 @@
|
|||
updateClaraCodeInterval = undefined;
|
||||
});
|
||||
|
||||
EventBridge.emitWebEvent(QUERY_CAN_WRITE_ASSETS);
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: QUERY_CAN_WRITE_ASSETS
|
||||
}));
|
||||
}
|
||||
|
||||
function cancelClaraDownload() {
|
||||
|
@ -673,7 +691,9 @@
|
|||
xmlHttpRequest.abort();
|
||||
xmlHttpRequest = null;
|
||||
console.log("Clara.io FBX: File download cancelled");
|
||||
EventBridge.emitWebEvent(CLARA_IO_CANCELLED_DOWNLOAD);
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: CLARA_IO_CANCELLED_DOWNLOAD
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -708,26 +728,22 @@
|
|||
|
||||
function onLoad() {
|
||||
EventBridge.scriptEventReceived.connect(function (message) {
|
||||
message = JSON.stringify(message);
|
||||
if (message.slice(0, CAN_WRITE_ASSETS.length) === CAN_WRITE_ASSETS) {
|
||||
canWriteAssets = message.slice(-4) === "true";
|
||||
} else if (message.slice(0, CLARA_IO_CANCEL_DOWNLOAD.length) === CLARA_IO_CANCEL_DOWNLOAD) {
|
||||
message = JSON.parse(message);
|
||||
if (message.type === CAN_WRITE_ASSETS) {
|
||||
canWriteAssets = message.canWriteAssets;
|
||||
} else if (message.type === CLARA_IO_CANCEL_DOWNLOAD) {
|
||||
cancelClaraDownload();
|
||||
} else {
|
||||
var parsedJsonMessage = JSON.parse(message);
|
||||
|
||||
if (parsedJsonMessage.type === "marketplaces") {
|
||||
if (parsedJsonMessage.action === "commerceSetting") {
|
||||
commerceMode = !!parsedJsonMessage.data.commerceMode;
|
||||
userIsLoggedIn = !!parsedJsonMessage.data.userIsLoggedIn;
|
||||
walletNeedsSetup = !!parsedJsonMessage.data.walletNeedsSetup;
|
||||
marketplaceBaseURL = parsedJsonMessage.data.metaverseServerURL;
|
||||
if (marketplaceBaseURL.indexOf('metaverse.') !== -1) {
|
||||
marketplaceBaseURL = marketplaceBaseURL.replace('metaverse.', '');
|
||||
}
|
||||
messagesWaiting = parsedJsonMessage.data.messagesWaiting;
|
||||
injectCode();
|
||||
} else if (message.type === "marketplaces") {
|
||||
if (message.action === "commerceSetting") {
|
||||
commerceMode = !!message.data.commerceMode;
|
||||
userIsLoggedIn = !!message.data.userIsLoggedIn;
|
||||
walletNeedsSetup = !!message.data.walletNeedsSetup;
|
||||
marketplaceBaseURL = message.data.metaverseServerURL;
|
||||
if (marketplaceBaseURL.indexOf('metaverse.') !== -1) {
|
||||
marketplaceBaseURL = marketplaceBaseURL.replace('metaverse.', '');
|
||||
}
|
||||
messagesWaiting = message.data.messagesWaiting;
|
||||
injectCode();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -740,6 +756,6 @@
|
|||
}
|
||||
|
||||
// Load / unload.
|
||||
window.addEventListener("load", onLoad); // More robust to Web site issues than using $(document).ready().
|
||||
window.addEventListener("page:change", onLoad); // Triggered after Marketplace HTML is changed
|
||||
window.addEventListener("load", onLoad); // More robust to Web site issues than using $(document).ready().
|
||||
window.addEventListener("page:change", onLoad); // Triggered after Marketplace HTML is changed
|
||||
}());
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -713,7 +713,7 @@ function tabletVisibilityChanged() {
|
|||
if (!ui.tablet.tabletShown && ui.isOpen) {
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var UPDATE_INTERVAL_MS = 100;
|
||||
var updateInterval;
|
||||
|
|
Loading…
Reference in a new issue