-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendevent-finished-listener.js
41 lines (35 loc) · 1.21 KB
/
endevent-finished-listener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = function (RED) {
function EndEventFinishedListener(config) {
RED.nodes.createNode(this, config);
var node = this;
node.engine = RED.nodes.getNode(config.engine);
let subscription = null;
const register = async () => {
const client = node.engine.engineClient;
if (!client) {
node.error('No engine configured.', {});
return;
}
try {
subscription = await client.events.onEndEventFinished((endEventFinished) => {
node.send({
payload: endEventFinished,
});
});
} catch (error) {
node.error(error, {});
}
node.on('close', async () => {
if (node.engine && node.engine.engineClient && client) {
client.events.removeSubscription(subscription);
}
});
};
if (node.engine) {
register().catch((error) => {
node.error(error, {});
});
}
}
RED.nodes.registerType('endevent-finished-listener', EndEventFinishedListener);
};