added events
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"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": {
|
||||
|
||||
@@ -157,6 +157,6 @@
|
||||
</select>
|
||||
<div class="form-row">
|
||||
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>
|
||||
47
src/nodes/ts3-event/ts3-event.ts
Normal file
47
src/nodes/ts3-event/ts3-event.ts
Normal 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;
|
||||
15
src/nodes/ts3-event/types.ts
Normal file
15
src/nodes/ts3-event/types.ts
Normal 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 {}
|
||||
28
src/nodes/ts3-event/ui/editor.html
Normal file
28
src/nodes/ts3-event/ui/editor.html
Normal 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>
|
||||
1
src/nodes/ts3-event/ui/help.html
Normal file
1
src/nodes/ts3-event/ui/help.html
Normal file
@@ -0,0 +1 @@
|
||||
<p>Listen on events on Teamspeak</p>
|
||||
19
src/nodes/ts3-event/ui/index.ts
Normal file
19
src/nodes/ts3-event/ui/index.ts
Normal 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;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user