ts3 stff
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
set -e
|
||||
|
||||
rm -r dist
|
||||
rm -rf dist
|
||||
|
||||
yarn run build
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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,{
|
||||
|
||||
@@ -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<TeamSpeak>
|
||||
}
|
||||
|
||||
|
||||
export interface Ts3ConfigConfig extends NodeDef, Ts3ConfigProps, Ts3ConfigCreds { }
|
||||
|
||||
export interface Ts3ConfigNode extends Node<Ts3ConfigCreds>, Ts3ConfigProps {}
|
||||
export interface Ts3ConfigNode extends Node<Ts3ConfigCreds>, Ts3ConfigData {}
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ export interface Ts3GetProps {
|
||||
}
|
||||
|
||||
export interface Ts3GetData {
|
||||
ts3Config: Ts3ConfigNode
|
||||
}
|
||||
|
||||
export interface Ts3GetConfig extends NodeDef, Ts3GetProps { }
|
||||
|
||||
Reference in New Issue
Block a user