11import { 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
56export 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}
0 commit comments