Skip to content

Commit

Permalink
docs: clarify differences between browser and node
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Jan 10, 2024
1 parent eaf82cd commit c8b6695
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,22 @@ Closes the Store.

## Browser

> [!IMPORTANT]
> The only protocol supported in the browser is MQTT over WebSockets, so you must use `ws://` or `wss://` URLs.
While in NodeJS the [ws](https://www.npmjs.com/package/ws) module is used, in the browser the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) is used.

This is totally transparent to users except for the following:

- The `wsOption` is not supported in the browser.
- Browser doesn't allow to catch many WebSocket errors for [security reasons](https://stackoverflow.com/a/31003057) as:

> Access to this information could allow a malicious Web page to gain information about your network, so they require browsers report all connection-time errors in an indistinguishable way.
So listening for `client.on('error')` may not catch all the errors you would get in NodeJS env.

### Bundle

MQTT.js is bundled using [esbuild](https://esbuild.github.io/). It is tested working with all bundlers like Webpack, Vite and React.

You can find all mqtt bundles versions in `dist` folder:
Expand Down Expand Up @@ -838,8 +854,6 @@ The MQTT.js bundle is available through <http://unpkg.com>, specifically
at <https://unpkg.com/mqtt/dist/mqtt.min.js>.
See <http://unpkg.com> for the full documentation on version ranges.

**Be sure to only use this bundle with `ws` or `wss` URLs in the browser. Others URL types will likey fail**

<a name="qos"></a>

## About QoS
Expand Down

0 comments on commit c8b6695

Please sign in to comment.