@5minds/node-red-contrib-processcube 1.5.2-feature-4b06ce-m3644zlp → 1.5.2-feature-fcaf4b-m3hagv0j
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/package.json +1 -1
- package/processcube-engine-config.js +30 -7
package/package.json
CHANGED
@@ -7,12 +7,14 @@ module.exports = function (RED) {
|
|
7
7
|
RED.nodes.createNode(this, n);
|
8
8
|
const node = this;
|
9
9
|
const identityChangedCallbacks = [];
|
10
|
-
this.url = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
|
11
10
|
this.identity = null;
|
12
11
|
|
13
12
|
this.credentials.clientId = RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node);
|
14
13
|
this.credentials.clientSecret = RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node);
|
15
14
|
|
15
|
+
// set the engine url
|
16
|
+
const stopRefreshing = periodicallyRefreshEngineClient(this, n, 10000);
|
17
|
+
|
16
18
|
this.registerOnIdentityChanged = function (callback) {
|
17
19
|
identityChangedCallbacks.push(callback);
|
18
20
|
};
|
@@ -34,6 +36,32 @@ module.exports = function (RED) {
|
|
34
36
|
}
|
35
37
|
};
|
36
38
|
|
39
|
+
function periodicallyRefreshEngineClient(node, n, intervalMs) {
|
40
|
+
function refreshUrl() {
|
41
|
+
const newUrl = RED.util.evaluateNodeProperty(n.url, n.urlType, node);
|
42
|
+
|
43
|
+
if (node.url == newUrl) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
node.url = newUrl;
|
48
|
+
if (node.credentials.clientId && node.credentials.clientSecret) {
|
49
|
+
this.engineClient.dispose();
|
50
|
+
node.engineClient = new engine_client.EngineClient(node.url, () =>
|
51
|
+
getFreshIdentity(node.url, node)
|
52
|
+
);
|
53
|
+
} else {
|
54
|
+
this.engineClient.dispose();
|
55
|
+
node.engineClient = new engine_client.EngineClient(node.url);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
refreshUrl();
|
60
|
+
const intervalId = setInterval(refreshUrl, intervalMs);
|
61
|
+
|
62
|
+
return () => clearInterval(intervalId);
|
63
|
+
}
|
64
|
+
|
37
65
|
async function getFreshIdentity(url, node) {
|
38
66
|
try {
|
39
67
|
if (
|
@@ -85,16 +113,11 @@ module.exports = function (RED) {
|
|
85
113
|
|
86
114
|
node.on('close', async () => {
|
87
115
|
if (this.engineClient) {
|
116
|
+
stopRefreshing();
|
88
117
|
this.engineClient.dispose();
|
89
118
|
this.engineClient = null;
|
90
119
|
}
|
91
120
|
});
|
92
|
-
|
93
|
-
if (this.credentials.clientId && this.credentials.clientSecret) {
|
94
|
-
this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url, node));
|
95
|
-
} else {
|
96
|
-
this.engineClient = new engine_client.EngineClient(this.url);
|
97
|
-
}
|
98
121
|
}
|
99
122
|
RED.nodes.registerType('processcube-engine-config', ProcessCubeEngineNode, {
|
100
123
|
credentials: {
|