call ts3 functions from node
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
import { TeamSpeak } from "ts3-nodejs-library";
|
||||
|
||||
export default function handleGet(func: string, client: TeamSpeak, options: any): Promise<any>{
|
||||
const member: any = client[func as keyof TeamSpeak]
|
||||
|
||||
if (typeof member === "function"){
|
||||
let rtn;
|
||||
|
||||
if (options instanceof Array){
|
||||
rtn = member(...options)
|
||||
}else{
|
||||
rtn = member(options)
|
||||
}
|
||||
|
||||
if (rtn instanceof Promise){
|
||||
return rtn
|
||||
}else{
|
||||
return rtn
|
||||
}
|
||||
}else{
|
||||
throw new Error(`"${func}" is not a valid function name`);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NodeInitializer } from "node-red";
|
||||
import { TeamSpeak } from "ts3-nodejs-library";
|
||||
import { Ts3ConfigNode } from "../ts3-config/types";
|
||||
import handleGet from "./handleGet";
|
||||
import { Ts3GetConfig, Ts3GetNode } from "./types";
|
||||
|
||||
const nodeInit: NodeInitializer = (RED): void => {
|
||||
@@ -28,12 +28,22 @@ const nodeInit: NodeInitializer = (RED): void => {
|
||||
this.on("input", async (msg,send,done) => {
|
||||
const client = await ts3Config.getConnection()
|
||||
|
||||
let payload = await handleGet(config.selection,client,msg.payload)
|
||||
//let payload = await client.whoami()
|
||||
const member: any = client[config.selection as keyof TeamSpeak]
|
||||
if (typeof member === "function"){
|
||||
let args: any[] = []
|
||||
|
||||
msg.payload = payload
|
||||
if (msg.payload instanceof Array){
|
||||
args = msg.payload
|
||||
}else{
|
||||
args = [msg.payload]
|
||||
}
|
||||
msg.payload = await member.apply(client,args)
|
||||
|
||||
send(msg)
|
||||
}else{
|
||||
this.error(`Failed to call ${config.selection}. Not a function`)
|
||||
}
|
||||
|
||||
done()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user