Add sending and receiving items.

This commit is contained in:
Kasen IO 2020-04-04 06:42:19 -04:00
parent f1ff399225
commit 7e414d47c7
4 changed files with 87 additions and 22 deletions

View file

@ -17,6 +17,7 @@
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
<!-- <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet"> -->
<link href="./styles/vuetify.css" rel="stylesheet">
<link href="./styles/styles.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
@ -446,7 +447,7 @@
color="blue"
class="px-3"
:disabled="!shareDialog.valid"
@click="shareDialog.show = false; shareItem();"
@click="shareDialog.show = false; shareItem(shareDialog.data.url);"
>
Send
</v-btn>
@ -477,8 +478,9 @@ EventBridge.scriptEventReceived.connect(function(receivedCommand) {
vue_this.receiveInventory(receivedCommand.data);
}
if (receivedCommand.command == 'script-to-web-item-offer') {
alert("RECEIVING ITEM OFFER:" + JSON.stringify(receivedCommand.data));
if (receivedCommand.command == 'script-to-web-receiving-item') {
// alert("RECEIVING ITEM OFFER:" + JSON.stringify(receivedCommand.data));
vue_this.receivingItem(receivedCommand.data);
}
if (receivedCommand.command == 'script-to-web-nearby-users') {
@ -647,6 +649,28 @@ new Vue({
return detectedItemType;
},
checkItemType: function(itemType) {
var detectedItemType = null;
switch (itemType) {
case "model":
detectedItemType = "model";
break;
case "avatar":
detectedItemType = "avatar";
break;
case "script":
detectedItemType = "script";
break;
}
if (detectedItemType == null) {
// This is not a known item type...
detectedItemType = "unknown";
}
return detectedItemType;
}
addItem: function(name, url) {
var extensionRegex = /\.[0-9a-z]+$/i; // to detect the file type based on extension in the URL.
var detectedFileType = url.match(extensionRegex);
@ -688,17 +712,30 @@ new Vue({
},
receivingItem: function(data) {
if (this.receiveDialog.show != true) { // Do not accept offers if the user is already receiving an offer.
this.receiveDialog.data.user = data.user;
this.receiveDialog.data.type = data.type;
this.receiveDialog.data.name = data.name;
this.receiveDialog.data.url = data.url;
this.receiveDialog.data.user = data.data.user;
this.receiveDialog.data.type = data.data.type;
this.receiveDialog.data.name = data.data.name;
this.receiveDialog.data.url = data.data.url;
this.receiveDialog.show = true;
}
},
shareItem: function() {
shareItem: function(url) {
var typeToShare;
var nameToShare;
for (i = 0; i < this.items.length; i++) {
if (this.items[i].url == url) {
typeToShare = this.items[i].type;
nameToShare = this.items[i].name;
}
}
// alert("type" + typeToShare + "name" + nameToShare);
this.sendAppMessage("share-item", {
"type": typeToShare,
"name": nameToShare,
"url": this.shareDialog.data.url,
"recipient": this.shareDialog.data.recipient,
});
@ -706,11 +743,10 @@ new Vue({
acceptItem: function() {
var itemToPush =
{
"type": this.checkFileType(this.receiveDialog.data.type),
"type": this.checkItemType(this.receiveDialog.data.type),
"name": this.receiveDialog.data.name,
"url": this.receiveDialog.data.url,
};
this.items.push(itemToPush);
},
useItem: function(type, url) {

View file

@ -63,6 +63,11 @@ var inventoryMessagesChannel = "com.vircadia.inventory";
function onMessageReceived(channel, message, sender, localOnly) {
if (channel == inventoryMessagesChannel) {
var messageJSON = JSON.parse(message);
// Window.alert("Passed 0 " + messageJSON.recipient + " vs " + MyAvatar.sessionUUID);
if (messageJSON.command == "share-item" && messageJSON.recipient == MyAvatar.sessionUUID) { // We are receiving an item.
// Window.alert("Passed 1 " + messageJSON.recipient + " vs " + MyAvatar.sessionUUID);
receivingItem(sender, messageJSON.type, messageJSON.name, messageJSON.url);
}
}
print("Message received:");
print("- channel: " + channel);
@ -71,6 +76,10 @@ function onMessageReceived(channel, message, sender, localOnly) {
print("- localOnly: " + localOnly);
}
function sendMessage(dataToSend) {
Messages.sendMessage(inventoryMessagesChannel, JSON.stringify(dataToSend));
}
// END APP EVENT AND MESSAGING ROUTING
// SEND AND RECEIVE INVENTORY STATE
@ -94,28 +103,33 @@ function loadInventory() {
inventoryData = Settings.getValue(inventoryDataSettingString);
}
function receivingItem(data) {
}
function shareItem(data) {
function receivingItem(sender, type, name, url) {
var packageRequest = {
"sender": sender,
"data": {
"type": type,
"name": name,
"url": url
}
}
sendToWeb("script-to-web-receiving-item", packageRequest);
}
function sendNearbyUsers() {
var nearbyUsers = AvatarList.getAvatarsInRange(Vec3.ZERO, 25); // Find all users within 25m.
var nearbyUsers = AvatarList.getAvatarsInRange(MyAvatar.position, 25); // Find all users within 25m.
var nearbyUsersToSend = [];
nearbyUsers.forEach(function(user, i) {
var objectToWrite;
var aviName = AvatarList.getAvatar(user).displayName;
if (aviName != MyAvatar.displayName) {
// Window.alert("aviName" + aviName + "user" + user + "MyAvatar.sessionUUID" + MyAvatar.sessionUUID);
if (user != MyAvatar.sessionUUID) { // Don't add ourselves to the list!
objectToWrite = { "name": aviName, "uuid": user };
nearbyUsersToSend.push = objectToWrite;
nearbyUsersToSend.push(objectToWrite);
}
});
sendToWeb("script-to-web-nearby-users", nearbyUsersToSend);
}
@ -141,6 +155,16 @@ function useItem(item) {
if (item.type == "avatar") {
MyAvatar.useFullAvatarURL(item.url);
}
if (item.type == "unknown") {
// We don't know how to handle this yet.
Window.alert("Unknown item type, unable to use.");
}
}
function shareItem(data) {
data.command = "share-item";
sendMessage(data);
}
function initializeInventoryApp() {
@ -159,6 +183,9 @@ function startup() {
loadInventory();
Messages.messageReceived.connect(onMessageReceived);
Messages.subscribe(inventoryMessagesChannel);
ui = new AppUi({
buttonName: "TOPSECRET",
home: Script.resolvePath("inventory.html"),
@ -170,8 +197,8 @@ function startup() {
startup();
Script.scriptEnding.connect(function () {
// Messages.messageReceived.disconnect(onMessageReceived);
// Messages.unsubscribe(inventoryMessagesChannel);
Messages.messageReceived.disconnect(onMessageReceived);
Messages.unsubscribe(inventoryMessagesChannel);
});
}()); // END LOCAL_SCOPE

View file

@ -0,0 +1 @@
/* .inventoryApp::-webkit-scrollbar { width: 0 !important } */

File diff suppressed because one or more lines are too long