Skip to content
Snippets Groups Projects
Commit d96c2ee5 authored by Tommi Penttinen's avatar Tommi Penttinen
Browse files

Added User-Agent logging and separated the JS into its own file

parent a8557522
Branches
No related tags found
No related merge requests found
Pipeline #41905 passed
...@@ -32,28 +32,7 @@ ...@@ -32,28 +32,7 @@
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
TMS_NUMBER = 2050001; TMS_NUMBER = 2050003;
DIRECTION1_TEXT = "Suunta: tulee vasemmalta";
DIRECTION2_TEXT = "Suunta: tulee oikealta";
VEHICLE_CAR = 1;
VEHICLE_TRUCK = 2;
VEHICLE_BUS = 3;
AUDIO = {};
// Wav files are also available.
AUDIO[VEHICLE_CAR] = 'audio/car_marimba.mp3';
AUDIO[VEHICLE_TRUCK] = 'audio/truck_glockenspiel.mp3';
AUDIO[VEHICLE_BUS] = 'audio/bus_mallets.mp3';
SEP = ',';
SERVER = 'wss://smarter-data.tt.utu.fi/ws/';
// SERVER = 'ws://localhost:8080/'
function send_data(ws, direction, vehicle_class) {
ws.send(TMS_NUMBER + SEP + direction + SEP + vehicle_class + SEP + new Date().getTime());
new Audio(AUDIO[vehicle_class]).play();
}
</script> </script>
<!-- Add your site or application content here --> <!-- Add your site or application content here -->
...@@ -91,43 +70,7 @@ ...@@ -91,43 +70,7 @@
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script src="js/smarter-ui.js"></script>
// Varoita, jos piste ei ole valittuna.
document.getElementById('direction1').textContent = DIRECTION1_TEXT;
document.getElementById('direction2').textContent = DIRECTION2_TEXT;
// https://stackoverflow.com/a/23176223
function connect() {
ws = new WebSocket(SERVER);
// ws.onopen = function() {
// // subscribe to some channels
// ws.send(JSON.stringify({
// //.... some message the I must send when I connect ....
// }));
// };
ws.onmessage = function(e) {
console.log('Message:', e.data);
};
ws.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
connect();
}, 1000);
};
ws.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
function send(direction, vehicle,) {
console.log();
}
connect();
</script>
</body> </body>
......
DIRECTION1_TEXT = "Suunta: tulee vasemmalta";
DIRECTION2_TEXT = "Suunta: tulee oikealta";
// Make it easier to read CSV files
USER_AGENT = navigator.userAgent.replace(';', '').replace(',', '');
VEHICLE_CAR = 1;
VEHICLE_TRUCK = 2;
VEHICLE_BUS = 3;
AUDIO = {};
// Wav files are also available.
AUDIO[VEHICLE_CAR] = 'audio/car_marimba.mp3';
AUDIO[VEHICLE_TRUCK] = 'audio/truck_glockenspiel.mp3';
AUDIO[VEHICLE_BUS] = 'audio/bus_mallets.mp3';
SEP = ',';
// SERVER = 'wss://smarter-data.tt.utu.fi/ws/';
SERVER = 'ws://localhost:8080/'
function send_data(ws, direction, vehicle_class) {
ws.send(TMS_NUMBER + SEP + direction + SEP + vehicle_class + SEP + new Date().getTime() + SEP + USER_AGENT);
}
document.getElementById('direction1').textContent = DIRECTION1_TEXT;
document.getElementById('direction2').textContent = DIRECTION2_TEXT;
var heartBeat;
// https://stackoverflow.com/a/23176223
function connect() {
ws = new WebSocket(SERVER);
ws.onopen = function() {
// Initiate hearbeat
heartBeat = setInterval(function() {
console.log("PING");
ws.send('PING' + SEP + new Date().getTime() + SEP + USER_AGENT);
}, 5000);
};
ws.onmessage = function(e) {
console.log('Message:', e.data);
try {
var vehicle_class = JSON.parse(e.data).vehicle_class;
new Audio(AUDIO[vehicle_class]).play();
} catch (exc) {
if (exc instanceof SyntaxError) {
console.log("Not json : " + e.data);
} else {
throw exc;
}
}
};
ws.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
clearInterval(heartBeat);
setTimeout(function() {
connect();
}, 1000);
};
ws.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
connect();
...@@ -32,28 +32,7 @@ ...@@ -32,28 +32,7 @@
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
TMS_NUMBER = 2050001; TMS_NUMBER = 2050002;
DIRECTION1_TEXT = "Suunta: tulee vasemmalta";
DIRECTION2_TEXT = "Suunta: tulee oikealta";
VEHICLE_CAR = 1;
VEHICLE_TRUCK = 2;
VEHICLE_BUS = 3;
AUDIO = {};
// Wav files are also available.
AUDIO[VEHICLE_CAR] = 'audio/car_marimba.mp3';
AUDIO[VEHICLE_TRUCK] = 'audio/truck_glockenspiel.mp3';
AUDIO[VEHICLE_BUS] = 'audio/bus_mallets.mp3';
SEP = ',';
SERVER = 'wss://smarter-data.tt.utu.fi/ws/';
// SERVER = 'ws://localhost:8080/'
function send_data(ws, direction, vehicle_class) {
ws.send(TMS_NUMBER + SEP + direction + SEP + vehicle_class + SEP + new Date().getTime());
new Audio(AUDIO[vehicle_class]).play();
}
</script> </script>
<!-- Add your site or application content here --> <!-- Add your site or application content here -->
...@@ -91,43 +70,7 @@ ...@@ -91,43 +70,7 @@
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script src="js/smarter-ui.js"></script>
// Varoita, jos piste ei ole valittuna.
document.getElementById('direction1').textContent = DIRECTION1_TEXT;
document.getElementById('direction2').textContent = DIRECTION2_TEXT;
// https://stackoverflow.com/a/23176223
function connect() {
ws = new WebSocket(SERVER);
// ws.onopen = function() {
// // subscribe to some channels
// ws.send(JSON.stringify({
// //.... some message the I must send when I connect ....
// }));
// };
ws.onmessage = function(e) {
console.log('Message:', e.data);
};
ws.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
connect();
}, 1000);
};
ws.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
function send(direction, vehicle,) {
console.log();
}
connect();
</script>
</body> </body>
......
...@@ -32,28 +32,7 @@ ...@@ -32,28 +32,7 @@
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
TMS_NUMBER = 2050001; TMS_NUMBER = 2050004;
DIRECTION1_TEXT = "Suunta: tulee vasemmalta";
DIRECTION2_TEXT = "Suunta: tulee oikealta";
VEHICLE_CAR = 1;
VEHICLE_TRUCK = 2;
VEHICLE_BUS = 3;
AUDIO = {};
// Wav files are also available.
AUDIO[VEHICLE_CAR] = 'audio/car_marimba.mp3';
AUDIO[VEHICLE_TRUCK] = 'audio/truck_glockenspiel.mp3';
AUDIO[VEHICLE_BUS] = 'audio/bus_mallets.mp3';
SEP = ',';
SERVER = 'wss://smarter-data.tt.utu.fi/ws/';
// SERVER = 'ws://localhost:8080/'
function send_data(ws, direction, vehicle_class) {
ws.send(TMS_NUMBER + SEP + direction + SEP + vehicle_class + SEP + new Date().getTime());
new Audio(AUDIO[vehicle_class]).play();
}
</script> </script>
<!-- Add your site or application content here --> <!-- Add your site or application content here -->
...@@ -91,43 +70,7 @@ ...@@ -91,43 +70,7 @@
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script src="js/smarter-ui.js"></script>
// Varoita, jos piste ei ole valittuna.
document.getElementById('direction1').textContent = DIRECTION1_TEXT;
document.getElementById('direction2').textContent = DIRECTION2_TEXT;
// https://stackoverflow.com/a/23176223
function connect() {
ws = new WebSocket(SERVER);
// ws.onopen = function() {
// // subscribe to some channels
// ws.send(JSON.stringify({
// //.... some message the I must send when I connect ....
// }));
// };
ws.onmessage = function(e) {
console.log('Message:', e.data);
};
ws.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
connect();
}, 1000);
};
ws.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
function send(direction, vehicle,) {
console.log();
}
connect();
</script>
</body> </body>
......
...@@ -33,27 +33,6 @@ ...@@ -33,27 +33,6 @@
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
TMS_NUMBER = 2050001; TMS_NUMBER = 2050001;
DIRECTION1_TEXT = "Suunta: tulee vasemmalta";
DIRECTION2_TEXT = "Suunta: tulee oikealta";
VEHICLE_CAR = 1;
VEHICLE_TRUCK = 2;
VEHICLE_BUS = 3;
AUDIO = {};
// Wav files are also available.
AUDIO[VEHICLE_CAR] = 'audio/car_marimba.mp3';
AUDIO[VEHICLE_TRUCK] = 'audio/truck_glockenspiel.mp3';
AUDIO[VEHICLE_BUS] = 'audio/bus_mallets.mp3';
SEP = ',';
SERVER = 'wss://smarter-data.tt.utu.fi/ws/';
// SERVER = 'ws://localhost:8080/'
function send_data(ws, direction, vehicle_class) {
ws.send(TMS_NUMBER + SEP + direction + SEP + vehicle_class + SEP + new Date().getTime());
new Audio(AUDIO[vehicle_class]).play();
}
</script> </script>
<!-- Add your site or application content here --> <!-- Add your site or application content here -->
...@@ -91,43 +70,7 @@ ...@@ -91,43 +70,7 @@
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script src="js/smarter-ui.js"></script>
// Varoita, jos piste ei ole valittuna.
document.getElementById('direction1').textContent = DIRECTION1_TEXT;
document.getElementById('direction2').textContent = DIRECTION2_TEXT;
// https://stackoverflow.com/a/23176223
function connect() {
ws = new WebSocket(SERVER);
// ws.onopen = function() {
// // subscribe to some channels
// ws.send(JSON.stringify({
// //.... some message the I must send when I connect ....
// }));
// };
ws.onmessage = function(e) {
console.log('Message:', e.data);
};
ws.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
connect();
}, 1000);
};
ws.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
function send(direction, vehicle,) {
console.log();
}
connect();
</script>
</body> </body>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment