Skip to content

Commit

Permalink
Fix MQTT clients when a port number is specified.
Browse files Browse the repository at this point in the history
`location.host` includes the port number, so if one is specified, the
resulting address is invalid as another port number is appended
(hostname:port:9001). Use `location.hostname` instead.

This also allows to configure httpd to serve from a non-default port.
  • Loading branch information
IngmarStein committed Apr 2, 2021
1 parent bc05d9c commit 216379d
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion web/display/cards/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function(){
client.connect(options);
Expand Down
2 changes: 1 addition & 1 deletion web/display/gauges/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function reloadDisplay() {
}

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

function handlevar(mqttmsg, mqttpayload, mqtttopic, htmldiv) {
//console.log('new mqttmsg...');
Expand Down
2 changes: 1 addition & 1 deletion web/display/minimal/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function(){
client.connect(options);
Expand Down
2 changes: 1 addition & 1 deletion web/display/parentwb/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function(){
client.connect(options);
Expand Down
2 changes: 1 addition & 1 deletion web/display/simple/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function reloadDisplay() {
}

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

function handlevar(mqttmsg, mqttpayload, mqtttopic, htmldiv) {
//console.log('new mqttmsg...');
Expand Down
2 changes: 1 addition & 1 deletion web/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function getCol(matrix, col){
}

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

function handlevar(mqttmsg, mqttpayload, mqtttopic, htmldiv) {
//console.log('new mqttmsg...');
Expand Down
2 changes: 1 addition & 1 deletion web/logging/chargelog/ladelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ function getCol(matrix, col){
// run
initLadelog();

var client = new Messaging.Client(location.host,9001, clientuid);
var client = new Messaging.Client(location.hostname,9001, clientuid);
client.onMessageArrived = function (message) {
handlevar(message.destinationName, message.payloadString, thevalues[0], thevalues[1]);
};
Expand Down
2 changes: 1 addition & 1 deletion web/logging/dailychart.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var thevalues = [

];
var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

function handlevar(mqttmsg, mqttpayload) {
if ( mqttmsg.match( /^openWB\/config\/get\/SmartHome\/Devices\/[1-9][0-9]*\/device_name$/i ) ) {
Expand Down
2 changes: 1 addition & 1 deletion web/logging/monthlychart.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var graphMonth = graphDate.substring(4);
var daysInMonth = new Date(graphYear, graphMonth, 0).getDate();

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

function handlevar(mqttmsg, mqttpayload, mqtttopic, htmldiv) {
if ( mqttmsg.match( /^openWB\/config\/get\/SmartHome\/Devices\/[1-9][0-9]*\/device_name$/i ) ) {
Expand Down
2 changes: 1 addition & 1 deletion web/logging/yearlychart.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var graphNextYear = Number(graphDate) + 1;
var monthsInYear = 12;

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

function handlevar(mqttmsg, mqttpayload, mqtttopic, htmldiv) {
if ( mqttmsg.match( /^openWB\/config\/get\/SmartHome\/Devices\/[1-9][0-9]*\/device_name$/i ) ) {
Expand Down
2 changes: 1 addition & 1 deletion web/settings/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function(){
client.connect(options);
Expand Down
2 changes: 1 addition & 1 deletion web/status/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function(){
client.connect(options);
Expand Down
2 changes: 1 addition & 1 deletion web/themes/Gauges/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function(){
client.connect(options);
Expand Down
2 changes: 1 addition & 1 deletion web/themes/colors/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function () {
client.connect(options);
Expand Down
2 changes: 1 addition & 1 deletion web/themes/dark/setupMqttServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ var options = {
};

var clientuid = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
var client = new Messaging.Client(location.host, 9001, clientuid);
var client = new Messaging.Client(location.hostname, 9001, clientuid);

$(document).ready(function(){
client.connect(options);
Expand Down

0 comments on commit 216379d

Please sign in to comment.