npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

paho.mqtt.js

v2.0.5

Published

The Paho JavaScript Client is a browser-based library that uses WebSockets to connect to an MQTT server.

Downloads

376

Readme

Paho.mqtt.js

js-standard-style

The Paho JavaScript Client is a browser-based library that uses WebSockets to connect to an MQTT server. fork from eclipse.paho.mqtt

Only expose a single object name in the global namespace. Everything must go through this module. Global Paho.MQTT module only has a single public function, client, which returns a Paho.MQTT client object given connection details.

The source of the client is in:

    src/mqttws31.js

Send & Receive messages using web browsers.

This programming interface lets a Javascript client application use the MQTT V3.1 or V3.1.1 protocol to connect to an MQTT-supporting messaging server.

Then function supported includes:

  • Connecting to and disconnecting from server.The server is identified by its host name and port number.
  • Specifying options that relate to the communications link with the server, for example the frequency of keep-alive heartbeats, and whether SSL/TLS is required.
  • Subscribing to and receiving messages from MQTT Topics.
  • Publishing messages to MQTT Topics.

The API consists of two main objects:

{@link Paho.MQTT.Client}

This contains methods that provide the functionality of the API, including provision of callbacks that notify the application when a message arrives from or is delivered to the messaging server, or when the status of its connection to the messaging server changes.

{@link Paho.MQTT.Message}

This encapsulates the payload of the message along with various attributes associated with its delivery, in particular the destination to which it has been (or is about to be) sent.

The programming interface validates parameters passed to it, and will throw an Error containing an error message intended for developer use, if it detects an error with any parameter.

Example for browser globals

<script src="./mqttws31js"></script>
client = new Paho.MQTT.Client(location.hostname, Number(location.port), "clientId");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({onSuccess:onConnect});
function onConnect() {
  // Once a connection has been made, make a subscription and send a message.
  console.log("onConnect");
  client.subscribe("/World");
  message = new Paho.MQTT.Message("Hello");
  message.destinationName = "/World";
  client.send(message);
};
function onConnectionLost(responseObject) {
  if (responseObject.errorCode !== 0)
    console.log("onConnectionLost:"+responseObject.errorMessage);
};
function onMessageArrived(message) {
  // If the transmitted data is non-UTF8 formatted data, do not use payloadString
  // It will throw an error from parseUTF8. use payloadBytes instead.
  console.log("onMessageArrived:"+message.payloadString);
  client.disconnect();
};

Example for AMD

define(['paho.mqtt.js'], function (PahoMQTT) {
    client = new PahoMQTT.Client(location.hostname, Number(location.port), "clientId");
})

Example for Node, CommonJS-like

var PahoMQTT = require('paho.mqtt.js')
client = new PahoMQTT.Client(location.hostname, Number(location.port), "clientId");