renamed to ts3-call
This commit is contained in:
54
src/nodes/ts3-call/ts3-call.ts
Normal file
54
src/nodes/ts3-call/ts3-call.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { NodeInitializer } from "node-red";
|
||||
import { TeamSpeak } from "ts3-nodejs-library";
|
||||
import { Ts3ConfigNode } from "../ts3-config/types";
|
||||
import { Ts3CallConfig, Ts3CallNode } from "./types";
|
||||
|
||||
const nodeInit: NodeInitializer = (RED): void => {
|
||||
function Ts3Call(
|
||||
this: Ts3CallNode,
|
||||
config: Ts3CallConfig
|
||||
): void {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
const ts3Config = RED.nodes.getNode(config.configid) as Ts3ConfigNode
|
||||
|
||||
// HACK: ts3Config.on("connected") would not work because i dont know how to use typescript
|
||||
ts3Config.addListener("connected",()=>{
|
||||
this.status({fill:"green",shape:"dot",text:"Connected"})
|
||||
})
|
||||
|
||||
ts3Config.addListener("disconnect",()=>{
|
||||
this.status({fill:"grey",shape:"dot",text:"not conncted"})
|
||||
})
|
||||
|
||||
ts3Config.addListener("error",()=>{
|
||||
this.status({fill:"red",shape:"dot",text:"Error"})
|
||||
})
|
||||
|
||||
this.on("input", async (msg,send,done) => {
|
||||
const client = await ts3Config.getConnection()
|
||||
|
||||
const member: any = client[config.selection as keyof TeamSpeak]
|
||||
if (typeof member === "function"){
|
||||
let args: any[] = []
|
||||
|
||||
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()
|
||||
})
|
||||
}
|
||||
|
||||
RED.nodes.registerType("ts3-call", Ts3Call);
|
||||
};
|
||||
|
||||
export = nodeInit;
|
||||
Reference in New Issue
Block a user