@mysetup/mqtt 1.15.1 → 1.15.3
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/mqttClient.d.ts +5 -4
- package/dist/mqttClient.d.ts.map +1 -1
- package/dist/mqttClient.js +7 -15
- package/dist/test/test-mqtt.js +2 -2
- package/package.json +1 -1
package/dist/mqttClient.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import mqtt from "mqtt";
|
|
2
2
|
import type { MqttClient } from "mqtt";
|
|
3
|
-
|
|
3
|
+
type MQttProtocol = "mqtt" | "mqtts" | "ws" | "wss";
|
|
4
4
|
interface MqttConfigProps {
|
|
5
|
-
protocol:
|
|
5
|
+
protocol: MQttProtocol;
|
|
6
6
|
port: number;
|
|
7
7
|
host: string;
|
|
8
8
|
path: string;
|
|
@@ -13,14 +13,15 @@ interface ConnectionProps {
|
|
|
13
13
|
clientId: string;
|
|
14
14
|
config: MqttConfigProps;
|
|
15
15
|
topicList: string[];
|
|
16
|
-
messageCallback
|
|
16
|
+
messageCallback: (topic: string, message: string) => void;
|
|
17
17
|
environment?: string | undefined;
|
|
18
18
|
}
|
|
19
|
-
declare const mqttSub: (topicList: string[], clientId: string,
|
|
19
|
+
declare const mqttSub: (topicList: string[], clientId: string, environment?: string) => void;
|
|
20
20
|
declare const mqttUnSub: (topicList: string[], clientId: string, environment?: string) => void;
|
|
21
21
|
declare const mqttDisconnect: (props: ConnectionProps, reinit: boolean, environment?: string) => void;
|
|
22
22
|
declare const mqttPublish: (topic: string, message: object, clientId: string, environment?: string) => void;
|
|
23
23
|
declare const mqttCreateConnection: (props: ConnectionProps) => mqtt.MqttClient | null;
|
|
24
24
|
declare const getMqttClient: (id: string) => mqtt.MqttClient | null;
|
|
25
25
|
export { mqttCreateConnection, mqttSub, mqttUnSub, mqttDisconnect, mqttPublish, getMqttClient, };
|
|
26
|
+
export type { ConnectionProps, MqttConfigProps, MqttClient };
|
|
26
27
|
//# sourceMappingURL=mqttClient.d.ts.map
|
package/dist/mqttClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mqttClient.d.ts","sourceRoot":"","sources":["../mqttClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGvC,YAAY,
|
|
1
|
+
{"version":3,"file":"mqttClient.d.ts","sourceRoot":"","sources":["../mqttClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGvC,KAAK,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,KAAK,CAAC;AAEpD,UAAU,eAAe;IACrB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,eAAe;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1D,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAkED,QAAA,MAAM,OAAO,GACT,WAAW,MAAM,EAAE,EACnB,UAAU,MAAM,EAChB,cAAc,MAAM,SAwBvB,CAAC;AAEF,QAAA,MAAM,SAAS,GACX,WAAW,MAAM,EAAE,EACnB,UAAU,MAAM,EAChB,cAAc,MAAM,SAoBvB,CAAC;AAEF,QAAA,MAAM,cAAc,GAChB,OAAO,eAAe,EACtB,QAAQ,OAAO,EACf,cAAc,MAAM,SAgBvB,CAAC;AAEF,QAAA,MAAM,WAAW,GACb,OAAO,MAAM,EACb,SAAS,MAAM,EACf,UAAU,MAAM,EAChB,cAAc,MAAM,SAqBvB,CAAC;AAsBF,QAAA,MAAM,oBAAoB,GAAI,OAAO,eAAe,2BAEnD,CAAC;AAEF,QAAA,MAAM,aAAa,GAAI,IAAI,MAAM,2BAEhC,CAAC;AAOF,OAAO,EACH,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,aAAa,GAChB,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/mqttClient.js
CHANGED
|
@@ -27,7 +27,7 @@ var checkInitConnect = function (props) {
|
|
|
27
27
|
logger_1.logger.info("MQTT connection successful");
|
|
28
28
|
}
|
|
29
29
|
(0, cache_1.setCacheData)("mqttClientStatus", "connect");
|
|
30
|
-
mqttSub(props.topicList, props.clientId, props.
|
|
30
|
+
mqttSub(props.topicList, props.clientId, props.environment);
|
|
31
31
|
});
|
|
32
32
|
client.on("error", function (err) {
|
|
33
33
|
if (props.environment === "development") {
|
|
@@ -54,12 +54,15 @@ var checkInitConnect = function (props) {
|
|
|
54
54
|
}
|
|
55
55
|
(0, cache_1.setCacheData)("mqttClientStatus", "offline");
|
|
56
56
|
});
|
|
57
|
+
client.on("message", function (topic, message) {
|
|
58
|
+
props.messageCallback(topic, message.toString());
|
|
59
|
+
});
|
|
57
60
|
return client;
|
|
58
61
|
};
|
|
59
|
-
var mqttSub = function (topicList, clientId,
|
|
62
|
+
var mqttSub = function (topicList, clientId, environment) {
|
|
60
63
|
try {
|
|
61
|
-
var
|
|
62
|
-
|
|
64
|
+
var client = getMqttClient(clientId);
|
|
65
|
+
client === null || client === void 0 ? void 0 : client.subscribe(topicList, { qos: 0 }, function (error, granted) {
|
|
63
66
|
if (error) {
|
|
64
67
|
logger_1.logger.error("MQTT Subscribe to topics error: ".concat(error.message));
|
|
65
68
|
}
|
|
@@ -71,7 +74,6 @@ var mqttSub = function (topicList, clientId, messageCallback, environment) {
|
|
|
71
74
|
}
|
|
72
75
|
});
|
|
73
76
|
(0, cache_1.setCacheData)("subscribedTopic", grantedList);
|
|
74
|
-
messageCallback && mqttOnMessage(messageCallback, client_1);
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
79
|
catch (error) {
|
|
@@ -117,16 +119,6 @@ var mqttDisconnect = function (props, reinit, environment) {
|
|
|
117
119
|
}
|
|
118
120
|
};
|
|
119
121
|
exports.mqttDisconnect = mqttDisconnect;
|
|
120
|
-
var mqttOnMessage = function (messageCallback, client) {
|
|
121
|
-
try {
|
|
122
|
-
client === null || client === void 0 ? void 0 : client.on("message", function (topic, message) {
|
|
123
|
-
messageCallback(topic, message.toString());
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
logger_1.logger.error("MQTT On-message error: ".concat(JSON.stringify(error)));
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
122
|
var mqttPublish = function (topic, message, clientId, environment) {
|
|
131
123
|
try {
|
|
132
124
|
var client = getMqttClient(clientId);
|
package/dist/test/test-mqtt.js
CHANGED
|
@@ -9,13 +9,13 @@ var CLIENT_ID = "testClient-".concat(Math.random().toString(16).slice(2, 8));
|
|
|
9
9
|
config: {
|
|
10
10
|
host: String(MQTT_HOST),
|
|
11
11
|
port: Number(MQTT_PORT),
|
|
12
|
-
protocol: "
|
|
12
|
+
protocol: "mqtts",
|
|
13
13
|
path: "",
|
|
14
14
|
username: MQTT_USERNAME,
|
|
15
15
|
password: MQTT_PASSWORD,
|
|
16
16
|
},
|
|
17
17
|
environment: String(ENVIRONMENT),
|
|
18
|
-
topicList: ["
|
|
18
|
+
topicList: ["#"],
|
|
19
19
|
messageCallback: function (topic, message) {
|
|
20
20
|
logger_1.logger.info("Message received \u2192 topic: ".concat(topic, ", message: ").concat(message.toString()));
|
|
21
21
|
},
|