prepared function selection

This commit is contained in:
2021-04-23 12:05:33 +02:00
parent a110d00a0f
commit 8b86e8ea40
5 changed files with 30 additions and 5 deletions

View File

@@ -44,7 +44,6 @@ const nodeInit: NodeInitializer = (RED): void => {
if (client != null){
await client.reconnect(-1, 1000)
}else{
// TODO: Emit error
this.emit("error")
}
}else{

View File

@@ -0,0 +1,13 @@
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<any>{
switch (func) {
case GetFunctions.CLIENTS_LIST:
return client.clientList(options)
default:
break;
}
}

View File

@@ -3,7 +3,8 @@
category: 'function',
color: '#a6bbcf',
defaults: {
configid: {type:"ts3-config"}
configid: {type:"ts3-config"},
selection: {default: ""}
},
inputs: 1,
outputs: 1,
@@ -18,6 +19,12 @@
<label for="node-input-configid"><i class="fa fa-database"></i> Connection</label>
<input type="text" id="node-input-configid">
</div>
<div class="form-row">
<label for="node-input-configid"><i class="fa fa-database"></i> Connection</label>
<select class="form-select" id="node-input-selection">
<option selected>Open this select menu</option>
</select>
</div>
</script>
<script type="text/html" data-help-name="ts3-get">

View File

@@ -1,6 +1,7 @@
import { NodeInitializer } from "node-red";
import { Ts3ConfigNode } from "../ts3-config/types";
import { Ts3GetConfig, Ts3GetNode } from "./types";
import handleGet from "./handleGet";
import { GetFunctions, Ts3GetConfig, Ts3GetNode } from "./types";
const nodeInit: NodeInitializer = (RED): void => {
function Ts3Get(
@@ -27,9 +28,9 @@ const nodeInit: NodeInitializer = (RED): void => {
this.on("input", async (msg,send,done) => {
const client = await ts3Config.getConnection()
let clients = await client.clientList({ clientType: 0 })
let payload = await handleGet(GetFunctions.CLIENTS_LIST,client,msg.payload)
msg.payload = clients
msg.payload = payload
send(msg)
done()

View File

@@ -3,6 +3,7 @@ import { Ts3ConfigNode } from "../ts3-config/types";
export interface Ts3GetProps {
configid: string
selection: string
}
export interface Ts3GetData {
@@ -11,3 +12,7 @@ export interface Ts3GetData {
export interface Ts3GetConfig extends NodeDef, Ts3GetProps { }
export interface Ts3GetNode extends Node, Ts3GetData {}
export enum GetFunctions {
CLIENTS_LIST,
}