diff --git a/docker-compose.yml b/docker-compose.yml index cf99f10..2a89863 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,3 +10,20 @@ services: - ./docker:/data ports: - 1880:1880 + networks: + - tsNet + ts3: + image: "teamspeak" + container_name: "ts3" + environment: + - TS3SERVER_LICENSE=accept + ports: + - "9987:9987/udp" + - "10011:10011" + - "30033:30033" + networks: + - tsNet + +networks: + tsNet: + driver: bridge diff --git a/docker-pack.sh b/docker-pack.sh index 54ca1d1..8dabcb8 100755 --- a/docker-pack.sh +++ b/docker-pack.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh set -e -rm -r dist +rm -rf dist yarn run build diff --git a/package.json b/package.json index 727e874..5595c10 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,6 @@ ], "node-red": { "nodes": { - "lower-case": "dist/nodes/lower-case/lower-case.js", - "lower-case-creds": "dist/nodes/lower-case-creds/lower-case-creds.js", "ts3-config": "dist/nodes/ts3-config/ts3-config.js", "ts3-get": "dist/nodes/ts3-get/ts3-get.js" } diff --git a/src/nodes/ts3-config/ts3-config.ts b/src/nodes/ts3-config/ts3-config.ts index c22d1af..3237781 100644 --- a/src/nodes/ts3-config/ts3-config.ts +++ b/src/nodes/ts3-config/ts3-config.ts @@ -1,16 +1,39 @@ import { NodeDef, NodeInitializer, Node } from "node-red"; import { Ts3ConfigConfig, Ts3ConfigNode } from "./types"; +import { TeamSpeak, QueryProtocol } from "ts3-nodejs-library" const nodeInit: NodeInitializer = (RED): void => { function Ts3Config( this: Ts3ConfigNode, config: Ts3ConfigConfig ): void { - RED.nodes.createNode(this, config); - this.host = config.host - this.nickname = config.nickname + RED.nodes.createNode(this, config) - // TODO connect ts3 query here + const host = config.host + const nickname = config.nickname + + let client: TeamSpeak | null = null + let connectPromise: Promise | null = null + + this.getConnection = async (): Promise=>{ + if (client){ + return client + }else if (connectPromise){ + return connectPromise + }else{ + connectPromise = TeamSpeak.connect({ + host: host, + protocol: QueryProtocol.RAW, + queryport: 10011, + serverport: 9987, + username: this.credentials.username, + password: this.credentials.password, + nickname: nickname + }) + this.emit("connected") + return await connectPromise + } + } } RED.nodes.registerType("ts3-config", Ts3Config,{ diff --git a/src/nodes/ts3-config/types.ts b/src/nodes/ts3-config/types.ts index e40876f..03a2849 100644 --- a/src/nodes/ts3-config/types.ts +++ b/src/nodes/ts3-config/types.ts @@ -1,4 +1,5 @@ import { NodeDef, Node } from "node-red"; +import { TeamSpeak } from "ts3-nodejs-library" export interface Ts3ConfigProps{ host: string, @@ -10,6 +11,11 @@ export interface Ts3ConfigCreds { password: string } +export interface Ts3ConfigData { + getConnection(): Promise +} + + export interface Ts3ConfigConfig extends NodeDef, Ts3ConfigProps, Ts3ConfigCreds { } -export interface Ts3ConfigNode extends Node, Ts3ConfigProps {} +export interface Ts3ConfigNode extends Node, Ts3ConfigData {} diff --git a/src/nodes/ts3-get/ts3-get.ts b/src/nodes/ts3-get/ts3-get.ts index 22bf3b2..25cae1a 100644 --- a/src/nodes/ts3-get/ts3-get.ts +++ b/src/nodes/ts3-get/ts3-get.ts @@ -8,12 +8,18 @@ const nodeInit: NodeInitializer = (RED): void => { config: Ts3GetConfig ): void { RED.nodes.createNode(this, config); - this.warn(config.configid) - this.ts3Config = RED.nodes.getNode(config.configid) as Ts3ConfigNode - this.on("input", (msg) => { - msg.payload = this.ts3Config.credentials.username - this.send(msg) + const ts3Config = RED.nodes.getNode(config.configid) as Ts3ConfigNode + + this.on("input", async (msg,send,done) => { + const client = await ts3Config.getConnection() + + let clients = await client.clientList({ clientType: 0 }) + + msg.payload = clients + + send(msg) + done() }) } diff --git a/src/nodes/ts3-get/types.ts b/src/nodes/ts3-get/types.ts index 7e839ae..781ad3f 100644 --- a/src/nodes/ts3-get/types.ts +++ b/src/nodes/ts3-get/types.ts @@ -6,7 +6,6 @@ export interface Ts3GetProps { } export interface Ts3GetData { - ts3Config: Ts3ConfigNode } export interface Ts3GetConfig extends NodeDef, Ts3GetProps { }