MQTT.js Download for Ionic/Angular Client Use

What is MQQT.js

MQTT.js is a client library for the MQTT protocol, written in JavaScript for node.js and the browser.

You can download the client/browser version here:

-> browserMqtt.js

Usage

You can then use mqtt.js in the browser with the same API that nodeJS uses.

<html>
<head>
  <title>test Ws mqtt.js</title>
</head>
<body>
<script src="./browserMqtt.js"></script>
<script>
      var client = mqtt.connect() // you add a ws:// url here
      client.subscribe("mqtt/demo")

      client.on("message", function (topic, payload) {
        alert([topic, payload].join(": "))
        client.end()
      })

      client.publish("mqtt/demo", "hello world!")
    </script>
</body>
</html>

Source: https://github.com/mqttjs/MQTT.js