@mysetup/mqtt 1.1.0 → 1.3.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.
@@ -1,4 +1,3 @@
1
- import mqtt from "mqtt";
2
1
  import type { MqttClient } from "mqtt";
3
2
  export type { MqttClient };
4
3
  type MQttOptionProps = "web" | "server";
@@ -8,11 +7,10 @@ interface ConnectionProps {
8
7
  topicList: string[];
9
8
  messageCallback?: (topic: string, message: string) => void;
10
9
  }
11
- declare const mqttSub: (topicList: string[], messageCallback?: (topic: string, message: string) => void, client?: MqttClient) => void;
12
- declare const mqttUnSub: (topicList: string[], client?: MqttClient) => void;
13
- declare const mqttDisconnect: (props: ConnectionProps, reinit: boolean, client?: MqttClient) => void;
14
- declare const mqttOnMessage: (messageCallback: (topic: string, message: string) => void, client?: MqttClient) => void;
15
- declare const mqttCreateConnection: (props: ConnectionProps) => mqtt.MqttClient;
16
- declare const getMqttClient: () => string;
17
- export { mqttCreateConnection, mqttSub, mqttUnSub, mqttDisconnect, mqttOnMessage, getMqttClient, };
10
+ export declare const mqttSub: (topicList: string[], messageCallback?: (topic: string, message: string) => void, client?: MqttClient) => void;
11
+ export declare const mqttUnSub: (topicList: string[], client?: MqttClient) => void;
12
+ export declare const mqttDisconnect: (props: ConnectionProps, reinit: boolean, client?: MqttClient) => void;
13
+ export declare const mqttOnMessage: (messageCallback: (topic: string, message: string) => void, client?: MqttClient) => void;
14
+ export declare const getMqttClient: () => string;
15
+ export declare const mqttCreateConnection: (props: ConnectionProps) => MqttClient;
18
16
  //# sourceMappingURL=mqttClient.d.ts.map
@@ -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,EAAE,UAAU,EAAE,CAAC;AAE3B,KAAK,eAA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C;CAC9D;AAkDD,eAAO,MAAM,OAAO,cACL,MAAM,EAAE,oBACD,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,WACjD,UAAU,SAoBtB,CAAC;AAEF,eAAO,MAAM,SAAS,cAAe,MAAM,EAAE,WAAW,UAAU,SAcjE,CAAC;AAEF,eAAO,MAAM,cAAc,UAChB,eAAe,UACd,OAAO,WACN,UAAU,SAetB,CAAC;AAEF,eAAO,MAAM,aAAa,oBACL,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,WAChD,UAAU,SAStB,CAAC;AAmBF,eAAO,MAAM,aAAa,cAEzB,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,eAAe,eAE1D,CAAC"}
@@ -10,12 +10,9 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
13
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getMqttClient = exports.mqttOnMessage = exports.mqttDisconnect = exports.mqttUnSub = exports.mqttSub = exports.mqttCreateConnection = void 0;
18
- var mqtt_1 = __importDefault(require("mqtt"));
14
+ exports.mqttCreateConnection = exports.getMqttClient = exports.mqttOnMessage = exports.mqttDisconnect = exports.mqttUnSub = exports.mqttSub = void 0;
15
+ var mqtt_1 = require("mqtt");
19
16
  var logger_1 = require("@mysetup/logger");
20
17
  var cache_1 = require("@mysetup/cache");
21
18
  var serverConnectOptions = {
@@ -32,7 +29,7 @@ var mqttClientId = "";
32
29
  var checkInitConnect = function (props) {
33
30
  var _a = props.option === "web" ? webConnectOptions : serverConnectOptions, protocol = _a.protocol, host = _a.host, port = _a.port;
34
31
  var connectUrl = "".concat(protocol, "://").concat(host, ":").concat(port);
35
- var client = mqtt_1.default.connect(connectUrl, {
32
+ var client = (0, mqtt_1.connect)(connectUrl, {
36
33
  clientId: props.value,
37
34
  clean: true,
38
35
  rejectUnauthorized: false,
@@ -44,12 +41,12 @@ var checkInitConnect = function (props) {
44
41
  client.on("connect", function () {
45
42
  logger_1.logger.info("MQTT connection successful");
46
43
  (0, cache_1.setCacheData)("mqttClientStatus", "connect");
47
- mqttSub(props.topicList, props.messageCallback, client);
44
+ (0, exports.mqttSub)(props.topicList, props.messageCallback, client);
48
45
  });
49
46
  client.on("error", function (err) {
50
47
  logger_1.logger.error("MQTT Connection error: ".concat(JSON.stringify(err)));
51
48
  (0, cache_1.setCacheData)("mqttClientStatus", "error");
52
- mqttDisconnect(props, true, client);
49
+ (0, exports.mqttDisconnect)(props, true, client);
53
50
  });
54
51
  client.on("reconnect", function () {
55
52
  (0, cache_1.setCacheData)("mqttClientStatus", "reconnect");
@@ -77,7 +74,7 @@ var mqttSub = function (topicList, messageCallback, client) {
77
74
  logger_1.logger.info("Subscribed to topics: ".concat(element.topic));
78
75
  });
79
76
  (0, cache_1.setCacheData)("subscribedTopic", grantedList);
80
- messageCallback && mqttOnMessage(messageCallback, client);
77
+ messageCallback && (0, exports.mqttOnMessage)(messageCallback, client);
81
78
  });
82
79
  }
83
80
  catch (error) {
@@ -142,11 +139,11 @@ var memoizedDb = function () {
142
139
  };
143
140
  // returned function from memoizedDb
144
141
  var cachedConnection = memoizedDb();
145
- var mqttCreateConnection = function (props) {
146
- return cachedConnection(props);
147
- };
148
- exports.mqttCreateConnection = mqttCreateConnection;
149
142
  var getMqttClient = function () {
150
143
  return mqttClientId;
151
144
  };
152
145
  exports.getMqttClient = getMqttClient;
146
+ var mqttCreateConnection = function (props) {
147
+ return cachedConnection(props);
148
+ };
149
+ exports.mqttCreateConnection = mqttCreateConnection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysetup/mqtt",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [