Functional joining and leaving
- Needs to be tested on multiple servers - Needs to be tested with multiple nodes #1 #9
This commit is contained in:
@@ -66,7 +66,6 @@ export const nodeUpdateWrapper = async (nodeData) => {
|
||||
* Wrapper to update the systems from the nearbySystems object passed from clients
|
||||
* @param {string} nuid The NUID of the node that sent the update
|
||||
* @param {object} nearbySystems The nearby systems object passed from the node to be updated
|
||||
* @returns {any}
|
||||
*/
|
||||
export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
|
||||
console.log("System updates sent by node: ", nuid, nearbySystems);
|
||||
@@ -142,9 +141,12 @@ 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 (nodeIo, nuid) => {
|
||||
for (const openSocket in await nodeIo.allSockets()) {
|
||||
if (openSockets[openSocket] == nuid)
|
||||
export const getSocketIdByNuid = async (nodeIo, nuid) => {
|
||||
const openSockets = await nodeIo.allSockets();
|
||||
for (const openSocketId of openSockets) {
|
||||
console.log(openSockets)
|
||||
const openSocket = await nodeIo.sockets.sockets.get(openSocketId);
|
||||
if (openSocket.node.nuid == nuid)
|
||||
return openSocket;
|
||||
}
|
||||
return null;
|
||||
@@ -152,9 +154,9 @@ const getSocketIdByNuid = async (nodeIo, nuid) => {
|
||||
|
||||
/**
|
||||
* 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}
|
||||
* @param {any} nodeIo The nodeIo object that contains the IO server
|
||||
* @param {string} guildId The guild ID string for the guild we are looking in
|
||||
* @returns {Array} The sockets connected to VC in a given server
|
||||
*/
|
||||
export const getAllSocketsConnectedToVC = async (nodeIo, guildId) => {
|
||||
// Get all open socket nodes
|
||||
@@ -167,7 +169,7 @@ export const getAllSocketsConnectedToVC = async (nodeIo, guildId) => {
|
||||
await new Promise((res) => {
|
||||
openSocket.emit('node-check-connected-status', guildId, (status) => {
|
||||
if (status) {
|
||||
console.log("Socket is connected to VC:", openSocket.node.name);
|
||||
console.log("Socket is connected to VC:", openSocket.node.name, status);
|
||||
socketsConnectedToVC.push(openSocket);
|
||||
} else {
|
||||
console.log("Socket is NOT connected to VC:", openSocket.node.name);
|
||||
@@ -183,8 +185,8 @@ export const getAllSocketsConnectedToVC = async (nodeIo, guildId) => {
|
||||
/**
|
||||
* 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}
|
||||
* @param {string} nuid The NUID string that we would like to find in the open socket connections
|
||||
* @returns {boolean} If the node is connected to VC in the given server
|
||||
*/
|
||||
export const checkIfNodeIsConnectedToVC = async (nodeIo, guildId, nuid) => {
|
||||
const socketsConnectedToVC = await getAllSocketsConnectedToVC(nodeIo, guildId);
|
||||
@@ -196,12 +198,25 @@ export const checkIfNodeIsConnectedToVC = async (nodeIo, guildId, nuid) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the discord username from a given socket
|
||||
* @param {any} socket The socket object of the node to check the username of
|
||||
* * @param {string} guildId The guild ID to check the username in
|
||||
* @returns {string} The username of the bot in the requested server
|
||||
*/
|
||||
export const getNodeDiscordUsername = async (socket, guildId) => {
|
||||
return await new Promise((res) => {
|
||||
socket.emit('node-get-discord-username', guildId, (username) => {
|
||||
res(username);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
* @param {string} discordChanelId The Discord channel ID to join the listening bot to
|
||||
*/
|
||||
export const requestNodeJoinSystem = async (socket, systemName, discordChanelId) => {
|
||||
// Check for open client IDs
|
||||
@@ -214,6 +229,12 @@ export const requestNodeJoinSystem = async (socket, systemName, discordChanelId)
|
||||
await sendNodeCommand(socket, "node-join", joinData);
|
||||
}
|
||||
|
||||
export const requestBotLeave = async () => {
|
||||
|
||||
/**
|
||||
* Request a given socket node to leave VC in a given server
|
||||
* @param {any} socket The socket object of the node the request should be sent to
|
||||
* @param {string} guildId The guild ID to disconnect the socket node from
|
||||
*/
|
||||
export const requestBotLeaveServer = async (socket, guildId) => {
|
||||
// Send the command to the node
|
||||
await sendNodeCommand(socket, "node-leave", guildId);
|
||||
}
|
||||
Reference in New Issue
Block a user