diff --git a/package.json b/package.json index 5a2f99b..fa877c2 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/nodes/ts3-call/ui/editor.html b/src/nodes/ts3-call/ui/editor.html index 83e7223..ff2bee4 100644 --- a/src/nodes/ts3-call/ui/editor.html +++ b/src/nodes/ts3-call/ui/editor.html @@ -157,6 +157,6 @@
You can find documentation for all functions - here + here
\ No newline at end of file diff --git a/src/nodes/ts3-event/ts3-event.ts b/src/nodes/ts3-event/ts3-event.ts new file mode 100644 index 0000000..6678682 --- /dev/null +++ b/src/nodes/ts3-event/ts3-event.ts @@ -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; diff --git a/src/nodes/ts3-event/types.ts b/src/nodes/ts3-event/types.ts new file mode 100644 index 0000000..9bc7a5b --- /dev/null +++ b/src/nodes/ts3-event/types.ts @@ -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 {} diff --git a/src/nodes/ts3-event/ui/editor.html b/src/nodes/ts3-event/ui/editor.html new file mode 100644 index 0000000..a70b67b --- /dev/null +++ b/src/nodes/ts3-event/ui/editor.html @@ -0,0 +1,28 @@ +
+ + +
+
+ + +
+
+ + +
+ +
+ You can find documentation for all events + here +
diff --git a/src/nodes/ts3-event/ui/help.html b/src/nodes/ts3-event/ui/help.html new file mode 100644 index 0000000..6bccd7f --- /dev/null +++ b/src/nodes/ts3-event/ui/help.html @@ -0,0 +1 @@ +

Listen on events on Teamspeak

\ No newline at end of file diff --git a/src/nodes/ts3-event/ui/index.ts b/src/nodes/ts3-event/ui/index.ts new file mode 100644 index 0000000..38526e8 --- /dev/null +++ b/src/nodes/ts3-event/ui/index.ts @@ -0,0 +1,19 @@ +import { EditorRED } from "node-red"; +import { Ts3EventEditorNodeProperties } from "../types"; + +declare const RED: EditorRED; + +RED.nodes.registerType('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; + } +}); \ No newline at end of file