mirror of
https://github.com/DerTyp7/teamspeak-obs-overlay.git
synced 2025-10-29 12:52:09 +01:00
[feature] add interfaces for classes
This commit is contained in:
@@ -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 { TS5DataHandler } from "./dataHandler";
|
||||||
import { TS5MessageHandler } from "./messageHandler";
|
import { TS5MessageHandler } from "./messageHandler";
|
||||||
|
|
||||||
|
|
||||||
// Establish connection to TS5 client
|
// Establish connection to TS5 client
|
||||||
// Main class
|
// Main class
|
||||||
export class TS5Connection {
|
export class TS5Connection implements ITS5Connection {
|
||||||
ws: WebSocket; // Websocket connection to TS5 client
|
ws: WebSocket; // Websocket connection to TS5 client
|
||||||
authenticated = false; // Is the connection authenticated?
|
authenticated = false; // Is the connection authenticated?
|
||||||
remoteAppPort: number; // Port of TS5 client
|
remoteAppPort: number; // Port of TS5 client
|
||||||
|
|||||||
@@ -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)
|
* Handles data received from TS5 client (list of connections, channels and clients)
|
||||||
* Updates the states of App.tsx
|
* Updates the states of App.tsx
|
||||||
*/
|
*/
|
||||||
export class TS5DataHandler {
|
export class TS5DataHandler implements ITS5DataHandler {
|
||||||
// Local lists of connections, channels and clients
|
// Local lists of connections, channels and clients
|
||||||
// These lists are used to keep track of the data, independent of the App.tsx state
|
// These lists are used to keep track of the data, independent of the App.tsx state
|
||||||
localConnections: IConnection[];
|
localConnections: IConnection[];
|
||||||
|
|||||||
@@ -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";
|
import { TS5DataHandler } from "./dataHandler";
|
||||||
|
|
||||||
// Handle incoming messages from TS5 client
|
// Handle incoming messages from TS5 client
|
||||||
export class TS5MessageHandler {
|
export class TS5MessageHandler implements ITS5MessageHandler {
|
||||||
ws: WebSocket;
|
ws: WebSocket;
|
||||||
dataHandler: TS5DataHandler;
|
dataHandler: TS5DataHandler;
|
||||||
|
|
||||||
|
|||||||
@@ -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<React.SetStateAction<IConnection[]>>;
|
||||||
|
setChannels: React.Dispatch<React.SetStateAction<IChannel[]>>;
|
||||||
|
setClients: React.Dispatch<React.SetStateAction<IClient[]>>;
|
||||||
|
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<React.SetStateAction<number>>;
|
||||||
|
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 {
|
export interface IAuthSenderPayload {
|
||||||
type: "auth";
|
type: "auth";
|
||||||
payload: {
|
payload: {
|
||||||
|
|||||||
Reference in New Issue
Block a user