-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
125 lines (103 loc) · 2.81 KB
/
Copy pathexample.html
File metadata and controls
125 lines (103 loc) · 2.81 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="strest.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
function connect() {
strest = new Strest({
url : $('#websocket_url').val(),
onopen : function(event) {
$('#not_connected').fadeOut();
$('#connected').fadeIn();
},
onclose: function(event) {
$('#not_connected').fadeIn();
}
});
}
function disconnect() {
strest.close();
}
function send() {
var request = strest.sendRequest({uri : $('#uri').val(), method : 'GET'},
function(response) {
addText('#response', '<div class="response">' + response.toString().replace(/\n/g, '<br />') + '</div>');
}
);
var str = '<div class="request">' + request.toString().replace(/\n/g, '<br />') + '</div>';
addText('#request',str);
}
/* Adds some html to the requested element. makes sure there are only max # of elements */
var max = 20; //max elements to show in results box
function addText(element, text) {
var count = $(element).data('count');
if (!count) {
count = 0;
}
$(element).prepend('<div id="content' + count + '">' + text + '</div>');
$(element).find('#content' + (count-max)).remove();
$(element).data('count', count+1);
}
</script>
<style>
#content {
height : 400px;
overflow : auto;
}
#request {
height : 400px;
overflow : auto;
}
#response {
height : 400px;
overflow : auto;
}
.content {
padding : 5px;
margin : 10px;
background-color:#eeeeee;
border:1px dashed black;
}
.response {
padding : 5px;
margin : 10px;
background-color:#eeeeff;
border:1px dashed black;
}
.request {
padding : 5px;
margin : 10px;
background-color:#eeddff;
border:1px dashed black;
}
</style>
</head>
<body>
<b>WEBSOCKET Example</b>
<div id="not_connected">
<input type="text" id="websocket_url" value="ws://localhost:8000/websocket"></input>
<button onclick="connect();">CONNECT</button><br />
</div>
<div id="connected" style="display:none;">
<input type="text" id="uri" value="/ping" />
<button onclick="send();">SEND</button>
<br />
<button onclick="disconnect();">DISCONNECT</button><br />
<table style="width:80%">
<tr>
<td>
<h1>Response Raw</h1>
<div id="response">
</div>
</td>
<td>
<h1>Request Raw</h1>
<div id="request">
</div>
</td>
</tr>
</table>
</div>
</body>
</html>