forked from VladimirKalachikhin/naiveGPXlogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.html
104 lines (94 loc) · 2.36 KB
/
sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
</head>
<title>Sample naiveGPXlogger control</title>
<body style="font-size:xx-large;">
<br>
Write log to <input type="text", id='toLogFile' size="50rem"> <span style="font-size:50%;">with trailing slash</span><br>
Logging: <input type="checkbox" id="doLogging" onChange="loggingChange();" disabled> <span id="loggingStatus" style="font-size:75%;"></span><br>
<br>
Server return: <span id="message" style="font-size:75%;"></span><br>
<br>
Log file: <span id="logFile" style="font-size:75%;"></span><br>
</body>
<script>
let logging;
console.log('Trying to open socket');
const socket = new WebSocket("ws://localhost:3000/signalk/v1/stream?subscribe=none");
socket.onopen = function(e) {
console.log("socket open");
doLogging.disabled = false;
socket.send(`{
"context": "vessels.self",
"subscribe": [
{
"path": "navigation.trip.logging",
"format": "delta",
"policy": "instant",
"minPeriod": 0
}
]
}`);
};
socket.onmessage = function(event) {
message.innerText = event.data;
if(!event.data.includes('updates')) return;
logging = JSON.parse(event.data).updates[0].values[0].value;
if(logging.status){
doLogging.checked = true;
loggingStatus.innerText = 'Logging ON';
logFile.innerText = logging.logFile;
}
else {
doLogging.checked = false;
loggingStatus.innerText = 'Logging OFF';
logFile.innerText = '';
}
};
socket.onclose = function(event) {
doLogging.disabled = true;
if (event.wasClean) {
console.log(`socket closed cleanly, code=${event.code} reason=${event.reason}`);
}
else {
loggingStatus.innerText = 'socket closed by unknown reason';
console.log('socket closed by unknown reason');
}
};
socket.onerror = function(error) {
console.log(`socket error ${error.message}`);
};
function loggingChange(){
let status, logFile, delta;
if(doLogging.checked) {
status = true;
logFile = toLogFile.value;
}
else {
status = false
logFile = '';
}
delta = {
context: 'vessels.self',
updates: [
{
values: [
{
"path": "navigation.trip.logging",
"value": {
"status": status,
"logFile": logFile,
},
}
],
timestamp: new Date().toISOString(),
}
]
};
socket.send(JSON.stringify(delta));
} // end function loggingChange
</script>
</html>