This commit is contained in:
2021-04-22 00:00:13 +02:00
parent a652d42472
commit 7a668cbd80
7 changed files with 63 additions and 14 deletions

View File

@@ -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<TeamSpeak> | null = null
this.getConnection = async (): Promise<TeamSpeak>=>{
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,{