1. <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
  2. <script type="text/javascript">
  3.  
  4.   // Create a client instance
  5.   client = new Paho.MQTT.Client("m12.cloudmqtt.com", 32705, "123456web_" + parseInt(Math.random() * 1000, 10));
  6.   //Example client = new Paho.MQTT.Client("m11.cloudmqtt.com", 32903, "web_" + parseInt(Math.random() * 100, 10));
  7.  
  8.   // set callback handlers
  9.   client.onConnectionLost = onConnectionLost;
  10.   client.onMessageArrived = onMessageArrived;
  11.   var options = {
  12.     useSSL: true,
  13.     userName: "wwfptvbl",
  14.     password: "hqvP7bmVIU0h",
  15.     onSuccess:onConnect,
  16.     onFailure:doFail
  17.   }
  18.  
  19.   // connect the client
  20.   client.connect(options);
  21.  
  22.   // called when the client connects
  23.   function onConnect() {
  24.     // Once a connection has been made, make a subscription and send a message.
  25.     console.log("onConnect");
  26.     client.subscribe("/cloudmqtt");
  27.     message = new Paho.MQTT.Message("Hello CloudMQTT");
  28.     message.destinationName = "/cloudmqtt";
  29.     client.send(message);
  30.   }
  31.  
  32.   function doFail(e){
  33.     console.log(e);
  34.   }
  35.  
  36.   // called when the client loses its connection
  37.   function onConnectionLost(responseObject) {
  38.     if (responseObject.errorCode !== 0) {
  39.       console.log("onConnectionLost:"+responseObject.errorMessage);
  40.     }
  41.   }
  42.  
  43.   // called when a message arrives
  44.   function onMessageArrived(message) {
  45.     console.log("onMessageArrived:"+message.payloadString);
  46.   }
  47.  
  48.   function next(){
  49.         var message = new Paho.MQTT.Message("next");
  50.         message.destinationName = "hienlt/chanel";
  51.         client.send(message);
  52.   }
  53.  
  54.   function prev(){
  55.         var message = new Paho.MQTT.Message("prev");
  56.         message.destinationName = "hienlt/chanel";
  57.         client.send(message);
  58.   }
  59.  
  60.   function selectChanel(chanelName){
  61.         var message = new Paho.MQTT.Message(chanelName);
  62.         message.destinationName = "hienlt/chanel";
  63.         client.send(message);
  64.   }
  65. </script>
  66.  
  67. <button onclick="next();">Kênh Kế</button><br>
  68. <button onclick="prev();">Kênh Trước</button><br>
  69. <select onchange="selectChanel(this.value)">
  70.     <option value="vtv1">VTV1</option>
  71. <option value="vtv2">VTV2</option>
  72. <option value="vtv3">VTV3</option>
  73. <option value="vtv6">VTV6</option>
  74. <option value="thvl1">THVL1</option>
  75. <option value="vinh-long-2">THVL2</option>
  76. </select>