Skip to content
This repository was archived by the owner on Aug 2, 2026. It is now read-only.

Commit 798dfd8

Browse files
committed
fixed subchannel not being recognized
1 parent 23a8a64 commit 798dfd8

4 files changed

Lines changed: 60 additions & 16 deletions

File tree

src/handlers/teamspeak/connectionHandler.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler {
5656
this.logger.log('Connecting to TS5 client...');
5757

5858
// Create authentication payload
59-
const initalPayload: IAuthSenderPayload = {
59+
const initialPayload: IAuthSenderPayload = {
6060
type: "auth",
6161
payload: {
6262
...this.authPayload,
@@ -68,15 +68,15 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler {
6868

6969
this.ws.onopen = () => {
7070
// Send authentication payload to TS5 client
71-
this.ws.send(JSON.stringify(initalPayload));
72-
this.logger.wsSent(initalPayload);
71+
this.ws.send(JSON.stringify(initialPayload));
72+
this.logger.wsSent(initialPayload);
7373
};
7474

7575
this.ws.onclose = (event) => {
7676
this.logger.log("WebSocket connection closed", event);
7777

7878
// If the connection was closed before authentication, remove the API key from local storage
79-
// OBS weirdly caches the localstorage and is very stubborn about clearing it (even when clicken "Clear Cache")
79+
// OBS weirdly caches the localstorage and is very stubborn about clearing it (even when clicking "Clear Cache")
8080
if (!this.authenticated) {
8181
this.logger.log("WebSocket connection closed before authentication");
8282
localStorage.removeItem("apiKey");
@@ -120,6 +120,9 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler {
120120
case "channels":
121121
this.messageHandler.handleChannelsMessage(data);
122122
break;
123+
case "channelCreated":
124+
this.messageHandler.handleChannelCreatedMessage(data);
125+
break;
123126
default:
124127
this.logger.log(`No handler for event type: ${data.type}`);
125128
break;

src/handlers/teamspeak/dataHandler.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IConnection, IChannel, IClient, ITS5DataHandler } from "interfaces/team
44

55
/**
66
* Handles data received from TS5 client (list of connections, channels and clients)
7-
* Updates the states of App.tsx
7+
* Updates the states of useTSRemoteApp.tsx
88
*/
99
export class TS5DataHandler implements ITS5DataHandler {
1010
// Local lists of connections, channels and clients
@@ -38,6 +38,18 @@ export class TS5DataHandler implements ITS5DataHandler {
3838
this.logger = logger;
3939
}
4040

41+
get connections(): IConnection[] {
42+
return this.localConnections;
43+
}
44+
45+
get channels(): IChannel[] {
46+
return this.localChannels;
47+
}
48+
49+
get clients(): IClient[] {
50+
return this.localClients;
51+
}
52+
4153
// Update App.tsx states
4254
private updateConnectionsState() {
4355
this.setConnections([...this.localConnections]);

src/handlers/teamspeak/messageHandler.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ILogger } from "utils/logger";
2-
import { IChannelInfos, IConnection, IChannel, IAuthMessage, IClientInfo, IClientMovedMessage, IClient, IClientPropertiesUpdatedMessage, ITalkStatusChangedMessage, IClientSelfPropertyUpdatedMessage, IServerPropertiesUpdatedMessage, IConnectStatusChangedMessage, IChannelsMessage, ITS5MessageHandler, ITS5DataHandler } from "interfaces/teamspeak";
2+
import { IChannelInfos, IConnection, IChannel, IAuthMessage, IClientInfo, IClientMovedMessage, IClient, IClientPropertiesUpdatedMessage, ITalkStatusChangedMessage, IClientSelfPropertyUpdatedMessage, IServerPropertiesUpdatedMessage, IConnectStatusChangedMessage, IChannelsMessage, ITS5MessageHandler, ITS5DataHandler, IChannelCreatedMessage } from "interfaces/teamspeak";
3+
import { log } from "console";
34

45
// Handle incoming messages from TS5 client
56
export class TS5MessageHandler implements ITS5MessageHandler {
@@ -25,15 +26,13 @@ export class TS5MessageHandler implements ITS5MessageHandler {
2526
parseChannelInfos(channelInfos: IChannelInfos, connection: IConnection) {
2627
channelInfos.rootChannels.forEach((channel: IChannel) => {
2728
this.dataHandler.addChannel({ ...channel, connection: connection });
28-
29-
if (channelInfos) {
30-
if (channelInfos.subChannels !== null && channel.id in channelInfos.subChannels) {
31-
channelInfos.subChannels[channel.id]?.forEach((subChannel: IChannel) => {
32-
this.dataHandler.addChannel({ ...subChannel, connection: connection });
33-
});
34-
}
35-
}
3629
});
30+
31+
for (const key in channelInfos.subChannels) {
32+
channelInfos.subChannels[key]?.forEach((subChannel: IChannel) => {
33+
this.dataHandler.addChannel({ ...subChannel, connection: connection });
34+
});
35+
}
3736
}
3837

3938
// This message is sent by the TS5 server when the client is connected
@@ -70,10 +69,9 @@ export class TS5MessageHandler implements ITS5MessageHandler {
7069
handleClientMovedMessage(data: IClientMovedMessage) {
7170
const client: IClient | undefined = this.dataHandler.getClientById(data.payload.clientId, data.payload.connectionId);
7271

73-
7472
//* This gets called when we are connecting to the server and the new clients get loaded
7573
if (+data.payload.oldChannelId == 0) { // Create new client(when connecting to server)
76-
//set timout to wait for channels to be created
74+
//set timeout to wait for channels to be created
7775
setTimeout(() => {
7876
const newChannel = this.dataHandler.getChannelById(data.payload.newChannelId, data.payload.connectionId);
7977
if (newChannel !== undefined) {
@@ -149,6 +147,7 @@ export class TS5MessageHandler implements ITS5MessageHandler {
149147
// console.log(this.dataHandler.localClients)
150148

151149
}
150+
152151
handleClientSelfPropertyUpdatedMessage(data: IClientSelfPropertyUpdatedMessage) {
153152
const connection: IConnection | undefined = this.dataHandler.getConnectionById(this.activeConnectionId);
154153

@@ -196,4 +195,19 @@ export class TS5MessageHandler implements ITS5MessageHandler {
196195
}
197196
}, 1000);
198197
}
198+
199+
handleChannelCreatedMessage(data: IChannelCreatedMessage) {
200+
const connection = this.dataHandler.getConnectionById(data.payload.connectionId);
201+
202+
if (connection !== undefined) {
203+
this.dataHandler.addChannel(
204+
{
205+
id: data.payload.channelId,
206+
connection: connection,
207+
order: data.payload.properties.order,
208+
parentId: data.payload.parentId,
209+
properties: data.payload.properties,
210+
});
211+
}
212+
}
199213
}

src/interfaces/teamspeak.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export interface ITS5DataHandler {
3535
getConnectionById(id: number): IConnection | undefined;
3636
getChannelById(id: number, connectionId: number): IChannel | undefined;
3737
getClientById(id: number, connectionId: number): IClient | undefined;
38+
39+
readonly connections: IConnection[];
40+
readonly channels: IChannel[];
41+
readonly clients: IClient[];
3842
}
3943

4044
export interface ITS5MessageHandler {
@@ -53,6 +57,7 @@ export interface ITS5MessageHandler {
5357
handleServerPropertiesUpdatedMessage(data: IServerPropertiesUpdatedMessage): void;
5458
handleConnectStatusChangedMessage(data: IConnectStatusChangedMessage): void;
5559
handleChannelsMessage(data: IChannelsMessage): void;
60+
handleChannelCreatedMessage(data: IChannelCreatedMessage): void;
5661
}
5762

5863
// Remote App
@@ -345,4 +350,14 @@ export interface IChannelsMessage {
345350
connectionId: number;
346351
info: IChannelInfos
347352
}
353+
}
354+
355+
export interface IChannelCreatedMessage {
356+
type: "channelCreated";
357+
payload: {
358+
channelId: number;
359+
connectionId: number;
360+
parentId: string;
361+
properties: IChannelProperties;
362+
}
348363
}

0 commit comments

Comments
 (0)