Permalink
Browse files

Using first message

  • Loading branch information...
1 parent d427e4a commit 0a3d082fab89220d2304e6318efa98d457537c3e @DanBUK DanBUK committed Feb 6, 2011
Showing with 22 additions and 18 deletions.
  1. +1 −1 irc.js
  2. +21 −17 public/index.html
View
2 irc.js
@@ -21,7 +21,7 @@ var socket = io.listen(app, {
});
socket.on('connection', function(client) {
-
+ client.send(JSON.stringify({connected: true}));
client.on('message', function(data) {
console.log(data);
});
View
@@ -33,31 +33,35 @@
<script type="text/javascript">
var sock = null;
var rv = null;
+ var nickname = null;
// var ts = null;
var body_loaded = function () {
sock = new io.Socket();
sock.on('message', handleMessage);
- sock.on('connection', 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;
- }
- });
sock.connect();
};
+ var getNickname = function () {
+ 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:
+ return name;
+ break;
+ }
+ }
var handleMessage = function (data) {
var obj = JSON.parse(data);
+ if (nickname === null) {
+ var tmp = getNickname();
+ // rv = sock.send(JSON.stringify({ nickname: name }));
+ }
// ts.textContent = obj.timestamp;
};
</script>

0 comments on commit 0a3d082

Please sign in to comment.