From 6d0937813b96e1ddb382336524a56bd858d84602 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 23 Apr 2021 15:36:10 +0200 Subject: [PATCH] idk --- src/nodes/ts3-get/handleGet.ts | 26 +++++++++---- src/nodes/ts3-get/ts3-get.ts | 7 ++-- src/nodes/ts3-get/types.ts | 5 --- src/nodes/ts3-get/ui/editor.html | 67 +++++++++++++++++++++++++++++++- 4 files changed, 88 insertions(+), 17 deletions(-) diff --git a/src/nodes/ts3-get/handleGet.ts b/src/nodes/ts3-get/handleGet.ts index 790032c..e338841 100644 --- a/src/nodes/ts3-get/handleGet.ts +++ b/src/nodes/ts3-get/handleGet.ts @@ -1,13 +1,23 @@ -import { NodeMessageInFlow } from "node-red"; import { TeamSpeak } from "ts3-nodejs-library"; -import { GetFunctions } from "./types"; -export default async function handleGet(func: GetFunctions, client: TeamSpeak, options: any): Promise{ - switch (func) { - case GetFunctions.CLIENTS_LIST: - return client.clientList(options) +export default function handleGet(func: string, client: TeamSpeak, options: any): Promise{ + const member: any = client[func as keyof TeamSpeak] + + if (typeof member === "function"){ + let rtn; - default: - break; + 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`); } } \ No newline at end of file diff --git a/src/nodes/ts3-get/ts3-get.ts b/src/nodes/ts3-get/ts3-get.ts index 583272b..755c589 100644 --- a/src/nodes/ts3-get/ts3-get.ts +++ b/src/nodes/ts3-get/ts3-get.ts @@ -1,7 +1,7 @@ import { NodeInitializer } from "node-red"; import { Ts3ConfigNode } from "../ts3-config/types"; import handleGet from "./handleGet"; -import { GetFunctions, Ts3GetConfig, Ts3GetNode } from "./types"; +import { Ts3GetConfig, Ts3GetNode } from "./types"; const nodeInit: NodeInitializer = (RED): void => { function Ts3Get( @@ -28,8 +28,9 @@ const nodeInit: NodeInitializer = (RED): void => { this.on("input", async (msg,send,done) => { const client = await ts3Config.getConnection() - let payload = await handleGet(GetFunctions.CLIENTS_LIST,client,msg.payload) - + let payload = await handleGet(config.selection,client,msg.payload) + //let payload = await client.whoami() + msg.payload = payload send(msg) diff --git a/src/nodes/ts3-get/types.ts b/src/nodes/ts3-get/types.ts index 95f25e8..e95f63c 100644 --- a/src/nodes/ts3-get/types.ts +++ b/src/nodes/ts3-get/types.ts @@ -1,5 +1,4 @@ import { NodeDef, Node, EditorNodeProperties } from "node-red"; -import { Ts3ConfigNode } from "../ts3-config/types"; export interface Ts3GetProps { configid: string @@ -14,7 +13,3 @@ export interface Ts3GetConfig extends NodeDef, Ts3GetProps { } export interface Ts3GetNode extends Node, Ts3GetData {} export interface Ts3GetEditorNodeProperties extends EditorNodeProperties,Ts3GetProps {} - -export enum GetFunctions { - CLIENTS_LIST, -} diff --git a/src/nodes/ts3-get/ui/editor.html b/src/nodes/ts3-get/ui/editor.html index 67adc5b..a6c055a 100644 --- a/src/nodes/ts3-get/ui/editor.html +++ b/src/nodes/ts3-get/ui/editor.html @@ -9,6 +9,71 @@
\ No newline at end of file