ts3 stff
This commit is contained in:
@@ -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,{
|
||||
|
||||
Reference in New Issue
Block a user