diff --git a/src/main.tsx b/src/main.tsx index b09d690..6c51dfd 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -5,9 +5,7 @@ import App from "./App.tsx"; import "@styles/index.scss"; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - - - - - + + + ); diff --git a/src/teamspeak5Handler.ts b/src/teamspeak5Handler.ts index e07bf1f..b8844c9 100644 --- a/src/teamspeak5Handler.ts +++ b/src/teamspeak5Handler.ts @@ -18,7 +18,7 @@ export class TS5Connection { setConnections: React.Dispatch>, setChannels: React.Dispatch>, setClients: React.Dispatch>, - setActiveConnectionId: React.Dispatch>, + setActiveConnectionStateId: React.Dispatch>, ) { // Create websocket connection to TS5 client this.remoteAppPort = remoteAppPort; @@ -26,7 +26,7 @@ export class TS5Connection { // Create dataHandler and messageHandler this.dataHandler = new TS5DataHandler(setConnections, setChannels, setClients); - this.messageHandler = new TS5MessageHandler(this.ws, this.dataHandler, setActiveConnectionId); + this.messageHandler = new TS5MessageHandler(this.ws, this.dataHandler, setActiveConnectionStateId); } reconnect() { @@ -328,12 +328,18 @@ class TS5MessageHandler { ws: WebSocket; dataHandler: TS5DataHandler; - setActiveConnectionId: React.Dispatch>; + setActiveConnectionStateId: React.Dispatch>; + activeConnectionId = 0; - constructor(ws: WebSocket, dataHandler: TS5DataHandler, setActiveConnectionId: React.Dispatch>) { + constructor(ws: WebSocket, dataHandler: TS5DataHandler, setActiveConnectionStateId: React.Dispatch>) { this.ws = ws; this.dataHandler = dataHandler; - this.setActiveConnectionId = setActiveConnectionId; + this.setActiveConnectionStateId = setActiveConnectionStateId; + } + + setActiveConnection(connectionId: number) { + this.activeConnectionId = connectionId; + this.setActiveConnectionStateId(connectionId); } parseChannelInfos(channelInfos: IChannelInfos, connection: IConnection) { @@ -476,8 +482,10 @@ class TS5MessageHandler { handleClientSelfPropertyUpdatedMessage(data: IClientSelfPropertyUpdatedMessage) { console.log("handleClientSelfPropertyUpdated", data); - if (data.payload.flag == "inputHardware") { // sadly thats the only way to detect if a server is active or not - this.setActiveConnectionId(data.payload.connectionId); + 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 + this.setActiveConnection(data.payload.connectionId); } }