@open-wa/node-red 2.8.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/nodes/cmd/cmd.html +79 -0
- package/dist/nodes/cmd/cmd.js +109 -0
- package/dist/nodes/cmd/cmd.js.map +1 -0
- package/dist/nodes/cmd/modules/types.js +3 -0
- package/dist/nodes/cmd/modules/types.js.map +1 -0
- package/dist/nodes/cmd/shared/types.js +3 -0
- package/dist/nodes/cmd/shared/types.js.map +1 -0
- package/dist/nodes/listen/listen.html +60 -0
- package/dist/nodes/listen/listen.js +102 -0
- package/dist/nodes/listen/listen.js.map +1 -0
- package/dist/nodes/listen/modules/types.js +3 -0
- package/dist/nodes/listen/modules/types.js.map +1 -0
- package/dist/nodes/listen/shared/types.js +3 -0
- package/dist/nodes/listen/shared/types.js.map +1 -0
- package/dist/nodes/owa-server/modules/types.js +3 -0
- package/dist/nodes/owa-server/modules/types.js.map +1 -0
- package/dist/nodes/owa-server/owa-server.html +36 -0
- package/dist/nodes/owa-server/owa-server.js +83 -0
- package/dist/nodes/owa-server/owa-server.js.map +1 -0
- package/dist/nodes/owa-server/shared/types.js +3 -0
- package/dist/nodes/owa-server/shared/types.js.map +1 -0
- package/dist/nodes/shared/common.js +9 -0
- package/dist/nodes/shared/common.js.map +1 -0
- package/dist/nodes/shared/http.js +40 -0
- package/dist/nodes/shared/http.js.map +1 -0
- package/dist/nodes/shared/types.js +7 -0
- package/dist/nodes/shared/types.js.map +1 -0
- package/package.json +74 -0
- package/yarn.lock +5870 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Alex Kaul
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @open-wa/node-red
|
|
2
|
+
|
|
3
|
+
Official @open-wa node-red integration.
|
|
4
|
+
|
|
5
|
+
Part of the [@open-wa v5 monorepo](https://github.com/open-wa/wa-automate-nodejs).
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
`@open-wa/node-red` provides Node-RED nodes for connecting flows to a remote open-wa Easy API session. The package registers three Node-RED node types from `package.json`: `owa-server`, `cmd`, and `listen`.
|
|
10
|
+
|
|
11
|
+
Use this integration when Node-RED should call open-wa commands or react to open-wa listener events through a configured Easy API server connection.
|
|
12
|
+
|
|
13
|
+
Legacy compatibility note: this integration still uses the `@open-wa/socket-client` surface for backward compatibility, but the active v5 runtime is backed by HTTP RPC + SSE rather than direct Socket.IO. Do not depend on `SocketManager` from `@open-wa/api` when integrating with current releases.
|
|
14
|
+
|
|
15
|
+
## Node types
|
|
16
|
+
|
|
17
|
+
| Node type | Source-visible behavior |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `owa-server` | Configuration node that stores `name`, `url`, and `key`, creates a `SocketClient`, exposes its socket-like connection object, and stores the client in Node-RED global context. It emits and reports connected, disconnected, and connect error status changes. |
|
|
20
|
+
| `cmd` | Executes a selected open-wa command against the configured server. It loads command metadata from `/meta/basic/commands`, accepts `method` and `args` from the incoming message or node config, calls `server.client.ask(method, args)`, and supports a timeout in seconds. |
|
|
21
|
+
| `listen` | Registers an event listener against the configured server. It loads listener names from `/meta/basic/listeners`, calls `client.listen(listener, listenerFn)`, sends received event data as `msg.payload`, and stops the listener on node close. |
|
|
22
|
+
|
|
23
|
+
## Configuration fields
|
|
24
|
+
|
|
25
|
+
The visible editor templates and runtime source define these fields.
|
|
26
|
+
|
|
27
|
+
### `owa-server`
|
|
28
|
+
|
|
29
|
+
- `name`: Node-RED display name and status payload socket ID.
|
|
30
|
+
- `url`: Base URL for the remote open-wa Easy API server.
|
|
31
|
+
- `key`: Optional API key sent as `X-API-Key` when loading command and listener metadata and passed to `SocketClient`.
|
|
32
|
+
|
|
33
|
+
### `cmd`
|
|
34
|
+
|
|
35
|
+
- `server`: Reference to an `owa-server` config node.
|
|
36
|
+
- `method`: Command method to call when the incoming message does not provide `msg.method`.
|
|
37
|
+
- `args`: JSON-like command arguments merged with object-like `msg.payload` values when present.
|
|
38
|
+
- `name`: Node-RED display name.
|
|
39
|
+
- `timeout`: Timeout in seconds. The runtime treats `-1` as no timeout and falls back to 30 seconds when parsing fails.
|
|
40
|
+
|
|
41
|
+
### `listen`
|
|
42
|
+
|
|
43
|
+
- `server`: Reference to an `owa-server` config node.
|
|
44
|
+
- `listener`: Listener name to register.
|
|
45
|
+
- `name`: Node-RED display name.
|
|
46
|
+
|
|
47
|
+
## Runtime behavior
|
|
48
|
+
|
|
49
|
+
- `owa-server` constructs `new SocketClient(url, key)`, stores it under the node ID in the global `CLIENT_STORE`, and removes it on disconnect or node removal.
|
|
50
|
+
- `cmd` uses `/meta/basic/commands` to populate command options in the editor. At runtime it prefers `msg.method` and `msg.args`, otherwise it parses configured args and `msg.payload`, then sends the result with `client.ask`.
|
|
51
|
+
- `cmd` reports `Executing..`, `Done`, timeout, waiting, and missing server states through Node-RED node status.
|
|
52
|
+
- `listen` uses `/meta/basic/listeners` to populate listener options in the editor. It registers once per node instance, forwards listener messages as `payload`, reports connection status, and calls `stopListener` on close.
|
|
53
|
+
|
|
54
|
+
## Development
|
|
55
|
+
|
|
56
|
+
- `pnpm --filter @open-wa/node-red add-node`
|
|
57
|
+
- `pnpm --filter @open-wa/node-red copy`
|
|
58
|
+
- `pnpm --filter @open-wa/node-red build:editor`
|
|
59
|
+
- `pnpm --filter @open-wa/node-red build:runtime`
|
|
60
|
+
- `pnpm --filter @open-wa/node-red build`
|
|
61
|
+
- `pnpm --filter @open-wa/node-red dev`
|
|
62
|
+
- `pnpm --filter @open-wa/node-red lint`
|
|
63
|
+
- `pnpm --filter @open-wa/node-red lint:fix`
|
|
64
|
+
- `pnpm --filter @open-wa/node-red test`
|
|
65
|
+
- `pnpm --filter @open-wa/node-red test:watch`
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
See the [docs site](https://docs.openwa.dev).
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
[H-DNH V1.0](https://github.com/open-wa/wa-automate-nodejs/blob/main/LICENSE.md) - Hippocratic + Do Not Harm
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
(function () {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
RED.nodes.registerType("cmd", {
|
|
6
|
+
category: "wa",
|
|
7
|
+
color: "#DEBD5C",
|
|
8
|
+
defaults: {
|
|
9
|
+
name: { value: "" },
|
|
10
|
+
server: { value: "", type: "owa-server" },
|
|
11
|
+
method: { value: "" },
|
|
12
|
+
args: { value: "" },
|
|
13
|
+
timeout: { value: "-1", validate: RED.validators.number(true) }
|
|
14
|
+
},
|
|
15
|
+
inputs: 1,
|
|
16
|
+
outputs: 1,
|
|
17
|
+
icon: "feed.svg",
|
|
18
|
+
paletteLabel: "Command",
|
|
19
|
+
label: function () {
|
|
20
|
+
return this.name || this.method || "cmd";
|
|
21
|
+
},
|
|
22
|
+
oneditprepare: function () {
|
|
23
|
+
var _this = this;
|
|
24
|
+
$("#node-input-args").typedInput({
|
|
25
|
+
default: "json",
|
|
26
|
+
types: ["json"]
|
|
27
|
+
});
|
|
28
|
+
$.getJSON('node_red_init_call', function (data) {
|
|
29
|
+
//... does stuff with data
|
|
30
|
+
if (typeof data == "string")
|
|
31
|
+
return $("#node-input-method").append(new Option(data, data, undefined, true));
|
|
32
|
+
$("#node-input-method")
|
|
33
|
+
.find('option')
|
|
34
|
+
.remove();
|
|
35
|
+
Object.keys(data).map(function (method) {
|
|
36
|
+
return $("#node-input-method").append(new Option(method, method, undefined, method === _this.method));
|
|
37
|
+
});
|
|
38
|
+
//@ts-ignore
|
|
39
|
+
$("#node-input-method").on('change', function (event) { return $('#node-input-args').typedInput('value', JSON.stringify(data[event.target.value])); });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
})();
|
|
45
|
+
</script>
|
|
46
|
+
<script type="text/html" data-template-name="cmd">
|
|
47
|
+
<div class="form-row">
|
|
48
|
+
<label for="node-input-server"><i class="fa fa-globe"></i>Server</label>
|
|
49
|
+
<input type="text" id="node-input-server" placeholder="Server">
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<div class="form-row">
|
|
53
|
+
<label for="node-input-method"
|
|
54
|
+
><i class="fa fa-globe"></i> Method</label>
|
|
55
|
+
<select type="text" id="node-input-method" style="width:70%;">
|
|
56
|
+
<option selected disabled hidden>Choose an Option</option>
|
|
57
|
+
</select>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div class="form-row">
|
|
61
|
+
<label for="node-input-args"><i class="icon-tag"></i> Args</label>
|
|
62
|
+
<input type="text" id="node-input-args" placeholder="Args">
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<div class="form-row">
|
|
66
|
+
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
67
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<div class="form-row">
|
|
71
|
+
<label for="node-input-timeout"><span data-i18n="exec.label.timeout"><i class="icon-tag"></i> Timeout</span></label>
|
|
72
|
+
<input type="text" id="node-input-timeout" placeholder="30" style="width: 70px; margin-right: 5px;"><span data-i18n="inject.seconds"></span>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
</script>
|
|
76
|
+
<script type="text/html" data-help-name="cmd">
|
|
77
|
+
<h1>Execute a command for your remote instance to run.</h1>
|
|
78
|
+
<p>Make sure to enable socket mode on your EASY API session by setting the --socket flag</p>
|
|
79
|
+
</script>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const http_1 = require("../shared/http");
|
|
3
|
+
async function fetchCommandOptions(server) {
|
|
4
|
+
const commands = await (0, http_1.getJson)(new URL('/meta/basic/commands', server.url), server.key ? { 'X-API-Key': server.key } : undefined);
|
|
5
|
+
return commands.reduce((acc, command) => {
|
|
6
|
+
if (!command.method)
|
|
7
|
+
return acc;
|
|
8
|
+
acc[command.method] = (command.parameterOrder || []).reduce((shape, key) => {
|
|
9
|
+
shape[key] = undefined;
|
|
10
|
+
return shape;
|
|
11
|
+
}, {});
|
|
12
|
+
return acc;
|
|
13
|
+
}, {});
|
|
14
|
+
}
|
|
15
|
+
function tryParseJSONObject(jsonString) {
|
|
16
|
+
if (typeof jsonString === "object")
|
|
17
|
+
return jsonString;
|
|
18
|
+
try {
|
|
19
|
+
//@ts-ignore
|
|
20
|
+
var o = JSON.parse(jsonString);
|
|
21
|
+
// Handle non-exception-throwing cases:
|
|
22
|
+
// Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,
|
|
23
|
+
// but... JSON.parse(null) returns null, and typeof null === "object",
|
|
24
|
+
// so we must check for that, too. Thankfully, null is falsey, so this suffices:
|
|
25
|
+
if (o && typeof o === "object") {
|
|
26
|
+
return o;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e) { }
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
;
|
|
33
|
+
const nodeInit = (RED) => {
|
|
34
|
+
function CmdNodeConstructor(config) {
|
|
35
|
+
RED.nodes.createNode(this, config);
|
|
36
|
+
this.name = config.name;
|
|
37
|
+
this.method = config.method;
|
|
38
|
+
this.args = config.args;
|
|
39
|
+
this.timeout = (config.timeout === "-1") ? -1 : parseFloat(config.timeout || "30") * 1000;
|
|
40
|
+
if (isNaN(this.timeout)) {
|
|
41
|
+
this.timeout = 30000;
|
|
42
|
+
}
|
|
43
|
+
RED.httpAdmin.get("/node_red_init_call", (req, res) => {
|
|
44
|
+
var _a;
|
|
45
|
+
this.server = RED.nodes.getNode(config.server);
|
|
46
|
+
if (!((_a = this.server) === null || _a === void 0 ? void 0 : _a.client.socket)) {
|
|
47
|
+
res.status(400).json({ error: "Please set a server first!" });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
void fetchCommandOptions(this.server)
|
|
51
|
+
.then((data) => res.json(data))
|
|
52
|
+
.catch((error) => {
|
|
53
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
54
|
+
res.status(502).json({ error: message });
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
this.on("input", (msg, send, done) => {
|
|
58
|
+
const m = msg;
|
|
59
|
+
const method = m.method || this.method;
|
|
60
|
+
let argmnts = m.args || {
|
|
61
|
+
...(tryParseJSONObject(this.args) || {}),
|
|
62
|
+
...(tryParseJSONObject(msg.payload) || {}),
|
|
63
|
+
};
|
|
64
|
+
argmnts = tryParseJSONObject(argmnts) || argmnts;
|
|
65
|
+
let _t;
|
|
66
|
+
if (config.server)
|
|
67
|
+
this.server = RED.nodes.getNode(config.server);
|
|
68
|
+
const executeCommand = () => { var _a; return (_a = this.server) === null || _a === void 0 ? void 0 : _a.client.ask(method, argmnts); };
|
|
69
|
+
const timeoutPomise = this.timeout === -1 ? false : new Promise((res) => {
|
|
70
|
+
_t = setTimeout(() => {
|
|
71
|
+
res('TIMEOUT');
|
|
72
|
+
}, this.timeout);
|
|
73
|
+
});
|
|
74
|
+
const proms = timeoutPomise ? () => Promise.race([executeCommand(), timeoutPomise]) : () => executeCommand();
|
|
75
|
+
const promWithHandler = () => proms().then((payload) => {
|
|
76
|
+
if (_t)
|
|
77
|
+
clearTimeout(_t);
|
|
78
|
+
if (payload === "TIMEOUT")
|
|
79
|
+
this.status({ fill: 'red', shape: 'ring', text: `Timed out. Took longer than ${(this.timeout || 1000) / 1000} seconds` });
|
|
80
|
+
else {
|
|
81
|
+
this.status({ fill: 'green', shape: 'dot', text: 'Done' });
|
|
82
|
+
send({
|
|
83
|
+
payload
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (this.server && this.server.client) {
|
|
88
|
+
this.status({ fill: 'yellow', shape: 'ring', text: 'Executing..' });
|
|
89
|
+
if (this.server.clientSocket.connected) {
|
|
90
|
+
promWithHandler();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.status({ fill: 'red', shape: 'ring', text: 'Waiting for socket connection..' });
|
|
94
|
+
this.server.addListener("connected", () => {
|
|
95
|
+
promWithHandler();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// No config node configured
|
|
101
|
+
this.error("No Server!");
|
|
102
|
+
}
|
|
103
|
+
done();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
RED.nodes.registerType("cmd", CmdNodeConstructor);
|
|
107
|
+
};
|
|
108
|
+
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AAM,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC;oBACvC,eAAe,EAAE,CAAA;gBACnB,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC;oBACrF,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,GAAG,EAAE;wBACxC,eAAe,EAAE,CAAA;oBACnB,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,4BAA4B;gBAC5B,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;YAC1B,CAAC;YAED,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,iBAAS,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/cmd/modules/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/cmd/shared/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
(function () {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
RED.nodes.registerType("listen", {
|
|
6
|
+
category: "wa",
|
|
7
|
+
paletteLabel: "Listen",
|
|
8
|
+
color: "#AAAA66",
|
|
9
|
+
defaults: {
|
|
10
|
+
name: { value: "" },
|
|
11
|
+
server: { value: "", type: "owa-server" },
|
|
12
|
+
listener: { value: "onMessage" },
|
|
13
|
+
},
|
|
14
|
+
outputs: 1,
|
|
15
|
+
icon: "arrow-in.svg",
|
|
16
|
+
label: function () {
|
|
17
|
+
return this.name || this.listener || "listen";
|
|
18
|
+
},
|
|
19
|
+
oneditprepare: function () {
|
|
20
|
+
var _this = this;
|
|
21
|
+
try {
|
|
22
|
+
$.getJSON('node_red_init_listen', function (options) {
|
|
23
|
+
options.map(function (option) {
|
|
24
|
+
return $("#node-input-listener").append(new Option(option, option, undefined, option === _this.listener));
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.log("🚀 ~ file: index.ts ~ line 30 ~ error", error);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
})();
|
|
35
|
+
</script>
|
|
36
|
+
<script type="text/html" data-template-name="listen">
|
|
37
|
+
<div class="form-row">
|
|
38
|
+
<label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
|
|
39
|
+
<input type="text" id="node-input-server" placeholder="Server" />
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div class="form-row">
|
|
43
|
+
<label for="node-input-listener"
|
|
44
|
+
><i class="fa fa-globe"></i> Listener</label>
|
|
45
|
+
<select type="text" id="node-input-listener" style="width:70%;">
|
|
46
|
+
<option selected disabled hidden>Choose an Option</option>
|
|
47
|
+
</select>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<div class="form-row">
|
|
51
|
+
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
52
|
+
<input type="text" id="node-input-name" placeholder="Name" />
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<script type="text/html" data-help-name="listen">
|
|
58
|
+
<h1>Listen to events.</h1>
|
|
59
|
+
<p>Make sure to enable socket mode on your EASY API session by setting the --socket flag</p>
|
|
60
|
+
</script>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const types_1 = require("../shared/types");
|
|
3
|
+
const http_1 = require("../shared/http");
|
|
4
|
+
async function fetchListenerOptions(server) {
|
|
5
|
+
const listeners = await (0, http_1.getJson)(new URL('/meta/basic/listeners', server.url), server.key ? { 'X-API-Key': server.key } : undefined);
|
|
6
|
+
return listeners
|
|
7
|
+
.map((listener) => listener.legacyName)
|
|
8
|
+
.filter((listenerName) => Boolean(listenerName));
|
|
9
|
+
}
|
|
10
|
+
const nodeInit = (RED) => {
|
|
11
|
+
function ListenNodeConstructor(config) {
|
|
12
|
+
var _a;
|
|
13
|
+
RED.nodes.createNode(this, config);
|
|
14
|
+
this.name = config.name;
|
|
15
|
+
this.listener = config.listener;
|
|
16
|
+
let listenerSet = false;
|
|
17
|
+
this.listenerFn = (message) => {
|
|
18
|
+
this.send({
|
|
19
|
+
payload: message
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
if (config.server) {
|
|
23
|
+
this.server = RED.nodes.getNode(config.server);
|
|
24
|
+
const client = () => getSocket(this.context().global, config.server);
|
|
25
|
+
try {
|
|
26
|
+
RED.httpAdmin.get("/node_red_init_listen", (req, res) => {
|
|
27
|
+
var _a;
|
|
28
|
+
if (!((_a = this.server) === null || _a === void 0 ? void 0 : _a.client.socket)) {
|
|
29
|
+
res.status(400).json({ error: "Please set a server first!" });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
void fetchListenerOptions(this.server)
|
|
33
|
+
.then((data) => {
|
|
34
|
+
res.json(data);
|
|
35
|
+
})
|
|
36
|
+
.catch((error) => {
|
|
37
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
+
res.status(502).json({ error: message });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.log(error);
|
|
44
|
+
}
|
|
45
|
+
const registerCallback = () => {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
if (listenerSet)
|
|
48
|
+
return;
|
|
49
|
+
if (this.callbackId)
|
|
50
|
+
(_a = client()) === null || _a === void 0 ? void 0 : _a.stopListener(this.listener, this.callbackId);
|
|
51
|
+
(_b = client()) === null || _b === void 0 ? void 0 : _b.listen(this.listener, this.listenerFn).then(callbackId => {
|
|
52
|
+
this.callbackId = callbackId;
|
|
53
|
+
listenerSet = true;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
if (config.server)
|
|
57
|
+
if (this.server) {
|
|
58
|
+
if ((_a = client()) === null || _a === void 0 ? void 0 : _a.socket.connected) {
|
|
59
|
+
registerCallback();
|
|
60
|
+
this.status({ fill: 'green', shape: 'dot', text: 'listening' });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.status({ fill: 'red', shape: 'ring', text: 'not connected' });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// No config node configured
|
|
68
|
+
this.status({ fill: 'red', shape: 'ring', text: 'No Server!' });
|
|
69
|
+
this.error("No Server!");
|
|
70
|
+
}
|
|
71
|
+
this.server.addListener("connected", () => {
|
|
72
|
+
this.status({ fill: 'green', shape: 'dot', text: 'listening' });
|
|
73
|
+
registerCallback();
|
|
74
|
+
});
|
|
75
|
+
this.server.addListener("disconnect", () => {
|
|
76
|
+
this.status({ fill: 'red', shape: 'ring', text: 'Disconnected!' });
|
|
77
|
+
});
|
|
78
|
+
this.server.addListener("connect_error", () => {
|
|
79
|
+
this.status({ fill: 'red', shape: 'ring', text: 'Disconnected!' });
|
|
80
|
+
});
|
|
81
|
+
this.on('close', (done) => {
|
|
82
|
+
var _a;
|
|
83
|
+
listenerSet = false;
|
|
84
|
+
(_a = client()) === null || _a === void 0 ? void 0 : _a.stopListener(this.listener, this.callbackId);
|
|
85
|
+
this.status({});
|
|
86
|
+
done();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
RED.nodes.registerType("listen", ListenNodeConstructor);
|
|
91
|
+
};
|
|
92
|
+
const getSocket = (globalContext, socketId) => {
|
|
93
|
+
let store = globalContext.get(types_1.CLIENT_STORE);
|
|
94
|
+
if (!store) {
|
|
95
|
+
//create global client store
|
|
96
|
+
globalContext.set(types_1.CLIENT_STORE, {});
|
|
97
|
+
}
|
|
98
|
+
store = globalContext.get(types_1.CLIENT_STORE);
|
|
99
|
+
return store[socketId];
|
|
100
|
+
};
|
|
101
|
+
module.exports = nodeInit;
|
|
102
|
+
//# sourceMappingURL=listen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listen.js","sourceRoot":"","sources":["../../../src/nodes/listen/listen.ts"],"names":[],"mappings":";AAGA,2CAA4D;AAC5D,yCAAyC;AAGzC,KAAK,UAAU,oBAAoB,CAAC,MAAqB;IACvD,MAAM,SAAS,GAAG,MAAM,IAAA,cAAO,EAE3B,IAAI,GAAG,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAExG,OAAO,SAAS;SACb,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC;SACtC,MAAM,CAAC,CAAC,YAAY,EAA0B,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,QAAQ,GAAoB,CAAC,GAAG,EAAQ,EAAE;IAC9C,SAAS,qBAAqB,CAE5B,MAAqB;;QAErB,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,CAAC,OAAgB,EAAE,EAAE;YACrC,IAAI,CAAC,IAAI,CAAC;gBACR,OAAO,EAAE,OAAO;a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Aa,CAAC,GAAG,CAAC,oBAAY,CAAgB,CAAA;IACtD,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC,CAAA;AAED,iBAAS,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/listen/modules/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/listen/shared/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/nodes/owa-server/modules/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
(function () {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
RED.nodes.registerType("owa-server", {
|
|
6
|
+
category: "config",
|
|
7
|
+
defaults: {
|
|
8
|
+
name: { value: "" },
|
|
9
|
+
url: { value: "" },
|
|
10
|
+
key: { value: "" }
|
|
11
|
+
},
|
|
12
|
+
label: function () {
|
|
13
|
+
return this.name || "owa server";
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
})();
|
|
18
|
+
</script>
|
|
19
|
+
<script type="text/html" data-template-name="owa-server">
|
|
20
|
+
<div class="form-row">
|
|
21
|
+
<label for="node-config-input-name"><i class="icon-tag"></i> Name</label>
|
|
22
|
+
<input type="text" id="node-config-input-name" placeholder="Name">
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-config-input-url"><i class="icon-tag"></i> URL</label>
|
|
26
|
+
<input type="text" id="node-config-input-url" placeholder="Url">
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-config-input-key"><i class="icon-tag"></i> Key</label>
|
|
30
|
+
<input type="text" id="node-config-input-key" placeholder="Key">
|
|
31
|
+
</div>
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script type="text/html" data-help-name="owa-server">
|
|
35
|
+
<p>Define a remote socket-enabled (use the --socket flag) session.</p>
|
|
36
|
+
</script>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const socket_client_1 = require("@open-wa/socket-client");
|
|
3
|
+
const types_1 = require("../shared/types");
|
|
4
|
+
const nodeInit = async (RED) => {
|
|
5
|
+
function OwaServerNodeConstructor(config) {
|
|
6
|
+
/**
|
|
7
|
+
* Create global client store.
|
|
8
|
+
*
|
|
9
|
+
* Legacy note: the surrounding Node-RED API still uses "socket" naming for
|
|
10
|
+
* backward compatibility, but the v5 runtime is backed by the remote client
|
|
11
|
+
* transport wrapper instead of @open-wa/api SocketManager.
|
|
12
|
+
*/
|
|
13
|
+
RED.nodes.createNode(this, config);
|
|
14
|
+
this.name = config.name;
|
|
15
|
+
this.url = config.url;
|
|
16
|
+
this.key = config.key;
|
|
17
|
+
this.client = new socket_client_1.SocketClient(this.url, this.key);
|
|
18
|
+
this.clientSocket = this.client.socket;
|
|
19
|
+
addSocketClientToGlobalStore(this.context().global, this.id, this.client);
|
|
20
|
+
this.clientSocket.on('connect', () => {
|
|
21
|
+
this.emit('connected');
|
|
22
|
+
this.send({ payload: { socketId: this.name, status: 'connected' } });
|
|
23
|
+
this.status({ fill: "green", shape: "dot", text: "connected" });
|
|
24
|
+
});
|
|
25
|
+
this.clientSocket.on('disconnect', () => {
|
|
26
|
+
this.emit('disconnect');
|
|
27
|
+
removeSocketClientFromGlobalStore(this.context().global, this.id);
|
|
28
|
+
this.send({ payload: { socketId: this.name, status: 'disconnected' } });
|
|
29
|
+
this.status({ fill: 'red', shape: 'ring', text: 'disconnected' });
|
|
30
|
+
});
|
|
31
|
+
this.clientSocket.on('connect_error', (err) => {
|
|
32
|
+
this.emit('connect_error');
|
|
33
|
+
if (err) {
|
|
34
|
+
this.status({ fill: 'red', shape: 'ring', text: 'disconnected' });
|
|
35
|
+
this.send({ payload: { socketId: this.name, status: 'disconnected' } });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
this.on('close', (removed, done) => {
|
|
39
|
+
this.clientSocket.disconnect();
|
|
40
|
+
this.status({});
|
|
41
|
+
if (removed) {
|
|
42
|
+
removeSocketClientFromGlobalStore(this.context().global, this.id);
|
|
43
|
+
}
|
|
44
|
+
done();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
RED.nodes.registerType("owa-server", OwaServerNodeConstructor);
|
|
48
|
+
};
|
|
49
|
+
const getSocketStore = (globalContext) => {
|
|
50
|
+
let store = globalContext.get(types_1.CLIENT_STORE);
|
|
51
|
+
if (!store) {
|
|
52
|
+
//create global client store
|
|
53
|
+
globalContext.set(types_1.CLIENT_STORE, {});
|
|
54
|
+
}
|
|
55
|
+
store = globalContext.get(types_1.CLIENT_STORE);
|
|
56
|
+
return store;
|
|
57
|
+
};
|
|
58
|
+
const addSocketClientToGlobalStore = (globalContext, socketClientId, socketClient) => {
|
|
59
|
+
const store = getSocketStore(globalContext);
|
|
60
|
+
if (store[socketClientId]) {
|
|
61
|
+
//client already exists
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
globalContext.set(types_1.CLIENT_STORE, {
|
|
65
|
+
...store,
|
|
66
|
+
[socketClientId]: socketClient
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const removeSocketClientFromGlobalStore = (globalContext, socketClientId) => {
|
|
71
|
+
const store = getSocketStore(globalContext);
|
|
72
|
+
if (store[socketClientId]) {
|
|
73
|
+
delete store[socketClientId];
|
|
74
|
+
globalContext.set(types_1.CLIENT_STORE, {
|
|
75
|
+
...store
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
//client does not exist
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
module.exports = nodeInit;
|
|
83
|
+
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