Permalink
Browse files

Fix indentation and some other improvements

  • Loading branch information...
simonewebdesign committed Dec 18, 2012
1 parent 15cbe21 commit eb60b0718e2ec21be2ec3536e361f07aa618bcec
Showing with 15 additions and 55 deletions.
  1. +11 −53 index.html
  2. +4 −2 ws_server.js
View
@@ -1,59 +1,17 @@
<!doctype html>
<html>
<head>
- <meta charset='utf-8'>
- <title>WebSocket Client</title>
+ <meta charset="utf-8">
+ <title>WebSocket Client Demo</title>
</head>
<body>
-<h1>WebSocket Client</h1>
-<p>Open your web console to see the response!</p>
-<form>
- <label for="message">Send a message</label>
- <input id="message" name="message" type="text">
- <button id="send" name="send">Send</button>
-</form>
-
-<!-- latest jQuery -->
-<script src="http://code.jquery.com/jquery-latest.min.js"></script>
-
-<script>
-var ws = new WebSocket("ws://localhost:1337");
-
-ws.onopen = function(ev) {
- console.log('Connection opened.');
-}
-
-ws.onmessage = function(ev) {
- console.log('Response from server: ' + ev.data);
-}
-
-ws.onclose = function(ev) {
- console.log('Connection closed.');
-}
-
-ws.onerror = function(ev) {
- console.log('An error occurred. Sorry for that.');
-}
-
-WebSocket.prototype.sendMessage = function(msg) {
- this.send(msg);
- console.log('Message sent: ' + msg);
-}
-
-var sendBtn = document.getElementById('send');
-var message = document.getElementById('message').value;
-
-sendBtn.addEventListener('click', function(ev) {
- ws.sendMessage(message);
- ev.preventDefault();
-});
-
-/*
-$('#send').on('click', function(ev) {
- ws.sendMessage( $('#message').val() );
- ev.preventDefault();
-});
-*/
-</script>
+ <h1>WebSocket Client</h1>
+ <p>Open the JavaScript console to see the response!</p>
+ <form>
+ <label for="message">Send a message</label>
+ <input id="message" name="message" type="text">
+ <button id="send" name="send">Send</button>
+ </form>
+ <script src="ws_client.js"></script>
</body>
-</html>
+</html>
View
@@ -18,7 +18,8 @@ wsServer = new WebSocketServer({
});
function isAllowedOrigin(origin) {
- if (origin === 'http://localhost') {
+ valid_origins = ['http://localhost', '127.0.0.1'];
+ if (valid_origins.indexOf(origin) != -1) {
console.log('Connection accepted from origin ' + origin);
return true;
}
@@ -56,7 +57,8 @@ wsServer.on('request', function(request) {
response = 'Keep typing, man. Keep typing.';
break;
default:
- response = "Hello. Uh... what am I supposed to do with '" + message.utf8Data + "'?";
+ response = "Hello. Uh... what am I supposed to do with '" +
+ message.utf8Data + "'?";
}
connection.sendUTF(response);
}

0 comments on commit eb60b07

Please sign in to comment.