mirror of
https://github.com/owntracks/recorder.git
synced 2024-11-15 09:58:40 -07:00
60 lines
1.6 KiB
HTML
60 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8" />
|
|
<title>WebSocket Test</title>
|
|
<script language="javascript" type="text/javascript">
|
|
|
|
var out = function(message) {
|
|
var div = document.createElement('div');
|
|
div.innerHTML = message;
|
|
document.getElementById('output').appendChild(div);
|
|
};
|
|
|
|
window.onload = function() {
|
|
var num_messages = 0;
|
|
|
|
// console.log(JSON.stringify(location));
|
|
// location.host localhost:8080 localhost:8083
|
|
// location.pathname /otr/ws.html /ws.html
|
|
|
|
/* Remove last part of URI to determine path to Websocket in OTR */
|
|
var url = "ws://" + location.host + "/";
|
|
var parts = location.pathname.split('/');
|
|
for (var i = 1; i < parts.length - 1; i++) {
|
|
url = url + parts[i] + "/";
|
|
}
|
|
url = url + "ws";
|
|
console.log(url);
|
|
|
|
websocket = new WebSocket(url);
|
|
websocket.onopen = function(ev) {
|
|
out('CONNECTED');
|
|
var msg = 'Hello.';
|
|
out('SENT: ' + msg);
|
|
websocket.send(msg);
|
|
};
|
|
websocket.onclose = function(ev) {
|
|
out('DISCONNECTED');
|
|
};
|
|
websocket.onmessage = function(ev) {
|
|
if (!ev.data) {
|
|
out('<span style="color: blue;">PING... </span>');
|
|
} else {
|
|
out('<span style="color: blue;">RESPONSE: ' + ev.data + ' </span>');
|
|
num_messages++;
|
|
}
|
|
/*
|
|
if (num_messages > 3) {
|
|
websocket.send('exit');
|
|
} */
|
|
};
|
|
websocket.onerror = function(ev) {
|
|
out('<span style="color: red; ">ERROR: </span> ' + ev.data);
|
|
};
|
|
};
|
|
</script>
|
|
<style> div {font: small Verdana; } </style>
|
|
<h2>OwnTracks Recorder WebSocket Test</h2>
|
|
|
|
<div id="output"></div>
|
|
</html>
|