node-red-contrib-mobius-flow-base 3.1.7 → 3.2.0
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/dist/engine-api-calls.d.ts +41 -34
- package/dist/engine-api-calls.js +341 -259
- package/dist/engine-api-client.d.ts +0 -1
- package/dist/engine-api-client.js +1 -1
- package/dist/nodes/mobius-connection-interface.d.ts +1 -1
- package/dist/nodes/mobius-connection.js +2 -2
- package/dist/nodes/mobius-send-bcmd.js +22 -3
- package/package.json +1 -1
|
@@ -1,52 +1,59 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
+
type Callback = (err: unknown | null, resp?: any) => void;
|
|
2
3
|
interface EngineApiCallsInterace {
|
|
3
4
|
setApiClient: (apiClient: AxiosInstance) => void;
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
setLoggedIn: (loggedIn: boolean) => void;
|
|
6
|
+
discover: (uri: string, callback: Callback) => void;
|
|
7
|
+
writeResource: (uri: string, value: number | string | boolean, priority: number, callback: Callback) => void;
|
|
6
8
|
writeMultiResource: (uri: string, updates: {
|
|
7
9
|
r: string;
|
|
8
10
|
p: number;
|
|
9
11
|
v: number | string | boolean;
|
|
10
|
-
}[], callback:
|
|
11
|
-
clearResource: (uri: string, priority: number, callback:
|
|
12
|
-
readResource: (uri: string, callback:
|
|
13
|
-
readObject: (uri: string, callback:
|
|
14
|
-
sendBroadcastCommand: (cid: string, commandData: any) => void;
|
|
15
|
-
sendDirectCommand: (uri: string, cid: string, commandData: any, timeout: number, callback:
|
|
16
|
-
getServiceConfig: (uri: string, callback:
|
|
17
|
-
updateObject: (uri: string, config: any, callback:
|
|
18
|
-
filterObjectsByRIDValue: (uri: string, pids: string[], rid: string, limit: number, func: (v: string | number | boolean) => boolean, callback:
|
|
19
|
-
getHubId: (callback:
|
|
20
|
-
getNodeConfig: (uri: string, callback:
|
|
21
|
-
changeAdminPassword: (password: string, callback:
|
|
22
|
-
getNodeConfigTree: (hid: string, callback:
|
|
23
|
-
getProfileByPid: (hid: string, pid: string, callback:
|
|
24
|
-
getAllObjectProfiles: (hid: string, callback:
|
|
12
|
+
}[], callback: Callback) => void;
|
|
13
|
+
clearResource: (uri: string, priority: number, callback: Callback) => void;
|
|
14
|
+
readResource: (uri: string, callback: Callback) => void;
|
|
15
|
+
readObject: (uri: string, callback: Callback) => void;
|
|
16
|
+
sendBroadcastCommand: (cid: string, commandData: any, callback: Callback) => void;
|
|
17
|
+
sendDirectCommand: (uri: string, cid: string, commandData: any, timeout: number, callback: Callback) => void;
|
|
18
|
+
getServiceConfig: (uri: string, callback: Callback) => void;
|
|
19
|
+
updateObject: (uri: string, config: any, callback: Callback) => void;
|
|
20
|
+
filterObjectsByRIDValue: (uri: string, pids: string[], rid: string, limit: number, func: (v: string | number | boolean) => boolean, callback: Callback) => void;
|
|
21
|
+
getHubId: (callback: Callback) => void;
|
|
22
|
+
getNodeConfig: (uri: string, callback: Callback) => void;
|
|
23
|
+
changeAdminPassword: (password: string, callback: Callback) => void;
|
|
24
|
+
getNodeConfigTree: (hid: string, callback: Callback) => void;
|
|
25
|
+
getProfileByPid: (hid: string, pid: string, callback: Callback) => void;
|
|
26
|
+
getAllObjectProfiles: (hid: string, callback: Callback) => void;
|
|
25
27
|
}
|
|
26
28
|
export declare class EngineApiCalls implements EngineApiCallsInterace {
|
|
27
29
|
private apiClient;
|
|
30
|
+
loggedIn: boolean;
|
|
31
|
+
private messageQueue;
|
|
28
32
|
constructor();
|
|
33
|
+
private startQueueInterval;
|
|
34
|
+
stopQueueInterval: () => void;
|
|
29
35
|
setApiClient: (apiClient: AxiosInstance) => void;
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
setLoggedIn: (loggedIn: boolean) => void;
|
|
37
|
+
discover: (uri: string, callback: Callback) => Promise<void>;
|
|
38
|
+
writeResource: (uri: string, value: number | string | boolean, priority: number, callback: Callback) => Promise<void>;
|
|
32
39
|
writeMultiResource: (uri: string, updates: {
|
|
33
40
|
r: string;
|
|
34
41
|
p: number;
|
|
35
42
|
v: number | string | boolean;
|
|
36
|
-
}[], callback:
|
|
37
|
-
clearResource: (uri: string, priority: number, callback:
|
|
38
|
-
readResource: (uri: string, callback:
|
|
39
|
-
readObject: (uri: string, callback:
|
|
40
|
-
sendBroadcastCommand: (cid: string, commandData: any) => Promise<void>;
|
|
41
|
-
sendDirectCommand: (uri: string, cid: string, commandData: any, timeout: number, callback:
|
|
42
|
-
getServiceConfig: (uri: string, callback:
|
|
43
|
-
updateObject: (uri: string, config: any, callback:
|
|
44
|
-
filterObjectsByRIDValue: (uri: string, pids: string[], rid: string, limit: number,
|
|
45
|
-
getHubId: (callback:
|
|
46
|
-
getNodeConfig: (uri: string, callback:
|
|
47
|
-
changeAdminPassword: (password: string, callback:
|
|
48
|
-
getNodeConfigTree: (hid: string, callback:
|
|
49
|
-
getProfileByPid: (hid: string, pid: string, callback:
|
|
50
|
-
getAllObjectProfiles: (hid: string, callback:
|
|
43
|
+
}[], callback: Callback) => Promise<void>;
|
|
44
|
+
clearResource: (uri: string, priority: number, callback: Callback) => Promise<void>;
|
|
45
|
+
readResource: (uri: string, callback: Callback) => Promise<void>;
|
|
46
|
+
readObject: (uri: string, callback: Callback) => Promise<void>;
|
|
47
|
+
sendBroadcastCommand: (cid: string, commandData: any, callback: Callback) => Promise<void>;
|
|
48
|
+
sendDirectCommand: (uri: string, cid: string, commandData: any, timeout: number, callback: Callback) => Promise<void>;
|
|
49
|
+
getServiceConfig: (uri: string, callback: Callback) => Promise<void>;
|
|
50
|
+
updateObject: (uri: string, config: any, callback: Callback) => Promise<void>;
|
|
51
|
+
filterObjectsByRIDValue: (uri: string, pids: string[], rid: string, limit: number, processFunc: (v: string | number | boolean) => boolean, callback: Callback) => Promise<void>;
|
|
52
|
+
getHubId: (callback: Callback) => Promise<void>;
|
|
53
|
+
getNodeConfig: (uri: string, callback: Callback) => Promise<void>;
|
|
54
|
+
changeAdminPassword: (password: string, callback: Callback) => Promise<void>;
|
|
55
|
+
getNodeConfigTree: (hid: string, callback: Callback) => Promise<void>;
|
|
56
|
+
getProfileByPid: (hid: string, pid: string, callback: Callback) => Promise<void>;
|
|
57
|
+
getAllObjectProfiles: (hid: string, callback: Callback) => Promise<void>;
|
|
51
58
|
}
|
|
52
59
|
export {};
|
package/dist/engine-api-calls.js
CHANGED
|
@@ -1,306 +1,388 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EngineApiCalls = void 0;
|
|
4
|
+
const maxQueueLength = 25;
|
|
4
5
|
class EngineApiCalls {
|
|
5
6
|
apiClient = null;
|
|
6
|
-
|
|
7
|
+
loggedIn = false;
|
|
8
|
+
// queue of callback functions
|
|
9
|
+
messageQueue = { maxLength: 100, timestep: 500, interval: null, queue: [] };
|
|
10
|
+
constructor() {
|
|
11
|
+
this.startQueueInterval();
|
|
12
|
+
}
|
|
13
|
+
startQueueInterval = () => {
|
|
14
|
+
this.messageQueue.interval = setInterval(() => {
|
|
15
|
+
if (this.messageQueue.queue.length > this.messageQueue.maxLength) {
|
|
16
|
+
this.messageQueue.queue = this.messageQueue.queue.slice(-this.messageQueue.maxLength);
|
|
17
|
+
console.log(`Node-RED Engine API Client: Maximum queue length ${this.messageQueue.maxLength} reached. Dropping oldest message.`);
|
|
18
|
+
}
|
|
19
|
+
if (this.loggedIn) {
|
|
20
|
+
const func = this.messageQueue.queue.shift();
|
|
21
|
+
if (func) {
|
|
22
|
+
func();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, this.messageQueue.timestep);
|
|
26
|
+
};
|
|
27
|
+
stopQueueInterval = () => {
|
|
28
|
+
if (this.messageQueue.interval) {
|
|
29
|
+
clearInterval(this.messageQueue.interval);
|
|
30
|
+
this.messageQueue.interval = null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
7
33
|
setApiClient = (apiClient) => {
|
|
8
34
|
this.apiClient = apiClient;
|
|
9
35
|
};
|
|
36
|
+
setLoggedIn = (loggedIn) => {
|
|
37
|
+
this.loggedIn = loggedIn;
|
|
38
|
+
};
|
|
10
39
|
discover = async (uri, callback) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
const func = async () => {
|
|
41
|
+
try {
|
|
42
|
+
if (!this.apiClient)
|
|
43
|
+
throw new Error('No API client set');
|
|
44
|
+
const response = await this.apiClient({
|
|
45
|
+
method: 'get',
|
|
46
|
+
url: `/mobius/discover/${uri}`,
|
|
47
|
+
});
|
|
48
|
+
callback(null, response.data);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.log(err);
|
|
52
|
+
callback(err);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
23
56
|
};
|
|
24
57
|
writeResource = async (uri, value, priority, callback) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
const func = async () => {
|
|
59
|
+
try {
|
|
60
|
+
if (!this.apiClient)
|
|
61
|
+
throw new Error('No API client set');
|
|
62
|
+
const response = await this.apiClient({
|
|
63
|
+
method: 'patch',
|
|
64
|
+
url: `/mobius/object/resource/${uri}`,
|
|
65
|
+
data: {
|
|
66
|
+
value,
|
|
67
|
+
priority,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
callback(null, response.data);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
callback(err);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
41
77
|
};
|
|
42
78
|
writeMultiResource = async (uri, updates, callback) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
const func = async () => {
|
|
80
|
+
try {
|
|
81
|
+
if (!this.apiClient)
|
|
82
|
+
throw new Error('No API client set');
|
|
83
|
+
const response = await this.apiClient({
|
|
84
|
+
method: 'patch',
|
|
85
|
+
url: `/mobius/object/resource/${uri}`,
|
|
86
|
+
data: updates,
|
|
87
|
+
});
|
|
88
|
+
callback(null, response.data);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
callback(err);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
56
95
|
};
|
|
57
96
|
clearResource = async (uri, priority, callback) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
97
|
+
const func = async () => {
|
|
98
|
+
try {
|
|
99
|
+
if (!this.apiClient)
|
|
100
|
+
throw new Error('No API client set');
|
|
101
|
+
const response = await this.apiClient({
|
|
102
|
+
method: 'patch',
|
|
103
|
+
url: `/mobius/object/resource/clear/${uri}`,
|
|
104
|
+
data: {
|
|
105
|
+
priority,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
callback(null, response.data);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
callback(err);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
73
115
|
};
|
|
74
116
|
readResource = async (uri, callback) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
const func = async () => {
|
|
118
|
+
try {
|
|
119
|
+
if (!this.apiClient)
|
|
120
|
+
throw new Error('No API client set');
|
|
121
|
+
const response = await this.apiClient({
|
|
122
|
+
method: 'get',
|
|
123
|
+
url: `/mobius/object/resource/${uri}`,
|
|
124
|
+
});
|
|
125
|
+
callback(null, response.data);
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
callback(err);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
87
132
|
};
|
|
88
133
|
readObject = async (uri, callback) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
134
|
+
const func = async () => {
|
|
135
|
+
try {
|
|
136
|
+
if (!this.apiClient)
|
|
137
|
+
throw new Error('No API client set');
|
|
138
|
+
const response = await this.apiClient({
|
|
139
|
+
method: 'get',
|
|
140
|
+
url: `/mobius/object/${uri}`,
|
|
141
|
+
});
|
|
142
|
+
callback(null, response.data);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
callback(err);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
101
149
|
};
|
|
102
|
-
sendBroadcastCommand = async (cid, commandData) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
150
|
+
sendBroadcastCommand = async (cid, commandData, callback) => {
|
|
151
|
+
const func = async () => {
|
|
152
|
+
try {
|
|
153
|
+
if (!this.apiClient)
|
|
154
|
+
throw new Error('No API client set');
|
|
155
|
+
const response = await this.apiClient({
|
|
156
|
+
method: 'post',
|
|
157
|
+
url: `/mobius/command/${cid}`,
|
|
158
|
+
data: commandData,
|
|
159
|
+
});
|
|
160
|
+
callback(null, 'Ok');
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
callback(err);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
115
167
|
};
|
|
116
168
|
sendDirectCommand = async (uri, cid, commandData, timeout, callback) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
169
|
+
const func = async () => {
|
|
170
|
+
try {
|
|
171
|
+
if (!this.apiClient)
|
|
172
|
+
throw new Error('No API client set');
|
|
173
|
+
const response = await this.apiClient({
|
|
174
|
+
method: 'post',
|
|
175
|
+
url: `/mobius/directCommand/${cid}`,
|
|
176
|
+
data: {
|
|
177
|
+
uri,
|
|
178
|
+
commandData,
|
|
179
|
+
timeout,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
callback(null, response.data);
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
callback(err);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
134
189
|
};
|
|
135
190
|
getServiceConfig = async (uri, callback) => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
url: `/mobius/service/config/${uri}`,
|
|
142
|
-
});
|
|
143
|
-
callback(null, response.data);
|
|
144
|
-
}
|
|
145
|
-
catch (err) {
|
|
146
|
-
callback(err);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
updateObject = async (uri, config, callback) => {
|
|
150
|
-
try {
|
|
151
|
-
if (!this.apiClient)
|
|
152
|
-
throw new Error('No API client set');
|
|
153
|
-
const response = await this.apiClient({
|
|
154
|
-
method: 'post',
|
|
155
|
-
url: `/mobius/object/config/${uri}`,
|
|
156
|
-
data: config,
|
|
157
|
-
});
|
|
158
|
-
callback(null, response.data);
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
callback(err);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
filterObjectsByRIDValue = async (uri, pids, rid, limit, func, callback) => {
|
|
165
|
-
try {
|
|
166
|
-
if (!this.apiClient)
|
|
167
|
-
throw new Error('No API client set');
|
|
168
|
-
const discoveries = [];
|
|
169
|
-
for (let pid of pids) {
|
|
170
|
-
discoveries.push(this.apiClient({
|
|
191
|
+
const func = async () => {
|
|
192
|
+
try {
|
|
193
|
+
if (!this.apiClient)
|
|
194
|
+
throw new Error('No API client set');
|
|
195
|
+
const response = await this.apiClient({
|
|
171
196
|
method: 'get',
|
|
172
|
-
url: `/mobius/
|
|
173
|
-
})
|
|
197
|
+
url: `/mobius/service/config/${uri}`,
|
|
198
|
+
});
|
|
199
|
+
callback(null, response.data);
|
|
174
200
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
inss: response.data.data,
|
|
178
|
-
}));
|
|
179
|
-
const objectUris = [];
|
|
180
|
-
for (let pidGroup of pidGroups) {
|
|
181
|
-
for (let ins of pidGroup.inss) {
|
|
182
|
-
objectUris.push(`${pidGroup.uri}/${ins}`);
|
|
183
|
-
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
callback(err);
|
|
184
203
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
204
|
+
};
|
|
205
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
206
|
+
};
|
|
207
|
+
updateObject = async (uri, config, callback) => {
|
|
208
|
+
const func = async () => {
|
|
209
|
+
try {
|
|
210
|
+
if (!this.apiClient)
|
|
211
|
+
throw new Error('No API client set');
|
|
212
|
+
const response = await this.apiClient({
|
|
213
|
+
method: 'post',
|
|
214
|
+
url: `/mobius/object/config/${uri}`,
|
|
215
|
+
data: config,
|
|
190
216
|
});
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
217
|
+
callback(null, response.data);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
callback(err);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
224
|
+
};
|
|
225
|
+
filterObjectsByRIDValue = async (uri, pids, rid, limit, processFunc, callback) => {
|
|
226
|
+
const func = async () => {
|
|
227
|
+
try {
|
|
228
|
+
if (!this.apiClient)
|
|
229
|
+
throw new Error('No API client set');
|
|
230
|
+
const discoveries = [];
|
|
231
|
+
for (let pid of pids) {
|
|
232
|
+
discoveries.push(this.apiClient({
|
|
233
|
+
method: 'get',
|
|
234
|
+
url: `/mobius/discover/${uri}/${pid}`,
|
|
235
|
+
}));
|
|
194
236
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
237
|
+
const pidGroups = (await Promise.all(discoveries)).map((response) => ({
|
|
238
|
+
uri: response.data.uri,
|
|
239
|
+
inss: response.data.data,
|
|
240
|
+
}));
|
|
241
|
+
const objectUris = [];
|
|
242
|
+
for (let pidGroup of pidGroups) {
|
|
243
|
+
for (let ins of pidGroup.inss) {
|
|
244
|
+
objectUris.push(`${pidGroup.uri}/${ins}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const objects = [];
|
|
248
|
+
for (let objectUri of objectUris) {
|
|
249
|
+
const object = await this.apiClient({
|
|
250
|
+
method: 'get',
|
|
251
|
+
url: `/mobius/object/${objectUri}`,
|
|
200
252
|
});
|
|
253
|
+
const resource = object.data.data.resources.find((r) => r.rid === rid);
|
|
254
|
+
if (processFunc(resource?.pv)) {
|
|
255
|
+
objects.push(object.data.data);
|
|
256
|
+
}
|
|
257
|
+
if (objects.length >= limit) {
|
|
258
|
+
return callback(null, {
|
|
259
|
+
uri,
|
|
260
|
+
ts: new Date().toISOString(),
|
|
261
|
+
value: objects,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
201
264
|
}
|
|
265
|
+
return callback(null, {
|
|
266
|
+
uri,
|
|
267
|
+
ts: new Date().toISOString(),
|
|
268
|
+
value: objects,
|
|
269
|
+
});
|
|
202
270
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
catch (err) {
|
|
210
|
-
callback(err);
|
|
211
|
-
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
callback(err);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
212
276
|
};
|
|
213
277
|
getHubId = async (callback) => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
278
|
+
const func = async () => {
|
|
279
|
+
try {
|
|
280
|
+
if (!this.apiClient)
|
|
281
|
+
throw new Error('No API client set');
|
|
282
|
+
const response = await this.apiClient({
|
|
283
|
+
method: 'get',
|
|
284
|
+
url: `/mobius/admin/settings`,
|
|
285
|
+
});
|
|
286
|
+
callback(null, response.data.data.mobiusFlow.hubID.runtime);
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
callback(err);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
226
293
|
};
|
|
227
294
|
getNodeConfig = async (uri, callback) => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
295
|
+
const func = async () => {
|
|
296
|
+
try {
|
|
297
|
+
if (!this.apiClient)
|
|
298
|
+
throw new Error('No API client set');
|
|
299
|
+
const response = await this.apiClient({
|
|
300
|
+
method: 'get',
|
|
301
|
+
url: `/mobius/node/config/${uri}`,
|
|
302
|
+
});
|
|
303
|
+
callback(null, response.data);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
callback(err);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
240
310
|
};
|
|
241
311
|
changeAdminPassword = async (password, callback) => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
312
|
+
const func = async () => {
|
|
313
|
+
try {
|
|
314
|
+
if (!this.apiClient)
|
|
315
|
+
throw new Error('No API client set');
|
|
316
|
+
const response = await this.apiClient({
|
|
317
|
+
method: 'get',
|
|
318
|
+
url: `/auth/user/admin`,
|
|
319
|
+
});
|
|
320
|
+
const adminUserId = response.data;
|
|
321
|
+
await this.apiClient({
|
|
322
|
+
method: 'patch',
|
|
323
|
+
url: `/auth/user/password/${adminUserId}`,
|
|
324
|
+
data: {
|
|
325
|
+
password,
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
callback(null, 'Ok');
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
callback(err);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
262
335
|
};
|
|
263
336
|
getNodeConfigTree = async (hid, callback) => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
337
|
+
const func = async () => {
|
|
338
|
+
try {
|
|
339
|
+
if (!this.apiClient)
|
|
340
|
+
throw new Error('No API client set');
|
|
341
|
+
const response = await this.apiClient({
|
|
342
|
+
method: 'get',
|
|
343
|
+
url: `/mobius/node/configtree/${hid}`,
|
|
344
|
+
});
|
|
345
|
+
callback(null, response.data);
|
|
346
|
+
}
|
|
347
|
+
catch (err) {
|
|
348
|
+
callback(err);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
276
352
|
};
|
|
277
353
|
getProfileByPid = async (hid, pid, callback) => {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
354
|
+
const func = async () => {
|
|
355
|
+
try {
|
|
356
|
+
if (!this.apiClient)
|
|
357
|
+
throw new Error('No API client set');
|
|
358
|
+
const response = await this.apiClient({
|
|
359
|
+
method: 'get',
|
|
360
|
+
url: `/mobius/profile/object/${hid}/${pid}`,
|
|
361
|
+
});
|
|
362
|
+
callback(null, response.data);
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
callback(err);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
290
369
|
};
|
|
291
370
|
getAllObjectProfiles = async (hid, callback) => {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
371
|
+
const func = async () => {
|
|
372
|
+
try {
|
|
373
|
+
if (!this.apiClient)
|
|
374
|
+
throw new Error('No API client set');
|
|
375
|
+
const response = await this.apiClient({
|
|
376
|
+
method: 'get',
|
|
377
|
+
url: `/mobius/profile/object/${hid}`,
|
|
378
|
+
});
|
|
379
|
+
callback(null, response.data);
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
callback(err);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
this.loggedIn ? func() : this.messageQueue.queue.push(func);
|
|
304
386
|
};
|
|
305
387
|
}
|
|
306
388
|
exports.EngineApiCalls = EngineApiCalls;
|
|
@@ -13,7 +13,6 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
13
13
|
client = null;
|
|
14
14
|
refreshLoop = null;
|
|
15
15
|
tokens = null;
|
|
16
|
-
loggedIn = false;
|
|
17
16
|
username;
|
|
18
17
|
password;
|
|
19
18
|
EngineWebSocket;
|
|
@@ -112,6 +111,7 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
112
111
|
}
|
|
113
112
|
};
|
|
114
113
|
close = () => {
|
|
114
|
+
this.stopQueueInterval();
|
|
115
115
|
if (this.refreshLoop) {
|
|
116
116
|
clearInterval(this.refreshLoop);
|
|
117
117
|
}
|
|
@@ -34,7 +34,7 @@ export interface MobiusConnectionInterface {
|
|
|
34
34
|
unsubscribeToObjectCOV(uri: string, ref: string, callback: (err: any, response: any) => void): void;
|
|
35
35
|
subscribeToBCMD(uri: string, ref: string, callback: (err: any, response: any) => void): void;
|
|
36
36
|
unsubscribeToBCMD(uri: string, ref: string, callback: (err: any, response: any) => void): void;
|
|
37
|
-
sendBroadcastCommand(cid: string, commandData: any): void;
|
|
37
|
+
sendBroadcastCommand(cid: string, commandData: any, callback: (err: any, response: any) => void): void;
|
|
38
38
|
sendDirectCommand(uri: string, cid: string, timeout: number, callback: (err: any, response: any) => void): void;
|
|
39
39
|
getServiceConfig(hid: string, sid: string, callback: (err: any, response: any) => void): void;
|
|
40
40
|
updateObjectInServiceConfig(hid: string, sid: string, pid: string, ins: string, config: any, callback: (err: any, response: any) => void): void;
|
|
@@ -542,8 +542,8 @@ module.exports = function (RED) {
|
|
|
542
542
|
* @param {string} cid - The command ID
|
|
543
543
|
* @param {Object} commandData - An object containing the command data
|
|
544
544
|
*/
|
|
545
|
-
node.sendBroadcastCommand = function (cid, commandData) {
|
|
546
|
-
this.apiClient.sendBroadcastCommand(cid, commandData);
|
|
545
|
+
node.sendBroadcastCommand = function (cid, commandData, callback) {
|
|
546
|
+
this.apiClient.sendBroadcastCommand(cid, commandData, callback);
|
|
547
547
|
};
|
|
548
548
|
|
|
549
549
|
/**
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
'use strict';
|
|
29
29
|
|
|
30
30
|
module.exports = function (RED) {
|
|
31
|
-
function MobiusSendBCMDNode
|
|
31
|
+
function MobiusSendBCMDNode(n) {
|
|
32
32
|
RED.nodes.createNode(this, n);
|
|
33
33
|
this.cid = n.cid;
|
|
34
34
|
this.serviceConn = RED.nodes.getNode(n.connection);
|
|
@@ -38,12 +38,31 @@ module.exports = function (RED) {
|
|
|
38
38
|
node.status({
|
|
39
39
|
fill: 'red',
|
|
40
40
|
shape: 'ring',
|
|
41
|
-
text: 'Disconnected'
|
|
41
|
+
text: 'Disconnected',
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
node.on('input', function (msg) {
|
|
45
45
|
if (msg.hasOwnProperty('payload')) {
|
|
46
|
-
node.serviceConn.sendBroadcastCommand(
|
|
46
|
+
node.serviceConn.sendBroadcastCommand(
|
|
47
|
+
node.cid,
|
|
48
|
+
msg.payload,
|
|
49
|
+
(err) => {
|
|
50
|
+
if (err) {
|
|
51
|
+
node.status({
|
|
52
|
+
fill: 'yellow',
|
|
53
|
+
shape: 'dot',
|
|
54
|
+
text: `Error sending BCMD`,
|
|
55
|
+
});
|
|
56
|
+
node.error(err.message);
|
|
57
|
+
} else {
|
|
58
|
+
node.status({
|
|
59
|
+
fill: 'green',
|
|
60
|
+
shape: 'dot',
|
|
61
|
+
text: 'Sent BCMD',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
);
|
|
47
66
|
}
|
|
48
67
|
});
|
|
49
68
|
|