Permalink
Browse files

Moving logic to after connect event fires.

  • Loading branch information...
1 parent 84f8186 commit c842a16fad2df8e1054d2862ea2377daa47a09a3 @DanBUK DanBUK committed Feb 6, 2011
Showing with 18 additions and 16 deletions.
  1. +18 −16 public/index.html
View
34 public/index.html
@@ -32,26 +32,28 @@
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var sock = null;
+ var rv = null;
// var ts = null;
var body_loaded = function () {
sock = new io.Socket();
sock.on('message', handleMessage);
- sock.connect();
- // ts = document.getElementById('timestamp');
- var name = prompt("Please enter your nickname:", "");
- switch (name) {
- case "":
- alert("You did not input a nickname, please reload if you wish to connect.");
- sock.disconnect();
- break;
- case null:
- alert("Login cancelled, please reload if you wish to connect.");
- sock.disconnect();
- break;
- default:
- sock.send(JSON.stringify({ nickname: name }));
- break;
- }
+ sock.connect(function () {
+ // ts = document.getElementById('timestamp');
+ var name = prompt("Please enter your nickname:", "");
+ switch (name) {
+ case "":
+ alert("You did not input a nickname, please reload if you wish to connect.");
+ sock.disconnect();
+ break;
+ case null:
+ alert("Login cancelled, please reload if you wish to connect.");
+ sock.disconnect();
+ break;
+ default:
+ rv = sock.send(JSON.stringify({ nickname: name }));
+ break;
+ }
+ });
};
var handleMessage = function (data) {
var obj = JSON.parse(data);

0 comments on commit c842a16

Please sign in to comment.