added events

This commit is contained in:
2021-04-26 23:42:22 +02:00
parent b70d1d45fb
commit cf82d85554
7 changed files with 113 additions and 2 deletions

View File

@@ -13,7 +13,8 @@
"node-red": { "node-red": {
"nodes": { "nodes": {
"ts3-config": "dist/nodes/ts3-config/ts3-config.js", "ts3-config": "dist/nodes/ts3-config/ts3-config.js",
"ts3-get": "dist/nodes/ts3-call/ts3-call.js" "ts3-get": "dist/nodes/ts3-call/ts3-call.js",
"ts3-event": "dist/nodes/ts3-event/ts3-event.js"
} }
}, },
"dependencies": { "dependencies": {

View File

@@ -157,6 +157,6 @@
</select> </select>
<div class="form-row"> <div class="form-row">
You can find documentation for all functions You can find documentation for all functions
<a target="_blank" href="https://multivit4min.github.io/TS3-NodeJS-Library/classes/teamspeak.teamspeak-2.html"> here</a> <a target="_blank" href="https://multivit4min.github.io/TS3-NodeJS-Library/classes/teamspeak.teamspeak-2.html#on"> here</a>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,47 @@
import { NodeInitializer } from "node-red";
import { Ts3ConfigNode } from "../ts3-config/types";
import { Ts3EventConfig, Ts3EventNode } from "./types";
const nodeInit: NodeInitializer = (RED): void => {
function Ts3Event(
this: Ts3EventNode,
config: Ts3EventConfig
): 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"})
});
(async() =>{
const client = await ts3Config.getConnection()
this.warn("added: " + config.selection)
// HACK: like above i dont know how to use typescript
client.addListener(config.selection,(event: any)=>{
let msg = {
payload: event
}
console.log("### EVENT ###")
console.log(event)
this.send(msg)
})
})();
}
RED.nodes.registerType("ts3-event", Ts3Event);
};
export = nodeInit;

View File

@@ -0,0 +1,15 @@
import { NodeDef, Node, EditorNodeProperties } from "node-red";
export interface Ts3EventProps {
configid: string
selection: string
}
export interface Ts3EventData {
}
export interface Ts3EventConfig extends NodeDef, Ts3EventProps { }
export interface Ts3EventNode extends Node, Ts3EventData {}
export interface Ts3EventEditorNodeProperties extends EditorNodeProperties,Ts3EventProps {}

View File

@@ -0,0 +1,28 @@
<div class="form-row">
<label for="node-input-name"><i class="fa fa-globe"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-row">
<label for="node-input-configid"><i class="fa fa-server"></i> Connection</label>
<input type="text" id="node-input-configid">
</div>
<div class="form-row">
<label for="node-input-configid"><i class="fa fa-terminal"></i> Event</label>
<select class="form-select" id="node-input-selection">
<option value="channelcreate" >ChannelCreate </option>
<option value="channeldelete" >ChannelDelete </option>
<option value="channeledit" >ChannelEdit </option>
<option value="channelmove" >ChannelMove </option>
<option value="clientconnect" >ClientConnect </option>
<option value="clientdisconnect" >ClientDisconnect </option>
<option value="clientmoved" >ClientMoved </option>
<option value="serveredit" >ServerEdit </option>
<option value="textmessage" >TextMessage </option>
<option value="tokenused" >TokenUsed </option>
</select>
</div>
<div class="form-row">
You can find documentation for all events
<a target="_blank" href="https://multivit4min.github.io/TS3-NodeJS-Library/modules/types_events.html"> here</a>
</div>

View File

@@ -0,0 +1 @@
<p>Listen on events on Teamspeak</p>

View File

@@ -0,0 +1,19 @@
import { EditorRED } from "node-red";
import { Ts3EventEditorNodeProperties } from "../types";
declare const RED: EditorRED;
RED.nodes.registerType<Ts3EventEditorNodeProperties>('ts3-event',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""},
configid: { type:"ts3-config", value: "" },
selection: { value:"" }
},
inputs: 0,
outputs: 1,
label: function() {
return this.name || "TS3 " + this.selection;
}
});