{"id":32264683,"url":"https://github.com/orbitbot/web-mqtt-client","last_synced_at":"2026-02-21T07:02:12.448Z","repository":{"id":57741786,"uuid":"51622163","full_name":"orbitbot/web-mqtt-client","owner":"orbitbot","description":"A better MQTT API for the browser","archived":false,"fork":false,"pushed_at":"2017-06-17T09:18:04.000Z","size":512,"stargazers_count":51,"open_issues_count":0,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-23T23:08:32.450Z","etag":null,"topics":["eclipse-paho","mqtt","mqtt-client","paho","utility","utility-wrapper"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orbitbot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-12T22:59:37.000Z","updated_at":"2025-06-18T01:34:24.000Z","dependencies_parsed_at":"2022-09-09T12:03:02.702Z","dependency_job_id":null,"html_url":"https://github.com/orbitbot/web-mqtt-client","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/orbitbot/web-mqtt-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitbot%2Fweb-mqtt-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitbot%2Fweb-mqtt-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitbot%2Fweb-mqtt-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitbot%2Fweb-mqtt-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orbitbot","download_url":"https://codeload.github.com/orbitbot/web-mqtt-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitbot%2Fweb-mqtt-client/sbom","scorecard":{"id":711677,"data":{"date":"2025-08-11","repo":{"name":"github.com/orbitbot/web-mqtt-client","commit":"ef5ac26a14f8df11486807daafe9b029e7220061"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 1/28 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: ISC License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T08:20:52.543Z","repository_id":57741786,"created_at":"2025-08-22T08:20:52.543Z","updated_at":"2025-08-22T08:20:52.543Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29675916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eclipse-paho","mqtt","mqtt-client","paho","utility","utility-wrapper"],"created_at":"2025-10-22T21:04:42.186Z","updated_at":"2026-02-21T07:02:12.443Z","avatar_url":"https://github.com/orbitbot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# web-mqtt-client\n\u003e A better MQTT API for the browser\n\n`web-mqtt-client` is a wrapper around the [Eclipse Paho MQTT javascript client](https://eclipse.org/paho/clients/js/), and offers an improved programmatic API somewhat similar to [MQTT.js](https://github.com/mqttjs/MQTT.js) in a much smaller package than the latter browserified. Further improvements will also be implemented as this library matures (see Roadmap below).\n\nAn example of this library in use is available on [`gh-pages`](https://orbitbot.github.io/web-mqtt-client), source code and resources for the example under the `demo/` folder.\n\n\u003cbr\u003e\n\n### Installation\n\n```sh\n$ npm install web-mqtt-client\n$ bower install web-mqtt-client\n```\n\nIn addition to `mqtt-client.js`, you will also need to add `mqttws31.js` from [Eclipse Paho](https://eclipse.org/paho/clients/js/) to your html, eg.\n\n```html\n\u003cscript src=\"path/to/mqttws31.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"path/to/mqtt-client.js\"\u003e\u003c/script\u003e\n```\n\n`mqtt-client.js` expects the globals from Eclipse Paho to be available when initialized, so the order of evaluation matters. When the scripts have been evaluated, `web-mqtt-client` is available through the `MqttClient` global.\n\n\u003cbr\u003e\n\n### Usage\n\nAn MQTT client is intialized with the call to `new MqttClient` with a configuration object. The configuration object is required to contain `host` and `port`, but accepts multiple other values:\n\n| Parameter     | Mandatory | Type          | Default   |\n|:--------------|:----------|:--------------|:----------|\n| `host`        | required  | String        |           |\n| `port`        | required  | Number        |           |\n| `clientId`    | optional  | String        | generated |\n| `timeout`     | optional  | Number        | 10        |\n| `keepalive`   | optional  | Number        | 30        |\n| `mqttVersion` | optional  | Number [3,4]  |           |\n| `username`    | optional  | String        |           |\n| `password`    | optional  | String        |           |\n| `ssl`         | optional  | boolean       |           |\n| `clean`       | optional  | boolean       |           |\n| `will`        | optional  | Object        |           |\n| `reconnect`   | optional  | Number        | undefined |\n\n`reconnect` is the time to wait in milliseconds before trying to connect if a client loses its connection to the broker. If not defined, automatic reconnection is disabled.\n\nSome further details for the parameters can be found in the [Paho documentation](http://www.eclipse.org/paho/files/jsdoc/symbols/Paho.MQTT.Client.html).\n\nExample:\n\n```js\nvar client = new MqttClient({\n  host : 'some.domain.tld/mqtt',\n  port : 5678,\n  will : {\n    topic   : 'farewells',\n    payload : 'So long!',\n  }\n});\n```\n\nThe `will` object is specified as follows and has the typical MQTT message attributes\n\n| field     | Mandatory | Type                  | Default   |\n|:----------|:----------|:----------------------|:----------|\n| `topic`   | required  | String                |           |\n| `payload` | required  | String or ArrayBuffer |           |\n| `qos`     | optional  | Number [0,1,2]        | 0         |\n| `retain`  | optional  | boolean               | false     |\n\n\u003cbr\u003e\n\n##### Client API\n\nA client `var client = new MqttClient(opts)` initialized as above will have\n\n###### Fields:\n\n**`client.connected` : `boolean`**\n\nSimplified connection state, ie. `true` if connected or `false` otherwise. If you need more detailed connection state tracking, this can be implemented by attaching callbacks to connection lifecycle events (see below).\n\n\u003cbr\u003e\n\n###### Methods:\n\n**`client.connect() ⇒ client`**\n\nConnect client to the broker specified in the configuration object.\n\n**`client.disconnect() ⇒ undefined`**\n\nDisconnect from the currently connected broker.\n\n**`client.subscribe(topic, function callback(error, granted) { }) ⇒ undefined`**\n\n**`client.subscribe(topic, qos, function callback(error, granted) { }) ⇒ undefined`**\n\nSubscribe to `topic`. `qos` and `callback` are optional, if two parameters are used the second one is assumed to be a callback function and the default QoS 0 is used. Note that if QoS 0 is passed, the broker does not actually acknowledge receiving the subscription message, so the callback firing essentially only means that the Paho library has processed the function call.\n\nThe callback function parameter `error` is the error object returned by Paho, and `granted` is the QoS level (0,1 or 2) granted by the broker.\n\n\n**`client.unsubscribe(topic, function callback (error) { }) ⇒ undefined`**\n\nUnsubscribe from `topic`. The optional `callback` will be fired when the broker acknowledges the request.\n\nThe callback function gets a single error parameter if something went wrong, containing the error object returned by Paho.\n\n**`client.publish(topic, payload, options, callback) ⇒ undefined`**\n\nPublish `payload` to `topic`, `callback` will be fired when the broker acknowledges the request. **NB.** if qos is 0 and a callback is provided functionality is identical to the `subscribe` callback. The callback getting triggered may also be broker-dependant, so verify the functionality before depending on a callback being fired.\n\n`options` are optional and can specify the following:\n```js\n{\n    qos    : \u003coptional\u003e - default 0,\n    retain : \u003coptional\u003e - default false,\n}\n```\n\n\u003cbr\u003e\n\n\nThe following event methods are used to attach callbacks to the events specified in the next section.\n\n**`client.bind(event, callback) ⇒ client`**\n\nAttaches `callback` to be called whenever `event` is triggered by the library. See Events below for possible events.\n\n**`client.on(event, callback) ⇒ client`**\n\nSynonym for `client.bind`.\n\n**`client.unbind(event, callback) ⇒ client`**\n\nDe-register `callback` from being called when `event` is triggered. Previously registered callbacks must be named variables for this to work, otherwise the method will fail silently.\n\n**`client.once(event, callback) ⇒ client`**\n\nJust like `bind`/`on`, but is automatically de-registered after being called.\n\n\u003cbr\u003e\n\n##### Messages API\n\nThe client has a utility API that compliments the `client.on('message', callback)` pattern.\n\n**`client.messages.bind(topic, qos, callback, force) ⇒ client`**\n\nAttaches `callback` to be called whenever a message arrives that match the MQTT `topic`. The topic string supports both MQTT wildcard characters, so it can be used fairly flexibly, but verify that your usecase is covered with `client.convertTopic()`. `qos` and `force` parameters are optional, if not supplied `qos` is 0. By default, a MQTT subscribe signal is not sent to the broker if there is already a callback registered with the Messages API that has the same exact string as its topic (wildcard matching is not attempted), `force` can be used to cirumvent this behavior f.e. when `qos` should change or similar.\n\n**`client.messages.on(topic, qos, callback, force) ⇒ client`**\n\nSynonym for `client.messages.bind`.\n\n**`client.messages.unbind(callback) ⇒ client`**\n\nDe-register `callback` from being called when incoming messages that matches its `topic` arrive. Previously registered callbacks must be named variables for this to work, otherwise the method will fail silently. For correct functionality, it's also important that the `topic` property added to `callback` in subscribe is not modified elsewhere in code (it should match the string passed when the callback was attached).\n\n\n\u003cbr\u003e\n\n###### Utils:\n\n**`client.convertTopic(topic) ⇒ RegEx`**\n\nConverts string `topic` to a matching regular expression that supports the MQTT topic wildcards (`#` and `+`), used internally. The implementation is not bullet-proof, see tests and verify that the functionality matches your use-case.\n\n\u003cbr\u003e\n\n###### Events:\n\nThe client emits the following events\n\n- `'connecting'`: client has started connecting to a broker\n- `'connect'`: client has successfully connected to broker\n- `'disconnect'`: client was disconnected from broker for whatever reason\n- `'offline'`: client is disconnected and no automatic reconnection attempts will be made\n- `'message'`: client received an MQTT message\n\n\nAs outlined above, callbacks can be attached to these events through `client.on` or `client.bind` and removed with `client.unbind`.\n\n```js\nclient\n  .on('connecting', function() { console.log('connecting...'); })\n  .on('connect',    function() { console.log(\"hooraah, I'm connected\"); })\n  .on('disconnect', function() { console.log('oh noes!'); })\n  .on('offline',    function() { console.log('stopped trying, call connect manually'); });\n\nclient.on('message', console.log.bind(console, 'MQTT message arrived: '));\n```\n\nThe callback attached to the `message` event has the following signature\n\n```js\nclient.on('message', function handleMessage(topic, payload, details) {\n  // ..\n});\n```\n\n- `payload` is either the UTF-8 encoded String in the message if parsed by Paho, or the payload as an ArrayBuffer\n- `details` is an object containing\n\n```js\n{\n    topic     : /* String */,\n    qos       : /* 0 | 1 | 2 */,\n    retained  : /* boolean  */,\n    payload   : /* payloadBytes */,\n    duplicate : /* boolean */,\n}\n```\n\nThe meaning of the fields are explained in the [Paho documentation](http://www.eclipse.org/paho/files/jsdoc/symbols/Paho.MQTT.Message.html).\n\n\u003cbr\u003e\n\n### Colophon\n\nThe event emitter pattern that `web-mqtt-client` uses is based on [microevent.js](https://github.com/jeromeetienne/microevent.js).\n\n### License\n\n`web-mqtt-client` is ISC licensed.\n\n\u003cbr\u003e\n\n### Roadmap \u0026 Changelog\n\n**1.3.1**\n\n- [x] fix for #3, throwing errors when trying to parse some string messages\n\n**1.3.0**\n\n- [x] Messages API automatically subscribes and unsubscribes from topics\n- [x] filter subscription/unsubscription calls to broker if topic has other callbacks\n- [x] can manually force subscribe or unsubscribe calls using Messages API\n\n**1.2.1**\n\n- [x] fix for #2 Cannot send retained messages using MqttClient's publish method\n\n**1.2.0**\n\n- [x] separate messages event API\n- [x] MQTT topic regex support\n\n**1.1.0**\n\n- [x] automatic reconnection interval\n- [x] extended connection lifecycle callbacks\n- [ ] ~~optional logging support~~ dropped, since it's currently easy to attach logging to callbacks if needed\n- [x] integration tests against Mosca\n\n**1.0.1**\n\n- [x] improve test coverage\n- [x] fix publish API (call w/o payload, options, callback)\n- [x] subscribe API (document callback, callback this reference)\n- [x] unsubscribe API (document callback, callback this reference)\n\n**1.0.0**\n\n- [x] unit test setup\n- [x] CI test configuration (travis)\n- [x] eslint configuration\n- [x] test coverage x\n- [x] lightweight API documentation\n- [x] publish demo to gh-pages\n\n**0.9.0**\n\n- [x] randomly generated clientIds\n- [x] subscribe / unsubscribe API\n- [x] event for incoming messages\n- [x] publish API\n- [x] lwt support\n- [x] minfied build\n- [x] public release npm/bower\n\n**Future**\n\n- [ ] ~~reconnection callback~~ abandoned, can easily be implemented with attaching a function that calls `client.connect()` to the `offline` event\n- [ ] better example in README\n- [ ] rewrite Paho Errors\n- [ ] proper linting config\n- [ ] test coverage x\n- [ ] ~~filter sub/unsub is QoS-aware~~\n- [ ] ~~automatic resubscription of topics on reconnect~~\n- [ ] optimize compression\n- [ ] provide sourcemaps\n\n\u003cbr\u003e\n\n### Notes\n\n- Paho documentation http://www.eclipse.org/paho/files/jsdoc/index.html\n- promise support for methods? or example for wrapping\n- publish callback if qos 0 is essentially nothing more than a message that message has been delivered to Paho lib...\n- piggyback on Paho error reporting or do own validation?\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbitbot%2Fweb-mqtt-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forbitbot%2Fweb-mqtt-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbitbot%2Fweb-mqtt-client/lists"}