Updates to join (server/client)

- Check if the available nodes are connected to a vc in the given guild
This commit is contained in:
Logan Cusano
2024-02-11 04:32:58 -05:00
parent b78fa8307d
commit ed33654b8c
4 changed files with 103 additions and 23 deletions

View File

@@ -114,7 +114,7 @@ export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
} else {
// The systems are not the same
// TODO - Implement logic to handle if system names match, but they are for different frequencies or have additional freqs
// Check if the current node is listed in the nodes, if not add it
if (!existingSystem.nodes.includes(nuid)) {
existingSystem.nodes.push(nuid);
@@ -141,23 +141,78 @@ export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
* @param {string} nuid The NUID to find within the open sockets
* @returns {string|null} Will return the open socket ID or NULL
*/
const getSocketIdByNuid = async (nuid) => {
for (const openSocket in openSockets) {
const getSocketIdByNuid = async (nodeIo, nuid) => {
for (const openSocket in await nodeIo.allSockets()) {
if (openSockets[openSocket] == nuid)
return openSocket;
}
return null;
}
/**
* Get all nodes that are connected to a voice channel
* @param {any} nodeIo
* @param {any} guildId The guild ID string for the guild we are looking in
* @returns {any}
*/
export const getAllSocketsConnectedToVC = async (nodeIo, guildId) => {
// Get all open socket nodes
// TODO - require a server guild to filter the results, ie this would be able to check what server the VCs the nodes are connected are in
const openSockets = [...await nodeIo.allSockets()]; // TODO - Filter the returned nodes to only nodes that have the radio capability
// Check each open socket to see if the node has the requested system
const socketsConnectedToVC = []
await Promise.all(openSockets.map(async openSocket => {
openSocket = await nodeIo.sockets.sockets.get(openSocket);
await new Promise((res) => {
openSocket.emit('node-check-connected-status', guildId, (status) => {
if (status) {
console.log("Socket is connected to VC:", openSocket.node.name);
socketsConnectedToVC.push(openSocket);
} else {
console.log("Socket is NOT connected to VC:", openSocket.node.name);
}
res();
})
});
}));
return socketsConnectedToVC;
}
/**
* Wrapper to check if the given NUID is connected to a VC
* @param {any} nodeIo The nodeIo object that contains the IO server
* @param {any} nuid The NUID string that we would like to find in the open socket connections
* @returns {any}
*/
export const checkIfNodeIsConnectedToVC = async (nodeIo, guildId, nuid) => {
const socketsConnectedToVC = await getAllSocketsConnectedToVC(nodeIo, guildId);
for (const socket of socketsConnectedToVC) {
if (socket.node.nuid === nuid) {
return true;
}
}
return false;
}
/**
* Request a given socket node to join a given voice channel
* @param {any} socket The socket object of the node the request should be sent to
* @param {any} systemName The system preset name that we would like to listen to
* @param {any} discordChanelId The Discord channel ID to join the listening bot to
* @returns {any}
*/
export const requestNodeJoinSystem = async (socket, systemName, discordChanelId) => {
// Check for System updates
// Check for open client IDs
const joinData = {
'clientID': "MTE5NjAwNTM2ODYzNjExMjk3Nw.GuCMXg.24iNNofNNumq46FIj68zMe9RmQgugAgfrvelEA",
'channelID': discordChanelId,
'preset': systemName
}
sendNodeCommand(socket, "node-join", joinData);
// Send the command to the node
await sendNodeCommand(socket, "node-join", joinData);
}
export const requestBotLeave = async () => {
}