mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Listen for messages and display using notifcore.
Avatar joining and leaving.
This commit is contained in:
parent
09f8d07a29
commit
eedabfa305
10 changed files with 224 additions and 0 deletions
0
scripts/system/domainChat/README.md
Normal file
0
scripts/system/domainChat/README.md
Normal file
53
scripts/system/domainChat/avatarList.js
Normal file
53
scripts/system/domainChat/avatarList.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// avatarList.js
|
||||
//
|
||||
// Created by Armored Dragon, 2025.
|
||||
// Copyright 2024 Overte e.V.
|
||||
//
|
||||
// Handles user joining and leaving events and emits messages to the message display
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
AvatarManager.avatarAddedEvent.connect((sessionId) => { _avatarAction("connected", sessionId) });
|
||||
AvatarManager.avatarRemovedEvent.connect((sessionId) => { _avatarAction("left", sessionId) });
|
||||
|
||||
function _avatarAction(type, sessionId) {
|
||||
Script.setTimeout(() => {
|
||||
if (type == "connected") {
|
||||
app.info.palData = AvatarManager.getPalData().data;
|
||||
}
|
||||
|
||||
// Get the display name of the user
|
||||
let displayName = "";
|
||||
displayName = AvatarManager.getPalData([sessionId])?.data[0]?.sessionDisplayName || null;
|
||||
if (displayName == null) {
|
||||
for (let i = 0; i < app.info.palData.length; i++) {
|
||||
if (app.info.palData[i].sessionUUID == sessionId) {
|
||||
displayName = app.info.palData[i].sessionDisplayName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Format the packet
|
||||
let message = {};
|
||||
// FIXME: Date / Time formatting
|
||||
// const timeArray = _formatTimestamp(_getTimestamp());
|
||||
// message.timeString = timeArray[0];
|
||||
// message.dateString = timeArray[1];
|
||||
message.timeString = Date.now();
|
||||
message.dateString = Date.now();
|
||||
message.message = `${displayName} ${type}`;
|
||||
|
||||
// Show new message on screen
|
||||
Messages.sendLocalMessage(
|
||||
"Floof-Notif",
|
||||
JSON.stringify({
|
||||
sender: displayName,
|
||||
text: type,
|
||||
})
|
||||
);
|
||||
|
||||
// _emitEvent({ type: "notification", ...message });
|
||||
}, 1500);
|
||||
}
|
23
scripts/system/domainChat/compatibility.js
Normal file
23
scripts/system/domainChat/compatibility.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// compatibility.js
|
||||
//
|
||||
// Created by Armored Dragon, May 17th, 2024.
|
||||
// Copyright 2024 Overte e.V.
|
||||
//
|
||||
// This provides functions for backwards compatibility for messages.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
const compatibility = {
|
||||
fromArmoredChat: (messagePacket) => {
|
||||
let newMessagePacket = {
|
||||
author: messagePacket.displayName || messagePacket.author || null,
|
||||
channel: messagePacket.channel.toLowerCase(),
|
||||
message: messagePacket.message,
|
||||
position: messagePacket.position
|
||||
}
|
||||
|
||||
return newMessagePacket;
|
||||
}
|
||||
}
|
44
scripts/system/domainChat/domainChat.js
Normal file
44
scripts/system/domainChat/domainChat.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// domainChat.js
|
||||
//
|
||||
// Created by Armored Dragon, May 17th, 2024.
|
||||
// Copyright 2024 Overte e.V.
|
||||
//
|
||||
// Uses the message mixer to facilitate text based communication between users
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
Script.include([
|
||||
"avatarList.js", // Avatar leaving and joining
|
||||
"formatting.js", // Message formatting and data parsing
|
||||
"messageMixer.js", // Message mixer handing
|
||||
"keypressEvents.js", // Keybinds
|
||||
"compatibility.js", // Backwards compatibility
|
||||
"ui.js" // User interface
|
||||
]);
|
||||
|
||||
let app = {
|
||||
isVisible: false,
|
||||
info: {
|
||||
tabletButton: null,
|
||||
palData: null
|
||||
},
|
||||
settings: {},
|
||||
windows: {},
|
||||
history: [],
|
||||
}
|
||||
let tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
||||
Messages.messageReceived.connect(messageMixer.messageReceived);
|
||||
Messages.subscribe("Chat"); // Floofchat
|
||||
Messages.subscribe("chat");
|
||||
|
||||
// TODO: Uninstall - Clear settings & message history
|
||||
// TODO: Launch - Load settings & message history
|
||||
// TODO: Send messages - Add to message history & update UI
|
||||
|
||||
function loadSettings() { }
|
||||
function saveSettings() { }
|
||||
function uninstall() { }
|
0
scripts/system/domainChat/formatting.js
Normal file
0
scripts/system/domainChat/formatting.js
Normal file
11
scripts/system/domainChat/keypressEvents.js
Normal file
11
scripts/system/domainChat/keypressEvents.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function keyPressEvent(event) {
|
||||
switch (JSON.stringify(event.key)) {
|
||||
case "16777220": // Enter key
|
||||
if (HMD.active) return; // Don't allow in VR
|
||||
|
||||
quickMessage.sendToQml({
|
||||
type: "change_visibility",
|
||||
value: true,
|
||||
});
|
||||
}
|
||||
}
|
78
scripts/system/domainChat/messageMixer.js
Normal file
78
scripts/system/domainChat/messageMixer.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
function messageReceived(channel, message) {
|
||||
// Parse the message packet
|
||||
let parsedMessage = _parseJSON(message);
|
||||
if (parsedMessage === null) return;
|
||||
|
||||
// Check if the message is a chat message
|
||||
if (!_isAChatMessage()) return;
|
||||
|
||||
// Compatibility
|
||||
console.log("\n------------ NEW MESSAGE -----------------")
|
||||
parsedMessage = compatibility.fromArmoredChat(parsedMessage);
|
||||
console.log(JSON.stringify(parsedMessage, null, 4));
|
||||
|
||||
// Display the chat message
|
||||
ui.displayNotificationCore(parsedMessage);
|
||||
|
||||
// Add to message history
|
||||
_addMessageToHistory(parsedMessage);
|
||||
|
||||
function _isAChatMessage() {
|
||||
// Checks to see if this is a message for us, and if we can handle it
|
||||
let normalizedChannel = channel.toLowerCase();
|
||||
if (normalizedChannel != 'chat') return false; // Make sure the message mixer was the right channel
|
||||
if (parsedMessage.type && parsedMessage.type === "TransmitChatMessage") return false; // Notification Core
|
||||
|
||||
// if (!_validateMessage(parsedMessage)) return false; // FIXME: This is causing issues due to compatibility.fromArmoredChat(parsedMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function sendMessage(message = "", channel = "") { }
|
||||
|
||||
const messageMixer = {
|
||||
sendMessage: sendMessage,
|
||||
messageReceived: messageReceived
|
||||
}
|
||||
|
||||
function _parseJSON(message) {
|
||||
try {
|
||||
return JSON.parse(message);
|
||||
} catch (e) {
|
||||
console.log("Error parsing JSON from the message mixer");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function _validateMessage(message = {}) {
|
||||
|
||||
// This is the structure of a message packet:
|
||||
//
|
||||
// const messageStructure = {
|
||||
// author: "", // The author of this message
|
||||
// channel: "", // The channel the message was sent in
|
||||
// message: "", // The content of the message
|
||||
// position: {} , // The position of the author of the message when it was sent
|
||||
// }
|
||||
|
||||
const validChannels = ["domain", "local"];
|
||||
console.log(JSON.stringify(message, null, 4));
|
||||
|
||||
if (!message.author) return false; // Needs message author
|
||||
if (!message.channel) return false; // Needs message channel (domain wide / local)
|
||||
if (!message.message) return false; // Needs message content
|
||||
if (!message.position) return false; // Needs message position
|
||||
|
||||
if (validChannels.indexOf(message.channel.toLowerCase()) === -1) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
function _addMessageToHistory(message = {}) {
|
||||
// Add the message to the history array
|
||||
app.history.push({ ...message, position: null });
|
||||
|
||||
while (app.history.length > app.settings.maximumNumberOfSavedMessages) {
|
||||
app.history.shift();
|
||||
}
|
||||
|
||||
Settings.setValue("DomainChat-Messages", messageHistory);
|
||||
}
|
0
scripts/system/domainChat/qml/chatWindow.qml
Normal file
0
scripts/system/domainChat/qml/chatWindow.qml
Normal file
0
scripts/system/domainChat/qml/quickChat.qml
Normal file
0
scripts/system/domainChat/qml/quickChat.qml
Normal file
15
scripts/system/domainChat/ui.js
Normal file
15
scripts/system/domainChat/ui.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const ui = {
|
||||
displayNotificationCore: (messagePacket) => {
|
||||
Messages.sendLocalMessage(
|
||||
"Floof-Notif",
|
||||
JSON.stringify({
|
||||
sender: messagePacket.author,
|
||||
text: messagePacket.message,
|
||||
})
|
||||
);
|
||||
},
|
||||
displayChatMessage: (messagePacket) => {
|
||||
// TODO
|
||||
console.log("displaychatMessage is not implemented");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue