Add checking for SSL_ENABLE for Dashboard. #453

This commit is contained in:
Korina Cordero 2020-07-30 03:23:03 +00:00
parent ca37b72d57
commit 3af78fd49b
4 changed files with 15 additions and 5 deletions

View file

@ -74,3 +74,6 @@ MAPTILER_API_KEY=map_tiler_api_key
# API version
API_VERSION=insert_api_version_here
#SSL_ENABLE for websockets
SSL_ENABLE=set_to_true_or_false

View file

@ -8,3 +8,4 @@ twig:
mqtt_host: "%env(MQTT_WS_HOST)%"
mqtt_port: "%env(MQTT_WS_PORT)%"
dashboard_enable: "%env(DASHBOARD_ENABLE)%"
ssl_enable: "%env(SSL_ENABLE)%"

View file

@ -1,7 +1,8 @@
class MapEventHandler {
constructor(options, dashmap) {
constructor(options, dashmap, ssl) {
this.options = options;
this.dashmap = dashmap;
this.ssl = ssl;
}
connect(user_id, host, port) {
@ -11,7 +12,7 @@ class MapEventHandler {
this.mqtt = new Paho.MQTT.Client(host, port, client_id);
var options = {
// useSSL: true,
useSSL: this.ssl,
timeout: 3,
invocationContext: this,
onSuccess: this.onConnect.bind(this),

View file

@ -45,7 +45,7 @@ function initMap(r_markers, c_markers, icons) {
return dashmap;
}
function initEventHandler(dashmap) {
function initEventHandler(dashmap, icons, ssl) {
var options = {
'track_jo': true,
'track_rider': true,
@ -58,7 +58,7 @@ function initEventHandler(dashmap) {
},
};
var event_handler = new MapEventHandler(options, dashmap);
var event_handler = new MapEventHandler(options, dashmap, ssl);
event_handler.connect('{{ app.user.getID }}', '{{ mqtt_host }}', {{ mqtt_port }});
}
@ -94,8 +94,13 @@ var icons = {
var r_markers = {};
var c_markers = {};
var ssl = false;
{% if ssl_enable == 'true' %}
ssl = true;
{% endif %}
var dashmap = initMap(r_markers, c_markers, icons);
initEventHandler(dashmap, icons);
initEventHandler(dashmap, icons, ssl);
{% endif %}
</script>