Skip to content

Commit

Permalink
[fix] bug while reconnecting server
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTyp7 committed Jun 28, 2023
1 parent 92906d2 commit b7beddb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import App from "./App.tsx";
import "@styles/index.scss";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
);
22 changes: 15 additions & 7 deletions src/teamspeak5Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export class TS5Connection {
setConnections: React.Dispatch<React.SetStateAction<IConnection[]>>,
setChannels: React.Dispatch<React.SetStateAction<IChannel[]>>,
setClients: React.Dispatch<React.SetStateAction<IClient[]>>,
setActiveConnectionId: React.Dispatch<React.SetStateAction<number>>,
setActiveConnectionStateId: React.Dispatch<React.SetStateAction<number>>,
) {
// Create websocket connection to TS5 client
this.remoteAppPort = remoteAppPort;
this.ws = new WebSocket(`ws://localhost:${this.remoteAppPort}`);

// 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() {
Expand Down Expand Up @@ -328,12 +328,18 @@ class TS5MessageHandler {
ws: WebSocket;
dataHandler: TS5DataHandler;

setActiveConnectionId: React.Dispatch<React.SetStateAction<number>>;
setActiveConnectionStateId: React.Dispatch<React.SetStateAction<number>>;
activeConnectionId = 0;

constructor(ws: WebSocket, dataHandler: TS5DataHandler, setActiveConnectionId: React.Dispatch<React.SetStateAction<number>>) {
constructor(ws: WebSocket, dataHandler: TS5DataHandler, setActiveConnectionStateId: React.Dispatch<React.SetStateAction<number>>) {
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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b7beddb

Please sign in to comment.