summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2012-02-09 17:45:22 -0600
committerJoel Martin <github@martintribe.org>2012-02-09 17:46:47 -0600
commite02b698015f9fe01baba42c17bb87c41cf0f751b (patch)
treef8907758c694f825730306c4ca9d1ea69149b616 /tests
parentbea32aebed82e8710e617b95d180dc32d07a2149 (diff)
downloadwebsockify-e02b698015f9fe01baba42c17bb87c41cf0f751b.tar.gz
Add simple client: tests/client.html.
Diffstat (limited to 'tests')
-rw-r--r--tests/client.html68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/client.html b/tests/client.html
new file mode 100644
index 0000000..18fb200
--- /dev/null
+++ b/tests/client.html
@@ -0,0 +1,68 @@
+<html>
+
+ <head>
+ <title>Websock Simple Client</title>
+ <script src="include/util.js"></script>
+ <script src="include/base64.js"></script>
+ <script src="include/websock.js"></script>
+ </head>
+
+ <body>
+ WebSocket/websockify URI: <input id='target'>&nbsp;
+ <input id='connectButton' type='button' value='Connect'
+ onclick="connect();">
+ <br> <br>
+ <input id='sendText'>&nbsp;
+ <input id='sendButton' type='button' value='Send' disabled
+ onclick="send();">&nbsp;
+ <br> <br>
+ Log:<br><textarea id="messages" cols=80 rows=25></textarea>
+ </body>
+
+
+ <script>
+ var $D = function(id) { return document.getElementById(id); },
+ ws = null, msgs = $D('messages');
+
+ function msg(str) {
+ msgs.innerHTML += str + "\n";
+ msgs.scrollTop = msgs.scrollHeight;
+ }
+
+ function connect() {
+ var uri = $D('target').value;
+ ws = new Websock()
+ msg("connecting to: " + uri);
+ ws.open(uri);
+ ws.on('open', function () {
+ msg("Connected");
+ });
+ ws.on('message', function () {
+ msg("Received: " + ws.rQshiftStr());
+ });
+ ws.on('close', function () {
+ disconnect();
+ msg("Disconnected");
+ });
+
+ $D('connectButton').value = "Disconnect";
+ $D('connectButton').onclick = disconnect;
+ $D('sendButton').disabled = false;
+ }
+
+ function disconnect() {
+ if (ws) { ws.close(); }
+ ws = null;
+
+ $D('connectButton').value = "Connect";
+ $D('connectButton').onclick = connect;
+ $D('sendButton').disabled = true;
+ }
+
+ function send() {
+ msg("Sending: " + $D('sendText').value);
+ ws.send_string($D('sendText').value);
+ };
+ </script>
+
+</html>