(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o
';
messageHistory = '';
//
// Subscribe to our current topic.
//
mqttClient.subscribe(currentlySubscribedTopic);
};
//
// Reconnect handler; update div visibility.
//
window.mqttClientReconnectHandler = function() {
console.log('reconnect');
document.getElementById("connecting-div").style.visibility = 'visible';
document.getElementById("explorer-div").style.visibility = 'hidden';
};
//
// Utility function to determine if a value has been defined.
//
window.isUndefined = function( value ) {
return typeof value === 'undefined' || typeof value === null;
};
//
// Message handler for lifecycle events; create/destroy divs as clients
// connect/disconnect.
//
window.mqttClientMessageHandler = function( topic, payload ) {
console.log('message: '+topic+':'+payload.toString());
messageHistory = messageHistory + topic + ':' + payload.toString() + '';
document.getElementById('subscribe-div').innerHTML = ''+messageHistory+'
';
};
//
// Handle the UI for the current topic subscription
//
window.updateSubscriptionTopic = function() {
var subscribeTopic = document.getElementById('subscribe-topic').value;
document.getElementById('subscribe-div').innerHTML = '';
mqttClient.unsubscribe(currentlySubscribedTopic);
currentlySubscribedTopic = subscribeTopic;
mqttClient.subscribe(currentlySubscribedTopic);
};
//
// Handle the UI to clear the history window
//
window.clearHistory= function() {
if (confirm('Delete message history?') === true) {
document.getElementById('subscribe-div').innerHTML = '
';
messageHistory = '';
}
};
//
// Handle the UI to update the topic we're publishing on
//
window.updatePublishTopic= function() {
};
//
// Handle the UI to update the data we're publishing
//
window.updatePublishData= function() {
var publishText = document.getElementById('publish-data').value;
var publishTopic = document.getElementById('publish-topic').value;
mqttClient.publish( publishTopic, publishText );
document.getElementById('publish-data').value = '';
};
//
// Install connect/reconnect event handlers.
//
mqttClient.on('connect', window.mqttClientConnectHandler);
mqttClient.on('reconnect', window.mqttClientReconnectHandler);
mqttClient.on('message', window.mqttClientMessageHandler);
//
// Initialize divs.
//
document.getElementById('connecting-div').style.visibility = 'visible';
document.getElementById('explorer-div').style.visibility = 'hidden';
document.getElementById('connecting-div').innerHTML = 'attempting to connect to aws iot...
';
},{"./aws-configuration.js":1,"aws-iot-device-sdk":"aws-iot-device-sdk","aws-sdk":"aws-sdk"}]},{},[2]);