@robot.com/better-mqtt
Version:
A modern, TypeScript-first MQTT client library that provides a better developer experience with async iterators, shared subscriptions, and React hooks. Better MQTT is a wrapper around the excellent [mqtt.js](https://github.com/mqttjs/MQTT.js) library, enh
110 lines (109 loc) • 3.03 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/mock.ts
var mock_exports = {};
__export(mock_exports, {
BetterMQTT: () => BetterMQTT,
Subscription: () => Subscription,
binaryParser: () => binaryParser,
jsonParser: () => jsonParser,
stringParser: () => stringParser
});
module.exports = __toCommonJS(mock_exports);
var import_ee_ts = require("ee-ts");
function stringParser(message) {
return message.toString("utf8");
}
function jsonParser(message) {
return JSON.parse(message.toString("utf8"));
}
function binaryParser(message) {
return message;
}
var Subscription = class extends import_ee_ts.EventEmitter {
topic;
parser;
constructor(opts) {
super();
this.topic = opts.topic;
this.parser = opts.parser;
}
handleMessage(_message, _topic, _params) {
}
async *[Symbol.asyncIterator]() {
}
end() {
this.emit("end");
}
};
var BetterMQTT = class _BetterMQTT extends import_ee_ts.EventEmitter {
client = new import_ee_ts.EventEmitter();
error = null;
get status() {
return "offline";
}
publish(_topic, _message, _opts) {
}
async publishAsync(_topic, _message) {
return Promise.resolve();
}
publishJson(_topic, _message) {
}
async publishJsonAsync(_topic, _message) {
return Promise.resolve();
}
unsubscribe(_sub) {
}
subscribe(topic, parser) {
return new Subscription({ mqtt: this, topic, parser });
}
subscribeString(topic) {
return this.subscribe(topic, stringParser);
}
subscribeJson(topic) {
return this.subscribe(topic, jsonParser);
}
subscribeBinary(topic) {
return this.subscribe(topic, binaryParser);
}
async subscribeAsync(topic, parser) {
return Promise.resolve(
new Subscription({ mqtt: this, topic, parser })
);
}
async subscribeStringAsync(topic) {
return this.subscribeAsync(topic, stringParser);
}
async subscribeJsonAsync(topic) {
return this.subscribeAsync(topic, jsonParser);
}
async subscribeBinaryAsync(topic) {
return this.subscribeAsync(topic, binaryParser);
}
static async connectAsync(..._args) {
return Promise.resolve(new _BetterMQTT());
}
static connect(..._args) {
return new _BetterMQTT();
}
end() {
this.emit("end");
}
};
//# sourceMappingURL=mock.cjs.map
;