diff --git a/package.json b/package.json index 18e5f61..6e20674 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "express-session": "^1.12.1", "express-socket.io-session": "^1.3.1", "mustache-express": "^1.2.2", + "shortid": "^2.2.4", "socket.io": "^1.4.0", "underscore": "^1.8.3", "uuid": "^2.0.1" diff --git a/src/app.js b/src/app.js index 8d22c73..ed9f4f6 100644 --- a/src/app.js +++ b/src/app.js @@ -5,6 +5,7 @@ import session from 'express-session'; import Redis from 'connect-redis'; import Io from 'socket.io'; import http from 'http'; +import shortid from 'shortid'; const app = express(); const server = http.createServer(app); @@ -37,7 +38,7 @@ app.use(express.static(__dirname + '/public')); app.get('/', (req, res) => { - res.render('index', {}); + res.render('index', {username: shortid.generate()}); }); @@ -53,7 +54,6 @@ io.on('connection', (socket) => { }); }); - // when the client emits 'add user', this listens and executes socket.on('add user', (username) => { if (addedUser) return; diff --git a/src/public/main.js b/src/public/main.js index 0b5c2c8..e2ec492 100644 --- a/src/public/main.js +++ b/src/public/main.js @@ -13,7 +13,6 @@ $(function() { var $messages = $('.messages'); // Messages area var $inputMessage = $('.inputMessage'); // Input message input box - var $loginPage = $('.login.page'); // The login page var $chatPage = $('.chat.page'); // The chatroom page // Prompt for setting a username @@ -37,13 +36,10 @@ $(function() { // Sets the client's username function setUsername () { - username = cleanInput($usernameInput.val().trim()); - + username = window.username; // If the username is valid if (username) { - $loginPage.fadeOut(); $chatPage.show(); - $loginPage.off('click'); $currentInput = $inputMessage.focus(); // Tell the server your username @@ -211,13 +207,6 @@ $(function() { updateTyping(); }); - // Click events - - // Focus input when clicking anywhere on login page - $loginPage.click(function () { - $currentInput.focus(); - }); - // Focus input when clicking on the message input's border $inputMessage.click(function () { $inputMessage.focus(); @@ -263,4 +252,6 @@ $(function() { socket.on('stop typing', function (data) { removeChatTyping(data); }); + + setUsername() }); diff --git a/src/views/index.mustache b/src/views/index.mustache index bb71cec..1109ffd 100644 --- a/src/views/index.mustache +++ b/src/views/index.mustache @@ -4,6 +4,9 @@ Hi +