diff --git a/src/handlers/teamspeak/connectionHandler.ts b/src/handlers/teamspeak/connectionHandler.ts index e972d19..985054f 100644 --- a/src/handlers/teamspeak/connectionHandler.ts +++ b/src/handlers/teamspeak/connectionHandler.ts @@ -1,11 +1,11 @@ -import { IAuthSenderPayload, IChannel, IClient, IConnection } from "interfaces/teamspeak"; +import { IAuthSenderPayload, IChannel, IClient, IConnection, ITS5Connection } from "interfaces/teamspeak"; import { TS5DataHandler } from "./dataHandler"; import { TS5MessageHandler } from "./messageHandler"; // Establish connection to TS5 client // Main class -export class TS5Connection { +export class TS5Connection implements ITS5Connection { ws: WebSocket; // Websocket connection to TS5 client authenticated = false; // Is the connection authenticated? remoteAppPort: number; // Port of TS5 client diff --git a/src/handlers/teamspeak/dataHandler.ts b/src/handlers/teamspeak/dataHandler.ts index a268cd7..af96a3d 100644 --- a/src/handlers/teamspeak/dataHandler.ts +++ b/src/handlers/teamspeak/dataHandler.ts @@ -1,11 +1,11 @@ -import { IConnection, IChannel, IClient } from "interfaces/teamspeak"; +import { IConnection, IChannel, IClient, ITS5DataHandler } from "interfaces/teamspeak"; /** * Handles data received from TS5 client (list of connections, channels and clients) * Updates the states of App.tsx */ -export class TS5DataHandler { +export class TS5DataHandler implements ITS5DataHandler { // Local lists of connections, channels and clients // These lists are used to keep track of the data, independent of the App.tsx state localConnections: IConnection[]; diff --git a/src/handlers/teamspeak/messageHandler.ts b/src/handlers/teamspeak/messageHandler.ts index ba5797a..0e922cb 100644 --- a/src/handlers/teamspeak/messageHandler.ts +++ b/src/handlers/teamspeak/messageHandler.ts @@ -1,8 +1,8 @@ -import { IChannelInfos, IConnection, IChannel, IAuthMessage, IClientInfo, IClientMovedMessage, IClient, IClientPropertiesUpdatedMessage, ITalkStatusChangedMessage, IClientSelfPropertyUpdatedMessage, IServerPropertiesUpdatedMessage, IConnectStatusChangedMessage, IChannelsMessage } from "interfaces/teamspeak"; +import { IChannelInfos, IConnection, IChannel, IAuthMessage, IClientInfo, IClientMovedMessage, IClient, IClientPropertiesUpdatedMessage, ITalkStatusChangedMessage, IClientSelfPropertyUpdatedMessage, IServerPropertiesUpdatedMessage, IConnectStatusChangedMessage, IChannelsMessage, ITS5MessageHandler } from "interfaces/teamspeak"; import { TS5DataHandler } from "./dataHandler"; // Handle incoming messages from TS5 client -export class TS5MessageHandler { +export class TS5MessageHandler implements ITS5MessageHandler { ws: WebSocket; dataHandler: TS5DataHandler; diff --git a/src/interfaces/teamspeak.ts b/src/interfaces/teamspeak.ts index ae5be44..df56675 100644 --- a/src/interfaces/teamspeak.ts +++ b/src/interfaces/teamspeak.ts @@ -1,3 +1,54 @@ +// Classes +export interface ITS5Connection { + ws: WebSocket; + authenticated: boolean; + remoteAppPort: number; + dataHandler: ITS5DataHandler; + messageHandler: ITS5MessageHandler; + reconnect(): void; + connect(): void; +} + +export interface ITS5DataHandler { + localConnections: IConnection[]; + localChannels: IChannel[]; + localClients: IClient[]; + setConnections: React.Dispatch>; + setChannels: React.Dispatch>; + setClients: React.Dispatch>; + clearAll(): void; + addConnection(connection: IConnection): void; + addChannel(channel: IChannel): void; + addClient(client: IClient): void; + updateConnection(connection: IConnection): void; + updateChannel(channel: IChannel): void; + updateClient(client: IClient): void; + removeConnection(connection: IConnection): void; + removeChannel(channel: IChannel): void; + removeClient(client: IClient): void; + getConnectionById(id: number): IConnection | undefined; + getChannelById(id: number, connectionId: number): IChannel | undefined; + getClientById(id: number, connectionId: number): IClient | undefined; +} + +export interface ITS5MessageHandler { + ws: WebSocket; + dataHandler: ITS5DataHandler; + setActiveConnectionStateId: React.Dispatch>; + activeConnectionId: number; + setActiveConnection(connectionId: number): void; + parseChannelInfos(channelInfos: IChannelInfos, connection: IConnection): void; + handleAuthMessage(data: IAuthMessage): void; + handleClientMovedMessage(data: IClientMovedMessage): void; + handleClientPropertiesUpdatedMessage(data: IClientPropertiesUpdatedMessage): void; + handleTalkStatusChangedMessage(data: ITalkStatusChangedMessage): void; + handleClientSelfPropertyUpdatedMessage(data: IClientSelfPropertyUpdatedMessage): void; + handleServerPropertiesUpdatedMessage(data: IServerPropertiesUpdatedMessage): void; + handleConnectStatusChangedMessage(data: IConnectStatusChangedMessage): void; + handleChannelsMessage(data: IChannelsMessage): void; +} + +// Remote App export interface IAuthSenderPayload { type: "auth"; payload: {