diff --git a/src/handlers/teamspeak/connectionHandler.ts b/src/handlers/teamspeak/connectionHandler.ts index 5ee218b..082f1c3 100644 --- a/src/handlers/teamspeak/connectionHandler.ts +++ b/src/handlers/teamspeak/connectionHandler.ts @@ -89,7 +89,7 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler { this.ws.onmessage = (event) => { const data = JSON.parse(event.data); - Logger.wsRecieved(data) + Logger.wsReceived(data) switch (data.type) { case "auth": @@ -107,7 +107,6 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler { break; case "serverPropertiesUpdated": this.messageHandler.handleServerPropertiesUpdatedMessage(data); - //this.ws.close(); break; case "connectStatusChanged": this.messageHandler.handleConnectStatusChangedMessage(data); @@ -119,7 +118,7 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler { this.messageHandler.handleChannelsMessage(data); break; default: - console.log(`No handler for event type: ${data.type}`); + Logger.log(`No handler for event type: ${data.type}`); break; } }; diff --git a/src/handlers/teamspeak/dataHandler.ts b/src/handlers/teamspeak/dataHandler.ts index b4cc622..1df8df7 100644 --- a/src/handlers/teamspeak/dataHandler.ts +++ b/src/handlers/teamspeak/dataHandler.ts @@ -1,3 +1,4 @@ +import Logger from "@/utils/logger"; import { IConnection, IChannel, IClient, ITS5DataHandler } from "@interfaces/teamspeak"; @@ -58,88 +59,88 @@ export class TS5DataHandler implements ITS5DataHandler { // Add data to local lists and update states addConnection(connection: IConnection) { - console.log("Adding connection...", connection) + Logger.log("Adding connection...", connection) const existingConnection: IConnection | undefined = this.localConnections.find((localConnection: IConnection) => localConnection.id === connection.id); if (existingConnection == undefined) { this.localConnections.push(connection); this.updateConnectionsState(); - console.log("Connection added") + Logger.log("Connection added") } else { - console.log("Connection already exists") + Logger.log("Connection already exists") } } addChannel(channel: IChannel) { - console.log("Adding channel...", channel) + Logger.log("Adding channel...", channel) const existingChannel: IChannel | undefined = this.localChannels.find((localChannel: IChannel) => localChannel.id === channel.id && localChannel.connection.id === channel.connection.id); if (existingChannel == undefined) { this.localChannels.push(channel); this.updateChannelsState(); - console.log("Channel added") + Logger.log("Channel added") } else { - console.log("Channel already exists") + Logger.log("Channel already exists") } } addClient(client: IClient) { - console.log("Adding client...", client) + Logger.log("Adding client...", client) const existingClient: IClient | undefined = this.localClients.find((localClient: IClient) => localClient.id === client.id && localClient.channel?.connection.id === client.channel?.connection.id); if (existingClient == undefined) { this.localClients.push(client); this.updateClientsState(); - console.log("Client added") + Logger.log("Client added") } else { - console.log("Client already exists") + Logger.log("Client already exists") } } // Update data in local lists and update states updateConnection(connection: IConnection) { - console.log("Updating connection...", connection) + Logger.log("Updating connection...", connection) const existingConnection: IConnection | undefined = this.localConnections.find((localConnection: IConnection) => localConnection.id === connection.id); if (existingConnection !== undefined) { this.localConnections[this.localConnections.indexOf(existingConnection)] = connection; this.updateConnectionsState(); - console.log("Connection updated") + Logger.log("Connection updated") } else { - console.log("Connection does not exist") + Logger.log("Connection does not exist") } } updateChannel(channel: IChannel) { - console.log("Updating channel...", channel) + Logger.log("Updating channel...", channel) const existingChannel: IChannel | undefined = this.localChannels.find((localChannel: IChannel) => localChannel.id === channel.id && localChannel.connection.id === channel.connection.id); if (existingChannel !== undefined) { this.localChannels[this.localChannels.indexOf(existingChannel)] = channel; this.updateChannelsState(); - console.log("Channel updated") + Logger.log("Channel updated") } else { - console.log("Channel does not exist") + Logger.log("Channel does not exist") } } updateClient(client: IClient) { - console.log("Updating client...", client) + Logger.log("Updating client...", client) const existingClient: IClient | undefined = this.localClients.find((localClient: IClient) => localClient.id === client.id && localClient.channel?.connection.id === client.channel?.connection.id); if (existingClient !== undefined) { this.localClients[this.localClients.indexOf(existingClient)] = client; this.updateClientsState(); - console.log("Client updated") + Logger.log("Client updated") } else { - console.log("Client does not exist") + Logger.log("Client does not exist") } } // Remove data from local lists and update states removeConnection(connection: IConnection) { - console.log("Removing connection...", connection) + Logger.log("Removing connection...", connection) const existingConnection: IConnection | undefined = this.localConnections.find((localConnection: IConnection) => localConnection.id === connection.id); if (existingConnection !== undefined) { @@ -152,14 +153,14 @@ export class TS5DataHandler implements ITS5DataHandler { this.updateChannelsState(); this.updateClientsState(); this.updateConnectionsState(); - console.log("Connection removed") + Logger.log("Connection removed") } else { - console.log("Connection does not exist") + Logger.log("Connection does not exist") } } removeChannel(channel: IChannel) { - console.log("Removing channel...", channel) + Logger.log("Removing channel...", channel) const existingChannel: IChannel | undefined = this.localChannels.find((localChannel: IChannel) => localChannel.id === channel.id && localChannel.connection.id === channel.connection.id); if (existingChannel !== undefined) { @@ -170,22 +171,22 @@ export class TS5DataHandler implements ITS5DataHandler { this.updateClientsState(); this.updateChannelsState(); - console.log("Channel removed") + Logger.log("Channel removed") } else { - console.log("Channel does not exist") + Logger.log("Channel does not exist") } } removeClient(client: IClient) { - console.log("Removing client...", client) + Logger.log("Removing client...", client) const existingClient: IClient | undefined = this.localClients.find((localClient: IClient) => localClient.id === client.id && localClient.channel?.connection.id === client.channel?.connection.id); if (existingClient !== undefined) { this.localClients.splice(this.localClients.indexOf(existingClient), 1); this.updateClientsState(); - console.log("Client removed") + Logger.log("Client removed") } else { - console.log("Client does not exist") + Logger.log("Client does not exist") } } diff --git a/src/handlers/teamspeak/messageHandler.ts b/src/handlers/teamspeak/messageHandler.ts index db46965..3e5dd41 100644 --- a/src/handlers/teamspeak/messageHandler.ts +++ b/src/handlers/teamspeak/messageHandler.ts @@ -1,3 +1,4 @@ +import Logger from "@/utils/logger"; import { IChannelInfos, IConnection, IChannel, IAuthMessage, IClientInfo, IClientMovedMessage, IClient, IClientPropertiesUpdatedMessage, ITalkStatusChangedMessage, IClientSelfPropertyUpdatedMessage, IServerPropertiesUpdatedMessage, IConnectStatusChangedMessage, IChannelsMessage, ITS5MessageHandler, ITS5DataHandler } from "@interfaces/teamspeak"; // Handle incoming messages from TS5 client @@ -36,8 +37,6 @@ export class TS5MessageHandler implements ITS5MessageHandler { // This message is sent by the TS5 server when the client is connected // It contains the initial data handleAuthMessage(data: IAuthMessage) { - console.log("handleAuthMessage", data); - localStorage.setItem("apiKey", data.payload.apiKey); // Process auth payload and add initial data @@ -67,8 +66,6 @@ export class TS5MessageHandler implements ITS5MessageHandler { // This message is sent by the TS5 server when a client moves a channel OR joins/leaves the server handleClientMovedMessage(data: IClientMovedMessage) { - console.log("handleClientMoved", data); - const client: IClient | undefined = this.dataHandler.getClientById(data.payload.clientId, data.payload.connectionId); @@ -76,7 +73,6 @@ export class TS5MessageHandler implements ITS5MessageHandler { if (+data.payload.oldChannelId == 0) { // Create new client(when connecting to server) //set timout to wait for channels to be created setTimeout(() => { - console.log("---> New Client created") const newChannel = this.dataHandler.getChannelById(data.payload.newChannelId, data.payload.connectionId); if (newChannel !== undefined) { this.dataHandler.addClient( @@ -86,25 +82,23 @@ export class TS5MessageHandler implements ITS5MessageHandler { channel: newChannel, properties: data.payload.properties, }); + Logger.ts(`New Client found (${data.payload.connectionId} - ${data.payload.clientId} - ${data.payload.properties.nickname})`) } }, 2000); + } else {//* This gets called when a client moves a channel OR joins/leaves the server const newChannel: IChannel | undefined = this.dataHandler.getChannelById(data.payload.newChannelId, data.payload.connectionId); if (newChannel === undefined || newChannel.id === 0) { - console.log("---> Client left") - + Logger.ts(`Client left (${data.payload.connectionId} - ${data.payload.clientId} - ${data.payload.properties.nickname})`) if (client !== undefined) { this.dataHandler.removeClient(client); - } return; } if (client !== undefined) { // Client already exists - - // Client moved - console.log("---> Client moved") + Logger.ts(`Client moved (${client.channel.connection.id} - ${client.id} - ${client.properties.nickname})`) this.dataHandler.updateClient({ ...client, @@ -113,7 +107,8 @@ export class TS5MessageHandler implements ITS5MessageHandler { } else { // Client does not exist // Client joined - console.log("---> New Client joined") + Logger.ts(`Client joined (${data.payload.connectionId} - ${data.payload.clientId} - ${data.payload.properties.nickname})`) + this.dataHandler.addClient( { id: data.payload.clientId, @@ -127,8 +122,6 @@ export class TS5MessageHandler implements ITS5MessageHandler { } handleClientPropertiesUpdatedMessage(data: IClientPropertiesUpdatedMessage) { - console.log("handleClientPropertiesUpdate", data); - const client: IClient | undefined = this.dataHandler.getClientById(data.payload.clientId, data.payload.connectionId); if (client !== undefined) { @@ -140,8 +133,6 @@ export class TS5MessageHandler implements ITS5MessageHandler { } handleTalkStatusChangedMessage(data: ITalkStatusChangedMessage) { - console.log("handleTalkStatusChanged", data); - const client: IClient | undefined = this.dataHandler.getClientById(data.payload.clientId, data.payload.connectionId); if (client !== undefined) { @@ -151,14 +142,12 @@ export class TS5MessageHandler implements ITS5MessageHandler { }); } - console.log(this.dataHandler.localConnections) - console.log(this.dataHandler.localChannels) - console.log(this.dataHandler.localClients) + // console.log(this.dataHandler.localConnections) + // console.log(this.dataHandler.localChannels) + // console.log(this.dataHandler.localClients) } handleClientSelfPropertyUpdatedMessage(data: IClientSelfPropertyUpdatedMessage) { - console.log("handleClientSelfPropertyUpdated", data); - const connection: IConnection | undefined = this.dataHandler.getConnectionById(this.activeConnectionId); if (data.payload.flag == "inputHardware" || connection == undefined) { // sadly thats the only way to detect if a server is active or not @@ -167,8 +156,6 @@ export class TS5MessageHandler implements ITS5MessageHandler { } handleServerPropertiesUpdatedMessage(data: IServerPropertiesUpdatedMessage) { - console.log("handleServerPropertiesUpdated", data); - const connection: IConnection | undefined = this.dataHandler.getConnectionById(data.payload.connectionId); if (connection !== undefined) { // Update existing connection @@ -180,8 +167,6 @@ export class TS5MessageHandler implements ITS5MessageHandler { } handleConnectStatusChangedMessage(data: IConnectStatusChangedMessage) { - console.log("handleConnectStatusChanged", data); - if (data.payload.status === 0) { // Disconnected from server const connection: IConnection | undefined = this.dataHandler.getConnectionById(data.payload.connectionId); @@ -201,19 +186,11 @@ export class TS5MessageHandler implements ITS5MessageHandler { } handleChannelsMessage(data: IChannelsMessage) { - console.log("handleChannels", data); - // Wait a bit for the connection to be added setTimeout(() => { - console.log(this.dataHandler.localConnections); - console.log(data.payload.connectionId) - console.log(this.dataHandler.localConnections.filter((connection: IConnection) => connection.id === data.payload.connectionId)[0]); - console.log(this.dataHandler.localConnections.find((connection: IConnection) => connection.id === data.payload.connectionId)); const connection: IConnection | undefined = this.dataHandler.getConnectionById(data.payload.connectionId); - console.log(connection); if (connection !== undefined) { this.parseChannelInfos(data.payload.info, connection); - console.log(data.payload.info) } }, 1000); }