At line (2), we initialize a Client_ID constant that will identify our JavaScript client with the broker.
Each Paho JavaScript MQTT client must have a unique hostname, port, and client ID combination when it connects to the broker. To ensure we can run multiple web pages on a single computer for testing and demonstration, we use a random number to create a quasi-unique client ID for each web page:
<script type="text/javascript" charset="utf-8">
messagePubCount = 0;
const CLIENT_ID = String(Math.floor(Math.random() * 10e16)) // (2)
const TOPIC = "led"; // (3)
At line (3), we define the TOPIC constant with led, the name of the MQTT topic that we will be subscribing and publishing to shortly. Next, we create our client instance.