-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
88 lines (74 loc) · 2.38 KB
/
index.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
<!doctype html>
<html>
<head>
<title>WebSockets Hello World</title>
<meta charset="utf-8" />
<style type="text/css">
body {
text-align: center;
min-width: 500px;
}
</style>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script>
// log function
log = function(data){
$("div#terminal").prepend("</br>" +data);
console.log(data);
};
$(document).ready(function () {
$("div#message_details").hide()
var ws;
$("#open").click(function(evt) {
evt.preventDefault();
var host = "rt.bolidozor.cz";
var port = 5252;
var uri = "/ws";
// create websocket instance
ws = new WebSocket("ws://" + host + ":" + port + uri);
// Handle incoming websocket message callback
ws.onmessage = function(evt) {
log("Message Received: " + evt.data)
alert("message received: " + evt.data);
};
// Close Websocket callback
ws.onclose = function(evt) {
log("***Connection Closed***");
alert("Connection close");
$("#host").css("background", "#ff0000");
$("#port").css("background", "#ff0000");
$("#uri").css("background", "#ff0000");
$("div#message_details").empty();
};
// Open Websocket callback
ws.onopen = function(evt) {
$("#host").css("background", "#00ff00");
$("#port").css("background", "#00ff00");
$("#uri").css("background", "#00ff00");
$("div#message_details").show();
log("***Connection Opened***");
};
});
// Send websocket message function
$("#send").click(function(evt) {
log("Sending Message: "+$("#message").val());
ws.send($("#message").val());
});
});
</script>
</head>
<body>
<h1>RTbolidozor</h1>
<div id="connection_details">
<input type="submit" id="open" value="open" />
</div>
<div id="message_details">
</br></br>
<label for="message">message:</label>
<input type="text" id="message" value="Hello World!"/><br />
<input type="submit" id="send" value="send" />
</div>
<div id="terminal">
</div>
</body>
</html>