Skip to content

Commit d4ea390

Browse files
Update belchertown.js.tmpl
edited the MQTT connection function to detect if the client is using https, and if so, connect to mqtt via tls. (requires mqtt_websockets_port_ssl to be specified in config) This change allows the skin to be served up without regard to http/https, works equally well either way.
1 parent 4c3cdc8 commit d4ea390

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

skins/Belchertown/js/belchertown.js.tmpl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -617,21 +617,24 @@ function connect() {
617617
jQuery(".offlineMarker").hide();
618618
jQuery(".loadingMarker").show();
619619

620-
client = new Paho.MQTT.Client("$Extras.mqtt_websockets_host", $Extras.mqtt_websockets_port, mqttclient);
621-
client.onConnectionLost = onConnectionLost;
622-
client.onMessageArrived = onMessageArrived;
623-
var options = {
624-
#if $Extras.has_key("mqtt_websockets_ssl") and $Extras.mqtt_websockets_ssl == '1'
625-
useSSL: true,
626-
#else
627-
useSSL: false,
628-
#end if
629-
onSuccess:onConnect,
630-
onFailure:onFailure
631-
}
620+
if (location.protocol === 'https:')
621+
{
622+
client = new Paho.MQTT.Client("$Extras.mqtt_websockets_host", $Extras.mqtt_websockets_port_ssl, mqttclient);
623+
client.onConnectionLost = onConnectionLost;
624+
client.onMessageArrived = onMessageArrived;
625+
var options = {useSSL: true,onSuccess:onConnect,onFailure:onFailure}
626+
}
627+
else
628+
{
629+
client = new Paho.MQTT.Client("$Extras.mqtt_websockets_host", $Extras.mqtt_websockets_port, mqttclient);
630+
client.onConnectionLost = onConnectionLost;
631+
client.onMessageArrived = onMessageArrived;
632+
var options = {useSSL: false,onSuccess:onConnect,onFailure:onFailure}
633+
}
632634
client.connect( options );
633635
}
634636

637+
635638
// MQTT connect callback
636639
function onConnect() {
637640
belchertown_debug("MQTT Connected. Subscribing.");

0 commit comments

Comments
 (0)