Created
March 21, 2013 07:33
-
-
Save rowanmanning/5211301 to your computer and use it in GitHub Desktop.
Testing out Wesley (https://github.com/adlawson/wesley) from a simple browser client. You can test this with the command line client which comes bundled with Wesley.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Simple Wesley Client</title> | |
</head> | |
<body> | |
<form id="form"> | |
<input type="text" id="input"/> | |
<input type="submit" value="send"/> | |
</form> | |
<ul id="messages"></ul> | |
<script> | |
// Create socket | |
var sock = new WebSocket('ws://localhost:3000/'); | |
// Send a message | |
function sendMessage (msg) { | |
sock.send(msg); | |
}; | |
// Receive a message | |
function receiveMessage (msg) { | |
messageContainer.innerHTML += '<li>' + msg + '</li>'; | |
} | |
// Get elements | |
var form = document.getElementById('form'); | |
var input = document.getElementById('input'); | |
var messageContainer = document.getElementById('messages'); | |
// Bind DOM events | |
form.onsubmit = function () { | |
sendMessage(input.value); | |
input.value = ''; | |
return false; | |
}; | |
// Bind socket events | |
sock.onopen = function () { | |
sock.onmessage = function (evt) { | |
receiveMessage(evt.data); | |
}; | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment