mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 09:37:29 +02:00
Address event bridge being shared with other scripts
This commit is contained in:
parent
aa8a1e1dda
commit
d0fc352d3b
2 changed files with 46 additions and 15 deletions
|
@ -43,7 +43,13 @@ function addImage(data) {
|
||||||
function handleShareButtons(shareMsg) {
|
function handleShareButtons(shareMsg) {
|
||||||
var openFeed = document.getElementById('openFeed');
|
var openFeed = document.getElementById('openFeed');
|
||||||
openFeed.checked = shareMsg.openFeedAfterShare;
|
openFeed.checked = shareMsg.openFeedAfterShare;
|
||||||
openFeed.onchange = function () { EventBridge.emitWebEvent(openFeed.checked ? 'setOpenFeedTrue' : 'setOpenFeedFalse'); };
|
openFeed.onchange = function () {
|
||||||
|
EventBridge.emitWebEvent(JSON.stringify({
|
||||||
|
type: "snapshot",
|
||||||
|
action: (openFeed.checked ? "setOpenFeedTrue" : "setOpenFeedFalse")
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
if (!shareMsg.canShare) {
|
if (!shareMsg.canShare) {
|
||||||
// this means you may or may not be logged in, but can't share
|
// this means you may or may not be logged in, but can't share
|
||||||
// because you are not in a public place.
|
// because you are not in a public place.
|
||||||
|
@ -57,25 +63,42 @@ window.onload = function () {
|
||||||
openEventBridge(function () {
|
openEventBridge(function () {
|
||||||
// Set up a handler for receiving the data, and tell the .js we are ready to receive it.
|
// Set up a handler for receiving the data, and tell the .js we are ready to receive it.
|
||||||
EventBridge.scriptEventReceived.connect(function (message) {
|
EventBridge.scriptEventReceived.connect(function (message) {
|
||||||
|
message = JSON.parse(message);
|
||||||
|
if (message.type !== "snapshot") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// last element of list contains a bool for whether or not we can share stuff
|
// last element of list contains a bool for whether or not we can share stuff
|
||||||
var shareMsg = message.pop();
|
var shareMsg = message.action.pop();
|
||||||
handleShareButtons(shareMsg);
|
handleShareButtons(shareMsg);
|
||||||
|
|
||||||
// rest are image paths which we add
|
// rest are image paths which we add
|
||||||
useCheckboxes = message.length > 1;
|
useCheckboxes = message.action.length > 1;
|
||||||
message.forEach(addImage);
|
message.action.forEach(addImage);
|
||||||
});
|
});
|
||||||
EventBridge.emitWebEvent('ready');
|
EventBridge.emitWebEvent(JSON.stringify({
|
||||||
|
type: "snapshot",
|
||||||
|
action: "ready"
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
// beware of bug: Cannot send objects at top level. (Nested in arrays is fine.)
|
// beware of bug: Cannot send objects at top level. (Nested in arrays is fine.)
|
||||||
function shareSelected() {
|
function shareSelected() {
|
||||||
EventBridge.emitWebEvent(paths);
|
EventBridge.emitWebEvent(JSON.stringify({
|
||||||
};
|
type: "snapshot",
|
||||||
|
action: paths
|
||||||
|
}));
|
||||||
|
}
|
||||||
function doNotShare() {
|
function doNotShare() {
|
||||||
EventBridge.emitWebEvent([]);
|
EventBridge.emitWebEvent(JSON.stringify({
|
||||||
};
|
type: "snapshot",
|
||||||
|
action: []
|
||||||
|
}));
|
||||||
|
}
|
||||||
function snapshotSettings() {
|
function snapshotSettings() {
|
||||||
EventBridge.emitWebEvent("openSettings");
|
EventBridge.emitWebEvent(JSON.stringify({
|
||||||
};
|
type: "snapshot",
|
||||||
|
action: "openSettings"
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
|
@ -47,11 +47,19 @@ function confirmShare(data) {
|
||||||
// 2. Although we currently use a single image, we would like to take snapshot, a selfie, a 360 etc. all at the
|
// 2. Although we currently use a single image, we would like to take snapshot, a selfie, a 360 etc. all at the
|
||||||
// same time, show the user all of them, and have the user deselect any that they do not want to share.
|
// same time, show the user all of them, and have the user deselect any that they do not want to share.
|
||||||
// So we'll ultimately be receiving a set of objects, perhaps with different post processing for each.
|
// So we'll ultimately be receiving a set of objects, perhaps with different post processing for each.
|
||||||
|
message = JSON.parse(message);
|
||||||
|
if (message.type !== "snapshot") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var isLoggedIn;
|
var isLoggedIn;
|
||||||
var needsLogin = false;
|
var needsLogin = false;
|
||||||
switch (message) {
|
switch (message.action) {
|
||||||
case 'ready':
|
case 'ready': // Send it.
|
||||||
tablet.emitScriptEvent(data); // Send it.
|
tablet.emitScriptEvent(JSON.stringify({
|
||||||
|
type: "snapshot",
|
||||||
|
action: data
|
||||||
|
}));
|
||||||
outstanding = 0;
|
outstanding = 0;
|
||||||
break;
|
break;
|
||||||
case 'openSettings':
|
case 'openSettings':
|
||||||
|
@ -67,7 +75,7 @@ function confirmShare(data) {
|
||||||
tablet.webEventReceived.disconnect(onMessage);
|
tablet.webEventReceived.disconnect(onMessage);
|
||||||
HMD.closeTablet();
|
HMD.closeTablet();
|
||||||
isLoggedIn = Account.isLoggedIn();
|
isLoggedIn = Account.isLoggedIn();
|
||||||
message.forEach(function (submessage) {
|
message.action.forEach(function (submessage) {
|
||||||
if (submessage.share && !isLoggedIn) {
|
if (submessage.share && !isLoggedIn) {
|
||||||
needsLogin = true;
|
needsLogin = true;
|
||||||
submessage.share = false;
|
submessage.share = false;
|
||||||
|
|
Loading…
Reference in a new issue