Skip to content

Commit f80009a

Browse files
Keith BannisterKeith Bannister
Keith Bannister
authored and
Keith Bannister
committed
Make randomised client ID
1 parent e738246 commit f80009a

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

dashboard.js

+5-14
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,12 @@ let userLastPositions = {}; // dictionary of most recent posObj keyed by user na
2929
function dashboard_init() {
3030

3131
map_init();
32-
3332
temp_chart_init();
3433
location_chart_init();
3534

36-
37-
}
38-
39-
40-
function mqtt_init() {
41-
// Create a client instance
42-
mqtt_client = new Paho.MQTT.Client(loc.hostname, Number(loc.port), "clientId");
43-
44-
// set callback handlers
45-
mqtt_client.onConnectionLost = onConnectionLost;
46-
mqtt_client.onMessageArrived = onMessageArrived;
4735
}
4836

4937

50-
5138
function setStatus(msg) {
5239
// statusText.textContent = msg;
5340
console.log("Status changed:", msg);
@@ -71,7 +58,11 @@ function mqtt_login() {
7158
// setStatus("Connecting...");
7259
$('#debug_logs').append("MQTT Client connecting...");
7360

74-
const clientId = username;
61+
// Make a unique-ish, random client ID
62+
const randint = Math.floor(Math.random()*1024*1024);
63+
// Client ID must be unique otherwise it disconnects the other client.
64+
const clientId = `${username}-${randint}`;
65+
7566
// Create a client instance
7667
mqtt_client = new Paho.MQTT.Client(loc.hostname, Number(loc.port), clientId);
7768

0 commit comments

Comments
 (0)