node-red-contrib-mobius-flow-base 3.3.0 → 3.4.0-beta.2
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AxiosInstance } from
|
|
2
|
-
import { EngineWebSocket } from
|
|
3
|
-
import { EngineApiCalls } from
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { EngineWebSocket } from "./engine-websocket";
|
|
3
|
+
import { EngineApiCalls } from "./engine-api-calls";
|
|
4
4
|
export declare class EngineApiClient extends EngineApiCalls {
|
|
5
5
|
private reloginInterval;
|
|
6
6
|
client: AxiosInstance | null;
|
|
@@ -14,7 +14,7 @@ export declare class EngineApiClient extends EngineApiCalls {
|
|
|
14
14
|
EngineWebSocket: EngineWebSocket;
|
|
15
15
|
private hostname;
|
|
16
16
|
private protocol;
|
|
17
|
-
constructor(protocol:
|
|
17
|
+
constructor(protocol: "http" | "https", host: string, username: string, password: string);
|
|
18
18
|
private login;
|
|
19
19
|
private refresh;
|
|
20
20
|
close: () => void;
|
|
@@ -24,11 +24,11 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
24
24
|
this.password = password;
|
|
25
25
|
this.hostname = host;
|
|
26
26
|
this.protocol = protocol;
|
|
27
|
-
const baseURL = `${this.protocol}://${this.hostname}/api/v1`;
|
|
27
|
+
const baseURL = `${this.protocol}://${this.hostname}/api/engine/v1`;
|
|
28
28
|
this.client = axios_1.default.create({
|
|
29
29
|
baseURL: baseURL,
|
|
30
30
|
headers: {
|
|
31
|
-
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
32
|
},
|
|
33
33
|
});
|
|
34
34
|
this.setApiClient(this.client);
|
|
@@ -41,15 +41,15 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
41
41
|
this.login();
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
console.log(
|
|
44
|
+
console.log("No username, password, host, or port provided. Not attempting to login to Mobius Engine API.");
|
|
45
45
|
this.reloginInterval && clearInterval(this.reloginInterval);
|
|
46
46
|
this.reloginInterval = null;
|
|
47
47
|
}
|
|
48
48
|
// Add auth headers to all axios calls
|
|
49
49
|
this.client.interceptors.request.use((config) => {
|
|
50
|
-
if (!config.url?.endsWith(
|
|
50
|
+
if (!config.url?.endsWith("/auth/login")) {
|
|
51
51
|
if (this.tokens && config.headers) {
|
|
52
|
-
config.headers[
|
|
52
|
+
config.headers["Authorization"] = `Bearer ${this.tokens.token}`;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
return config;
|
|
@@ -62,7 +62,7 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
62
62
|
throw error;
|
|
63
63
|
});
|
|
64
64
|
this.EngineWebSocket = new engine_websocket_1.EngineWebSocket(this.hostname, this.protocol);
|
|
65
|
-
this.EngineWebSocket.on(
|
|
65
|
+
this.EngineWebSocket.on("disconnected", () => {
|
|
66
66
|
this.loggedIn = false;
|
|
67
67
|
});
|
|
68
68
|
}
|
|
@@ -70,8 +70,8 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
70
70
|
console.log(`(${this.hostname}) -> Attempting Mobius Engine API Login`);
|
|
71
71
|
try {
|
|
72
72
|
const response = await this.client({
|
|
73
|
-
method:
|
|
74
|
-
url:
|
|
73
|
+
method: "post",
|
|
74
|
+
url: "/auth/login",
|
|
75
75
|
data: {
|
|
76
76
|
username: this.username,
|
|
77
77
|
password: this.password,
|
|
@@ -97,8 +97,8 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
97
97
|
}
|
|
98
98
|
try {
|
|
99
99
|
const response = await this.client({
|
|
100
|
-
method:
|
|
101
|
-
url:
|
|
100
|
+
method: "post",
|
|
101
|
+
url: "/auth/refresh",
|
|
102
102
|
data: {
|
|
103
103
|
refreshToken: this.tokens.refreshToken,
|
|
104
104
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EventEmitter } from
|
|
2
|
-
type WebSocketTopics =
|
|
1
|
+
import { EventEmitter } from "stream";
|
|
2
|
+
type WebSocketTopics = "authorize" | "subscribe" | "unsubscribe" | "connected" | "authorized" | "object-cov" | "resource-cov" | "service-status" | "broadcast-command" | "error" | "ping" | "pong";
|
|
3
3
|
interface EngineWebSocketInterface {
|
|
4
4
|
registerCallback: (topic: WebSocketTopics, callback: Function) => void;
|
|
5
5
|
clearAllCallbacks: () => void;
|
|
@@ -24,7 +24,7 @@ export declare class EngineWebSocket extends EventEmitter implements EngineWebSo
|
|
|
24
24
|
private authToken;
|
|
25
25
|
private hostname;
|
|
26
26
|
private protocol;
|
|
27
|
-
constructor(hostname: string, protocol:
|
|
27
|
+
constructor(hostname: string, protocol: "http" | "https");
|
|
28
28
|
connectToWebSocket: (token: string) => void;
|
|
29
29
|
private sendWebSocketMessage;
|
|
30
30
|
private sendPingMessage;
|
package/dist/engine-websocket.js
CHANGED
|
@@ -24,18 +24,18 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
24
24
|
}
|
|
25
25
|
connectToWebSocket = (token) => {
|
|
26
26
|
this.authToken = token;
|
|
27
|
-
let webSocketProtocol =
|
|
28
|
-
if (this.protocol ===
|
|
29
|
-
webSocketProtocol =
|
|
27
|
+
let webSocketProtocol = "wss";
|
|
28
|
+
if (this.protocol === "http") {
|
|
29
|
+
webSocketProtocol = "ws";
|
|
30
30
|
}
|
|
31
|
-
this.webSocket = new ws_1.default(`${webSocketProtocol}://${this.hostname}/api/v1/mobius/subscribe/connect`);
|
|
31
|
+
this.webSocket = new ws_1.default(`${webSocketProtocol}://${this.hostname}/api/engine/v1/mobius/subscribe/connect`);
|
|
32
32
|
this.webSocket.onopen = () => {
|
|
33
33
|
this.attemptReconnect = true;
|
|
34
34
|
console.log(`(${this.hostname}) -> Engine API Subscription WebSocket Client Connected`);
|
|
35
35
|
this.pingInterval = setInterval(this.sendPingMessage, 30000);
|
|
36
36
|
clearInterval(this.reconnectInterval);
|
|
37
37
|
this.sendWebSocketMessage({
|
|
38
|
-
topic:
|
|
38
|
+
topic: "authorize",
|
|
39
39
|
payload: `Bearer ${this.authToken}`,
|
|
40
40
|
});
|
|
41
41
|
this.pendingWebSocketMessageInterval = setInterval(() => {
|
|
@@ -60,7 +60,7 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
60
60
|
this.reconnect();
|
|
61
61
|
}, 30000);
|
|
62
62
|
}
|
|
63
|
-
this.emit(
|
|
63
|
+
this.emit("disconnected");
|
|
64
64
|
};
|
|
65
65
|
this.webSocket.onmessage = (message) => {
|
|
66
66
|
try {
|
|
@@ -70,15 +70,15 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
catch (e) {
|
|
73
|
-
console.log(`(${this.hostname}) -> Error parsing message: ${e.code}, ${e.message ? e.message :
|
|
73
|
+
console.log(`(${this.hostname}) -> Error parsing message: ${e.code}, ${e.message ? e.message : ""}`);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
this.webSocket.on(
|
|
77
|
-
if (e.code ===
|
|
78
|
-
this.emit(
|
|
76
|
+
this.webSocket.on("error", (e) => {
|
|
77
|
+
if (e.code === "ECONNREFUSED") {
|
|
78
|
+
this.emit("disconnected");
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
console.error(`(${this.hostname}) -> Engine API Subscription WebSocket Client Error: ${e.code}, ${e.message ? e.message :
|
|
81
|
+
console.error(`(${this.hostname}) -> Engine API Subscription WebSocket Client Error: ${e.code}, ${e.message ? e.message : ""}`);
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
};
|
|
@@ -97,7 +97,7 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
97
97
|
};
|
|
98
98
|
sendPingMessage = () => {
|
|
99
99
|
this.sendWebSocketMessage({
|
|
100
|
-
topic:
|
|
100
|
+
topic: "ping",
|
|
101
101
|
payload: {},
|
|
102
102
|
});
|
|
103
103
|
};
|
|
@@ -108,12 +108,12 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
108
108
|
this.registeredCallbacks = [];
|
|
109
109
|
};
|
|
110
110
|
handleWebSocketMessage = (message) => {
|
|
111
|
-
if (message.topic ===
|
|
111
|
+
if (message.topic === "error") {
|
|
112
112
|
console.log(`(${this.hostname}) -> Websocket Error: ${message.payload}`);
|
|
113
113
|
}
|
|
114
|
-
if (message.topic ===
|
|
114
|
+
if (message.topic === "authorized") {
|
|
115
115
|
console.log(`(${this.hostname}) -> Engine API Subscription WebSocket Auth Success`);
|
|
116
|
-
this.emit(
|
|
116
|
+
this.emit("connected");
|
|
117
117
|
}
|
|
118
118
|
const callbacks = this.registeredCallbacks
|
|
119
119
|
.filter((cb) => cb.topic === message.topic)
|
|
@@ -153,38 +153,38 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
153
153
|
};
|
|
154
154
|
subscribeToObjectCOV = (uri) => {
|
|
155
155
|
this.sendWebSocketMessage({
|
|
156
|
-
topic:
|
|
157
|
-
payload: { type:
|
|
156
|
+
topic: "subscribe",
|
|
157
|
+
payload: { type: "object-cov", uri },
|
|
158
158
|
});
|
|
159
159
|
};
|
|
160
160
|
unsubscribeToObjectCOV = (uri) => {
|
|
161
161
|
this.sendWebSocketMessage({
|
|
162
|
-
topic:
|
|
163
|
-
payload: { type:
|
|
162
|
+
topic: "unsubscribe",
|
|
163
|
+
payload: { type: "object-cov", uri },
|
|
164
164
|
});
|
|
165
165
|
};
|
|
166
166
|
subscribeToResourceCOV = (uri) => {
|
|
167
167
|
this.sendWebSocketMessage({
|
|
168
|
-
topic:
|
|
169
|
-
payload: { type:
|
|
168
|
+
topic: "subscribe",
|
|
169
|
+
payload: { type: "resource-cov", uri },
|
|
170
170
|
});
|
|
171
171
|
};
|
|
172
172
|
unsubscribeToResourceCOV = (uri) => {
|
|
173
173
|
this.sendWebSocketMessage({
|
|
174
|
-
topic:
|
|
175
|
-
payload: { type:
|
|
174
|
+
topic: "unsubscribe",
|
|
175
|
+
payload: { type: "resource-cov", uri },
|
|
176
176
|
});
|
|
177
177
|
};
|
|
178
178
|
subscribeToBCMD = (uri) => {
|
|
179
179
|
this.sendWebSocketMessage({
|
|
180
|
-
topic:
|
|
181
|
-
payload: { type:
|
|
180
|
+
topic: "subscribe",
|
|
181
|
+
payload: { type: "broadcast-command", uri },
|
|
182
182
|
});
|
|
183
183
|
};
|
|
184
184
|
unsubscribeToBCMD = (uri) => {
|
|
185
185
|
this.sendWebSocketMessage({
|
|
186
|
-
topic:
|
|
187
|
-
payload: { type:
|
|
186
|
+
topic: "unsubscribe",
|
|
187
|
+
payload: { type: "broadcast-command", uri },
|
|
188
188
|
});
|
|
189
189
|
};
|
|
190
190
|
}
|