@yidingdian/binding-mqtt 0.9.2-custom.1
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/README.md +211 -0
- package/dist/mqtt-broker-server.d.ts +36 -0
- package/dist/mqtt-broker-server.js +361 -0
- package/dist/mqtt-broker-server.js.map +1 -0
- package/dist/mqtt-client-factory.d.ts +9 -0
- package/dist/mqtt-client-factory.js +78 -0
- package/dist/mqtt-client-factory.js.map +1 -0
- package/dist/mqtt-client.d.ts +26 -0
- package/dist/mqtt-client.js +329 -0
- package/dist/mqtt-client.js.map +1 -0
- package/dist/mqtt-message-pool.d.ts +13 -0
- package/dist/mqtt-message-pool.js +114 -0
- package/dist/mqtt-message-pool.js.map +1 -0
- package/dist/mqtt.d.ts +39 -0
- package/dist/mqtt.js +41 -0
- package/dist/mqtt.js.map +1 -0
- package/dist/mqtts-client-factory.d.ts +12 -0
- package/dist/mqtts-client-factory.js +79 -0
- package/dist/mqtts-client-factory.js.map +1 -0
- package/dist/util.d.ts +3 -0
- package/dist/util.js +22 -0
- package/dist/util.js.map +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const core_1 = require("@node-wot/core");
|
|
40
|
+
const mqtt_client_1 = __importDefault(require("./mqtt-client"));
|
|
41
|
+
const url = __importStar(require("url"));
|
|
42
|
+
const debug = (0, core_1.createDebugLogger)("binding-mqtt", "mqtt-client-factory");
|
|
43
|
+
class MqttClientFactory {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.scheme = "mqtt";
|
|
46
|
+
this.clientMap = new Map();
|
|
47
|
+
}
|
|
48
|
+
getClient(brokerUri) {
|
|
49
|
+
const key = brokerUri ? this._normalizeUri(brokerUri) : "default";
|
|
50
|
+
if (this.clientMap.has(key)) {
|
|
51
|
+
debug(`Reusing existing MQTT client for broker '${key}'`);
|
|
52
|
+
return this.clientMap.get(key);
|
|
53
|
+
}
|
|
54
|
+
const client = new mqtt_client_1.default();
|
|
55
|
+
this.clientMap.set(key, client);
|
|
56
|
+
return client;
|
|
57
|
+
}
|
|
58
|
+
init() {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
_normalizeUri(uri) {
|
|
62
|
+
try {
|
|
63
|
+
const u = new url.URL(uri);
|
|
64
|
+
return `${u.protocol}//${u.host}`;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return uri;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
destroy() {
|
|
71
|
+
debug(`MqttClientFactory stopping all clients for '${this.scheme}'`);
|
|
72
|
+
this.clientMap.forEach((client) => client.stop());
|
|
73
|
+
this.clientMap.clear();
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = MqttClientFactory;
|
|
78
|
+
//# sourceMappingURL=mqtt-client-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mqtt-client-factory.js","sourceRoot":"","sources":["../src/mqtt-client-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,yCAA0F;AAC1F,gEAAuC;AACvC,yCAA2B;AAE3B,MAAM,KAAK,GAAG,IAAA,wBAAiB,EAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;AAEvE,MAAqB,iBAAiB;IAAtC;QACoB,WAAM,GAAW,MAAM,CAAC;QACvB,cAAS,GAAgC,IAAI,GAAG,EAAE,CAAC;IAkCxE,CAAC;IAhCG,SAAS,CAAC,SAAkB;QACxB,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAClE,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,KAAK,CAAC,4CAA4C,GAAG,GAAG,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;QACpC,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,qBAAU,EAAE,CAAC;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,IAAI;QACA,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,aAAa,CAAC,GAAW;QAE7B,IAAI,CAAC;YACD,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC3B,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,GAAG,CAAC;QACf,CAAC;IAEL,CAAC;IAED,OAAO;QACH,KAAK,CAAC,+CAA+C,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AApCD,oCAoCC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ProtocolClient, Content, Form, SecurityScheme } from "@node-wot/core";
|
|
2
|
+
import { MqttClientConfig, MqttForm } from "./mqtt";
|
|
3
|
+
import { Subscription } from "rxjs/Subscription";
|
|
4
|
+
declare interface MqttClientSecurityParameters {
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
}
|
|
8
|
+
export default class MqttClient implements ProtocolClient {
|
|
9
|
+
private config;
|
|
10
|
+
private scheme;
|
|
11
|
+
private pools;
|
|
12
|
+
constructor(config?: MqttClientConfig, secure?: boolean);
|
|
13
|
+
private client?;
|
|
14
|
+
private ensureV5Properties;
|
|
15
|
+
private publishAndWait;
|
|
16
|
+
subscribeResource(form: MqttForm, next: (value: Content) => void, error?: (error: Error) => void, complete?: () => void): Promise<Subscription>;
|
|
17
|
+
readResource(form: MqttForm): Promise<Content>;
|
|
18
|
+
writeResource(form: MqttForm, content: Content): Promise<void | Content>;
|
|
19
|
+
invokeResource(form: MqttForm, content: Content): Promise<Content>;
|
|
20
|
+
unlinkResource(form: Form): Promise<void>;
|
|
21
|
+
requestThingDescription(uri: string): Promise<Content>;
|
|
22
|
+
start(): Promise<void>;
|
|
23
|
+
stop(): Promise<void>;
|
|
24
|
+
setSecurity(metadata: Array<SecurityScheme>, credentials?: MqttClientSecurityParameters): boolean;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const core_1 = require("@node-wot/core");
|
|
40
|
+
const url = __importStar(require("url"));
|
|
41
|
+
const Subscription_1 = require("rxjs/Subscription");
|
|
42
|
+
const stream_1 = require("stream");
|
|
43
|
+
const mqtt_message_pool_1 = __importDefault(require("./mqtt-message-pool"));
|
|
44
|
+
const util_1 = require("./util");
|
|
45
|
+
const { debug, warn } = (0, core_1.createLoggers)("binding-mqtt", "mqtt-client");
|
|
46
|
+
const DEFAULT_TIMEOUT = 5000;
|
|
47
|
+
function generateCorrelationData() {
|
|
48
|
+
return Buffer.from(Math.random().toString(16).substring(2, 10));
|
|
49
|
+
}
|
|
50
|
+
class MqttClient {
|
|
51
|
+
constructor(config = {}, secure = false) {
|
|
52
|
+
this.config = config;
|
|
53
|
+
this.pools = new Map();
|
|
54
|
+
this.scheme = "mqtt" + (secure ? "s" : "");
|
|
55
|
+
}
|
|
56
|
+
ensureV5Properties(options) {
|
|
57
|
+
if (this.config.protocolVersion === 5) {
|
|
58
|
+
if (!options.properties) {
|
|
59
|
+
options.properties = {};
|
|
60
|
+
}
|
|
61
|
+
if (!options.properties.correlationData) {
|
|
62
|
+
options.properties.correlationData = generateCorrelationData();
|
|
63
|
+
}
|
|
64
|
+
if (!options.properties.userProperties) {
|
|
65
|
+
options.properties.userProperties = {};
|
|
66
|
+
}
|
|
67
|
+
if (!options.properties.userProperties.timestamp) {
|
|
68
|
+
options.properties.userProperties.timestamp = new Date().toISOString();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async publishAndWait(pool, topic, buffer, options, responseTopic, contentType) {
|
|
73
|
+
this.ensureV5Properties(options);
|
|
74
|
+
let resolve;
|
|
75
|
+
let reject;
|
|
76
|
+
const responsePromise = new Promise((res, rej) => {
|
|
77
|
+
resolve = res;
|
|
78
|
+
reject = rej;
|
|
79
|
+
});
|
|
80
|
+
let timer;
|
|
81
|
+
const messageHandler = (topic, message, packet) => {
|
|
82
|
+
if (timer)
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
debug(`##### Received response on topic ${topic}`, message.toString());
|
|
85
|
+
resolve(new core_1.Content(contentType, stream_1.Readable.from(message), packet));
|
|
86
|
+
};
|
|
87
|
+
await pool.subscribe(responseTopic, messageHandler, (e) => {
|
|
88
|
+
if (timer)
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
reject(e);
|
|
91
|
+
});
|
|
92
|
+
timer = setTimeout(() => {
|
|
93
|
+
pool.unsubscribe(responseTopic).catch(() => { });
|
|
94
|
+
reject(new Error(`Timeout waiting for response on topic ${responseTopic}`));
|
|
95
|
+
}, this.config.timeout ?? DEFAULT_TIMEOUT);
|
|
96
|
+
try {
|
|
97
|
+
await pool.publish(topic, buffer, options);
|
|
98
|
+
const result = await responsePromise;
|
|
99
|
+
await pool.unsubscribe(responseTopic);
|
|
100
|
+
debug(`##### Finished waiting for response on topic ${responseTopic}`, result);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (timer)
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
await pool.unsubscribe(responseTopic).catch(() => { });
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async subscribeResource(form, next, error, complete) {
|
|
111
|
+
const contentType = form.contentType ?? core_1.ContentSerdes.DEFAULT;
|
|
112
|
+
const requestUri = new url.URL(form.href);
|
|
113
|
+
const brokerUri = `${this.scheme}://` + requestUri.host;
|
|
114
|
+
const _path = requestUri.pathname.slice(1) || '';
|
|
115
|
+
const filter = _path.length ? _path : form["mqv:filter"];
|
|
116
|
+
if (!filter) {
|
|
117
|
+
throw new Error("No topic or filter provided");
|
|
118
|
+
}
|
|
119
|
+
let pool = this.pools.get(brokerUri);
|
|
120
|
+
if (pool == null) {
|
|
121
|
+
pool = new mqtt_message_pool_1.default();
|
|
122
|
+
this.pools.set(brokerUri, pool);
|
|
123
|
+
}
|
|
124
|
+
await pool.connect(brokerUri, this.config);
|
|
125
|
+
await pool.subscribe(filter, (topic, message, packet) => {
|
|
126
|
+
next(new core_1.Content(contentType, stream_1.Readable.from(message), packet));
|
|
127
|
+
if (this.config.protocolVersion === 5 &&
|
|
128
|
+
packet.properties &&
|
|
129
|
+
packet.properties.responseTopic) {
|
|
130
|
+
const correlationData = packet.properties?.correlationData ?? generateCorrelationData();
|
|
131
|
+
const options = {
|
|
132
|
+
properties: {
|
|
133
|
+
correlationData,
|
|
134
|
+
userProperties: {
|
|
135
|
+
timestamp: new Date().toISOString(),
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
pool.publish(packet.properties.responseTopic, Buffer.from(JSON.stringify({ statusCode: 0, statusDesc: "OK" })), options);
|
|
140
|
+
}
|
|
141
|
+
}, (e) => {
|
|
142
|
+
if (error)
|
|
143
|
+
error(e);
|
|
144
|
+
});
|
|
145
|
+
return new Subscription_1.Subscription(() => { });
|
|
146
|
+
}
|
|
147
|
+
async readResource(form) {
|
|
148
|
+
const contentType = form.contentType ?? core_1.ContentSerdes.DEFAULT;
|
|
149
|
+
const requestUri = new url.URL(form.href);
|
|
150
|
+
const brokerUri = `${this.scheme}://` + requestUri.host;
|
|
151
|
+
const _path = requestUri.pathname.slice(1) || '';
|
|
152
|
+
let pool = this.pools.get(brokerUri);
|
|
153
|
+
if (pool == null) {
|
|
154
|
+
pool = new mqtt_message_pool_1.default();
|
|
155
|
+
this.pools.set(brokerUri, pool);
|
|
156
|
+
}
|
|
157
|
+
await pool.connect(brokerUri, this.config);
|
|
158
|
+
const filter = _path.length ? _path : form["mqv:filter"];
|
|
159
|
+
const explicitResponseTopic = form["mqv:properties"] && form["mqv:properties"].responseTopic;
|
|
160
|
+
const useDefaultResponseTopic = this.config.protocolVersion === 5 && !form["mqv:properties"];
|
|
161
|
+
if (explicitResponseTopic || useDefaultResponseTopic) {
|
|
162
|
+
const filterString = typeof filter === "string" ? filter : undefined;
|
|
163
|
+
const responseTopic = explicitResponseTopic || (filterString ? `${filterString}/response` : undefined);
|
|
164
|
+
if (!responseTopic) {
|
|
165
|
+
throw new Error("No response topic could be determined");
|
|
166
|
+
}
|
|
167
|
+
const topic = _path.length ? _path : (form["mqv:topic"] || filterString);
|
|
168
|
+
if (!topic) {
|
|
169
|
+
throw new Error("No topic provided for read request");
|
|
170
|
+
}
|
|
171
|
+
const options = {
|
|
172
|
+
qos: (0, util_1.mapQoS)(form["mqv:qos"]),
|
|
173
|
+
retain: form["mqv:retain"],
|
|
174
|
+
properties: form["mqv:properties"] ?? {
|
|
175
|
+
responseTopic: responseTopic,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
return await this.publishAndWait(pool, topic, Buffer.from(""), options, responseTopic, contentType);
|
|
179
|
+
}
|
|
180
|
+
if (!filter) {
|
|
181
|
+
throw new Error("No topic or filter provided");
|
|
182
|
+
}
|
|
183
|
+
let timer;
|
|
184
|
+
const result = await new Promise((resolve, reject) => {
|
|
185
|
+
timer = setTimeout(() => {
|
|
186
|
+
reject(new Error(`Timeout waiting for message on topic ${filter}`));
|
|
187
|
+
}, this.config.timeout ?? DEFAULT_TIMEOUT);
|
|
188
|
+
pool.subscribe(filter, (topic, message, packet) => {
|
|
189
|
+
clearTimeout(timer);
|
|
190
|
+
resolve(new core_1.Content(contentType, stream_1.Readable.from(message), packet));
|
|
191
|
+
}, (e) => {
|
|
192
|
+
clearTimeout(timer);
|
|
193
|
+
reject(e);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
await pool.unsubscribe(filter);
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
async writeResource(form, content) {
|
|
200
|
+
const requestUri = new url.URL(form.href);
|
|
201
|
+
const brokerUri = `${this.scheme}://${requestUri.host}`;
|
|
202
|
+
const _path = requestUri.pathname.slice(1) || "";
|
|
203
|
+
const topic = _path.length ? _path : form["mqv:topic"] ?? form["mqv:filter"];
|
|
204
|
+
if (!topic) {
|
|
205
|
+
throw new Error("No topic provided");
|
|
206
|
+
}
|
|
207
|
+
if (Array.isArray(topic)) {
|
|
208
|
+
throw new Error("Topic cannot be an array");
|
|
209
|
+
}
|
|
210
|
+
let pool = this.pools.get(brokerUri);
|
|
211
|
+
if (pool == null) {
|
|
212
|
+
pool = new mqtt_message_pool_1.default();
|
|
213
|
+
this.pools.set(brokerUri, pool);
|
|
214
|
+
}
|
|
215
|
+
await pool.connect(brokerUri, this.config);
|
|
216
|
+
const buffer = content === undefined ? Buffer.from("") : await content.toBuffer();
|
|
217
|
+
const options = {
|
|
218
|
+
retain: form["mqv:retain"],
|
|
219
|
+
qos: (0, util_1.mapQoS)(form["mqv:qos"]),
|
|
220
|
+
};
|
|
221
|
+
if (this.config.protocolVersion === 5) {
|
|
222
|
+
options.properties = {
|
|
223
|
+
responseTopic: `${topic}/response`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
if (content && content?.meta?.properties) {
|
|
227
|
+
options.properties = { ...options.properties, ...content.meta.properties };
|
|
228
|
+
if (content.meta.properties.userProperties) {
|
|
229
|
+
options.properties.userProperties = {
|
|
230
|
+
...options.properties.userProperties,
|
|
231
|
+
...content.meta.properties.userProperties,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
this.ensureV5Properties(options);
|
|
236
|
+
if (options.properties && options.properties.responseTopic) {
|
|
237
|
+
return await this.publishAndWait(pool, topic, buffer, options, options.properties.responseTopic, form.contentType ?? core_1.ContentSerdes.DEFAULT);
|
|
238
|
+
}
|
|
239
|
+
await pool.publish(topic, buffer, options);
|
|
240
|
+
}
|
|
241
|
+
async invokeResource(form, content) {
|
|
242
|
+
const requestUri = new url.URL(form.href);
|
|
243
|
+
const brokerUri = `${this.scheme}://${requestUri.host}`;
|
|
244
|
+
const _path = requestUri.pathname.slice(1) || '';
|
|
245
|
+
const topic = _path.length ? _path : form["mqv:topic"] ?? form["mqv:filter"];
|
|
246
|
+
if (!topic) {
|
|
247
|
+
throw new Error("No topic provided");
|
|
248
|
+
}
|
|
249
|
+
if (Array.isArray(topic)) {
|
|
250
|
+
throw new Error("Topic cannot be an array");
|
|
251
|
+
}
|
|
252
|
+
let pool = this.pools.get(brokerUri);
|
|
253
|
+
if (pool == null) {
|
|
254
|
+
pool = new mqtt_message_pool_1.default();
|
|
255
|
+
this.pools.set(brokerUri, pool);
|
|
256
|
+
}
|
|
257
|
+
await pool.connect(brokerUri, this.config);
|
|
258
|
+
const buffer = content === undefined ? Buffer.from("") : await content.toBuffer();
|
|
259
|
+
const options = {
|
|
260
|
+
retain: form["mqv:retain"],
|
|
261
|
+
qos: (0, util_1.mapQoS)(form["mqv:qos"]),
|
|
262
|
+
};
|
|
263
|
+
if (this.config.protocolVersion === 5) {
|
|
264
|
+
options.properties = {
|
|
265
|
+
responseTopic: `${topic}/response`,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (content && content.meta && content.meta.properties) {
|
|
269
|
+
options.properties = { ...options.properties, ...content.meta.properties };
|
|
270
|
+
if (content.meta.properties.userProperties) {
|
|
271
|
+
options.properties.userProperties = {
|
|
272
|
+
...options.properties.userProperties,
|
|
273
|
+
...content.meta.properties.userProperties,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
this.ensureV5Properties(options);
|
|
278
|
+
if (options.properties && options.properties.responseTopic) {
|
|
279
|
+
return await this.publishAndWait(pool, topic, buffer, options, options.properties.responseTopic, form.contentType ?? core_1.ContentSerdes.DEFAULT);
|
|
280
|
+
}
|
|
281
|
+
await pool.publish(topic, buffer, options);
|
|
282
|
+
return new core_1.DefaultContent(stream_1.Readable.from([]));
|
|
283
|
+
}
|
|
284
|
+
async unlinkResource(form) {
|
|
285
|
+
const requestUri = new url.URL(form.href);
|
|
286
|
+
const brokerUri = `${this.scheme}://` + requestUri.host;
|
|
287
|
+
const _path = requestUri.pathname.slice(1) || '';
|
|
288
|
+
const topic = _path.length ? _path : form["mqv:filter"];
|
|
289
|
+
if (!topic) {
|
|
290
|
+
throw new Error("No topic or filter provided");
|
|
291
|
+
}
|
|
292
|
+
const pool = this.pools.get(brokerUri);
|
|
293
|
+
if (pool != null) {
|
|
294
|
+
await pool.unsubscribe(topic);
|
|
295
|
+
debug(`MqttClient unsubscribed from topic '${topic}'`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async requestThingDescription(uri) {
|
|
299
|
+
throw new Error("Method not implemented");
|
|
300
|
+
}
|
|
301
|
+
async start() {
|
|
302
|
+
}
|
|
303
|
+
async stop() {
|
|
304
|
+
for (const pool of this.pools.values()) {
|
|
305
|
+
await pool.end();
|
|
306
|
+
}
|
|
307
|
+
if (this.client)
|
|
308
|
+
return this.client.endAsync();
|
|
309
|
+
}
|
|
310
|
+
setSecurity(metadata, credentials) {
|
|
311
|
+
if (metadata === undefined || !Array.isArray(metadata) || metadata.length === 0) {
|
|
312
|
+
warn(`MqttClient received empty security metadata`);
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
const security = metadata[0];
|
|
316
|
+
if (security.scheme === "basic") {
|
|
317
|
+
if (credentials === undefined) {
|
|
318
|
+
throw new Error("binding-mqtt: security wants to be basic but you have provided no credentials");
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
this.config.username = credentials.username;
|
|
322
|
+
this.config.password = credentials.password;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.default = MqttClient;
|
|
329
|
+
//# sourceMappingURL=mqtt-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mqtt-client.js","sourceRoot":"","sources":["../src/mqtt-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,yCAQwB;AAGxB,yCAA2B;AAC3B,oDAAiD;AACjD,mCAAkC;AAClC,4EAAkD;AAClD,iCAAgC;AAEhC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAa,EAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAErE,MAAM,eAAe,GAAG,IAAI,CAAC;AAO7B,SAAS,uBAAuB;IAC5B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,MAAqB,UAAU;IAI3B,YACY,SAA2B,EAAE,EACrC,MAAM,GAAG,KAAK;QADN,WAAM,GAAN,MAAM,CAAuB;QAHjC,UAAK,GAAiC,IAAI,GAAG,EAAE,CAAC;QAMpD,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;IAIO,kBAAkB,CAAC,OAAmC;QAC1D,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,KAAK,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;gBACtB,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC;YAC5B,CAAC;YACD,IAAI,CAAC,OAAO,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L,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA3ZD,6BA2ZC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MqttClientConfig } from "./mqtt";
|
|
2
|
+
import * as mqtt from "mqtt";
|
|
3
|
+
export default class MQTTMessagePool {
|
|
4
|
+
client?: mqtt.MqttClient;
|
|
5
|
+
subscribers: Map<string, (topic: string, message: Buffer, packet: mqtt.IPublishPacket) => void>;
|
|
6
|
+
errors: Map<string, (error: Error) => void>;
|
|
7
|
+
private connectionPromise?;
|
|
8
|
+
connect(brokerURI: string, config: MqttClientConfig): Promise<void>;
|
|
9
|
+
subscribe(filter: string | string[], callback: (topic: string, message: Buffer, packet: mqtt.IPublishPacket) => void, error: (error: Error) => void): Promise<void>;
|
|
10
|
+
unsubscribe(filter: string | string[]): Promise<void>;
|
|
11
|
+
publish(topic: string, message: Buffer, options?: mqtt.IClientPublishOptions): Promise<void>;
|
|
12
|
+
end(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const core_1 = require("@node-wot/core");
|
|
37
|
+
const mqtt = __importStar(require("mqtt"));
|
|
38
|
+
const { debug, warn } = (0, core_1.createLoggers)("binding-mqtt", "mqtt-message-pool");
|
|
39
|
+
class MQTTMessagePool {
|
|
40
|
+
constructor() {
|
|
41
|
+
this.subscribers = new Map();
|
|
42
|
+
this.errors = new Map();
|
|
43
|
+
}
|
|
44
|
+
async connect(brokerURI, config) {
|
|
45
|
+
if (this.client) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.connectionPromise) {
|
|
49
|
+
await this.connectionPromise;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.connectionPromise = (async () => {
|
|
53
|
+
this.client = await mqtt.connectAsync(brokerURI, config);
|
|
54
|
+
this.client.on("message", (receivedTopic, payload, packet) => {
|
|
55
|
+
debug(`Received MQTT message from ${brokerURI} (topic: ${receivedTopic}, data length: ${payload.length})`, payload, packet.properties);
|
|
56
|
+
this.subscribers.get(receivedTopic)?.(receivedTopic, payload, packet);
|
|
57
|
+
});
|
|
58
|
+
this.client.on("error", (error) => {
|
|
59
|
+
warn(`MQTT client error: ${error.message}`);
|
|
60
|
+
this.errors.forEach((errorCallback) => {
|
|
61
|
+
errorCallback(error);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
})();
|
|
65
|
+
try {
|
|
66
|
+
await this.connectionPromise;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
this.connectionPromise = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async subscribe(filter, callback, error) {
|
|
73
|
+
if (this.client == null) {
|
|
74
|
+
throw new Error("MQTT client is not connected");
|
|
75
|
+
}
|
|
76
|
+
const filters = Array.isArray(filter) ? filter : [filter];
|
|
77
|
+
filters.forEach((f) => {
|
|
78
|
+
if (this.subscribers.has(f)) {
|
|
79
|
+
warn(`Already subscribed to ${f}; we are not supporting multiple subscribers to the same topic`);
|
|
80
|
+
warn(`The subscription will be ignored`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.subscribers.set(f, callback);
|
|
84
|
+
this.errors.set(f, error);
|
|
85
|
+
});
|
|
86
|
+
await this.client.subscribeAsync(filters);
|
|
87
|
+
}
|
|
88
|
+
async unsubscribe(filter) {
|
|
89
|
+
if (this.client == null) {
|
|
90
|
+
throw new Error("MQTT client is not connected");
|
|
91
|
+
}
|
|
92
|
+
const filters = Array.isArray(filter) ? filter : [filter];
|
|
93
|
+
filters.forEach((f) => {
|
|
94
|
+
this.subscribers.delete(f);
|
|
95
|
+
this.errors.delete(f);
|
|
96
|
+
});
|
|
97
|
+
await this.client.unsubscribeAsync(filters);
|
|
98
|
+
}
|
|
99
|
+
async publish(topic, message, options) {
|
|
100
|
+
if (this.client == null) {
|
|
101
|
+
throw new Error("MQTT client is not connected");
|
|
102
|
+
}
|
|
103
|
+
debug(`Publishing MQTT message to ${topic} (data length: ${message.length})`);
|
|
104
|
+
await this.client.publishAsync(topic, message, options);
|
|
105
|
+
}
|
|
106
|
+
async end() {
|
|
107
|
+
for (const filter of this.subscribers.keys()) {
|
|
108
|
+
this.unsubscribe(filter);
|
|
109
|
+
}
|
|
110
|
+
return this.client?.endAsync();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.default = MQTTMessagePool;
|
|
114
|
+
//# sourceMappingURL=mqtt-message-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mqtt-message-pool.js","sourceRoot":"","sources":["../src/mqtt-message-pool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,yCAA+C;AAE/C,2CAA6B;AAE7B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAa,EAAC,cAAc,EAAE,mBAAmB,CAAC,CAAC;AAE3E,MAAqB,eAAe;IAApC;QAEI,gBAAW,GAAuF,IAAI,GAAG,EAAE,CAAC;QAC5G,WAAM,GAAwC,IAAI,GAAG,EAAE,CAAC;IA0F5D,CAAC;IAvFU,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,MAAwB;QAC5D,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,OAAO;QACX,CAAC;QACD,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAEzB,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC7B,OAAO;QACX,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG,CAAC,KAAK,IAAI,EAAE;YACjC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACzD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,aAAqB,EAAE,OAAe,EAAE,MAA2B,EAAE,EAAE;gBAC9F,KAAK,CACD,8BAA8B,SAAS,YAAY,aAAa,kBAAkB,OAAO,CAAC,MAAM,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAClI,CAAC;gBACF,IAAI,CAAC,WAAW,CAAC,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QACD,OAAO,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnC,CAAC;CACJ;AA7FD,kCA6FC"}
|
package/dist/mqtt.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Form } from "@node-wot/core";
|
|
2
|
+
export { default as MqttClient } from "./mqtt-client";
|
|
3
|
+
export { default as MqttClientFactory } from "./mqtt-client-factory";
|
|
4
|
+
export { default as MqttsClientFactory } from "./mqtts-client-factory";
|
|
5
|
+
export { default as MqttBrokerServer } from "./mqtt-broker-server";
|
|
6
|
+
export * from "./mqtt-client";
|
|
7
|
+
export * from "./mqtt-client-factory";
|
|
8
|
+
export * from "./mqtts-client-factory";
|
|
9
|
+
export * from "./mqtt-broker-server";
|
|
10
|
+
export type MqttQoS = "0" | "1" | "2";
|
|
11
|
+
export declare class MqttForm extends Form {
|
|
12
|
+
"mqv:qos"?: MqttQoS;
|
|
13
|
+
"mqv:retain"?: boolean;
|
|
14
|
+
"mqv:topic"?: string;
|
|
15
|
+
"mqv:filter"?: string | string[];
|
|
16
|
+
"mqv:controlPacket"?: "publish" | "subscribe" | "unsubscribe";
|
|
17
|
+
"mqv:properties"?: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface MqttClientConfig {
|
|
22
|
+
username?: string;
|
|
23
|
+
password?: string;
|
|
24
|
+
rejectUnauthorized?: boolean;
|
|
25
|
+
protocolVersion?: 3 | 4 | 5;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface MqttBrokerServerConfig {
|
|
29
|
+
uri: string;
|
|
30
|
+
user?: string;
|
|
31
|
+
psw?: string;
|
|
32
|
+
clientId?: string;
|
|
33
|
+
protocolVersion?: 3 | 4 | 5;
|
|
34
|
+
rejectUnauthorized?: boolean;
|
|
35
|
+
selfHost?: boolean;
|
|
36
|
+
key?: Buffer;
|
|
37
|
+
cert?: Buffer | undefined;
|
|
38
|
+
selfHostAuthentication?: MqttClientConfig[];
|
|
39
|
+
}
|