Merge branch '489-cmb-rider-realtime-not-displaying' into '488-cmb-live'
Use new mqtt library and enable reconnect #489 See merge request jankstudio/resq!577
This commit is contained in:
commit
59ecc19ef7
2 changed files with 15 additions and 3 deletions
|
|
@ -10,20 +10,32 @@ class MapEventHandler {
|
|||
var client_id = "dash-" + user_id + "-" + d.getMonth() + "-" + d.getDate() + "-" + d.getHours() + "-" + d.getMinutes() + "-" + d.getSeconds() + "-" + d.getMilliseconds();
|
||||
console.log(client_id);
|
||||
|
||||
this.mqtt = new Paho.MQTT.Client(host, port, client_id);
|
||||
let protocol = 'ws';
|
||||
if (this.ssl)
|
||||
protocol = 'wss';
|
||||
|
||||
this.mqtt = new Paho.Client(protocol + '://' + host + ':' + port + '/mqtt', client_id);
|
||||
var options = {
|
||||
useSSL: this.ssl,
|
||||
timeout: 3,
|
||||
timeout: 10,
|
||||
keepAliveInterval: 10,
|
||||
invocationContext: this,
|
||||
onSuccess: this.onConnect.bind(this),
|
||||
reconnect: true
|
||||
};
|
||||
|
||||
this.mqtt.onMessageArrived = this.onMessage.bind(this);
|
||||
this.mqtt.onConnectionLost = this.onConnectionLost;
|
||||
|
||||
console.log('connecting to mqtt server...');
|
||||
this.mqtt.connect(options);
|
||||
}
|
||||
|
||||
onConnectionLost(err) {
|
||||
console.log('mqtt connection lost');
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
onConnect(icontext) {
|
||||
console.log('mqtt connected!');
|
||||
var my = icontext.invocationContext;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
|
||||
{% block scripts %}
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.1.0/paho-mqtt.min.js" type="text/javascript"></script>
|
||||
<script src="{{ asset('assets/js/dashboard_map.js') }}"></script>
|
||||
<script src="{{ asset('assets/js/map_mqtt.js') }}"></script>
|
||||
{% if dashboard_enable == 'true' %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue