diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-08-06 01:15:05 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-08-06 01:15:05 -0400 |
| commit | 78f7f5ae58d9357e240873c137e8940e0647fbbd (patch) | |
| tree | 932abd16a89c2f72aec03455fcebef262f7d522b /public/js/lib | |
| parent | 20e62e8d18905a778f8b347103f9352fab38908e (diff) | |
userlist stuph
Diffstat (limited to 'public/js/lib')
| -rw-r--r-- | public/js/lib/views/room/chat.js | 2 | ||||
| -rw-r--r-- | public/js/lib/views/room/room.js | 19 | ||||
| -rw-r--r-- | public/js/lib/views/room/userlist.js | 20 |
3 files changed, 28 insertions, 13 deletions
diff --git a/public/js/lib/views/room/chat.js b/public/js/lib/views/room/chat.js index 058d02d..222522f 100644 --- a/public/js/lib/views/room/chat.js +++ b/public/js/lib/views/room/chat.js @@ -9,7 +9,7 @@ var ChatView = View.extend({ "scroll #messages": "scroll", }, - initialize: function(){ + initialize: function(socket){ var $msg = this.$msg = this.$("#message") this.$messages = this.$("#messages") this.messages = this.$messages.get(0) diff --git a/public/js/lib/views/room/room.js b/public/js/lib/views/room/room.js index 10c4d08..3b3b253 100644 --- a/public/js/lib/views/room/room.js +++ b/public/js/lib/views/room/room.js @@ -6,20 +6,21 @@ var RoomView = View.extend({ }, initialize: function(name){ - this.name = name - chat = this.chatView = new ChatView () - this.userlist = new UserlistView () app.socket = ws.connect(name) + + var base = this + this.name = name + chat = this.chatView = new ChatView (socket) + this.userlist = new UserlistView (socket) + app.socket.emit("join", { nick: user.username }) - - app.socket.on("joined", function(msgs){ - msgs && msgs.forEach(chat.add) - }) - app.socket.on("messages", function(msgs){ - msgs && msgs.forEach(chat.add) + app.socket.on("welcome", function(room){ + room.messages.forEach(chat.add) + base.userlist.users = room.users + base.userlist.update() }) app.socket.on("message", function(msg){ diff --git a/public/js/lib/views/room/userlist.js b/public/js/lib/views/room/userlist.js index d638a02..600f647 100644 --- a/public/js/lib/views/room/userlist.js +++ b/public/js/lib/views/room/userlist.js @@ -5,11 +5,25 @@ var UserlistView = View.extend({ events: { }, - initialize: function(){ + users: {}, + initialize: function(socket){ + var base = this + app.socket.on("joined", function(data){ + base.users[data.nick] = true + base.update() + }) + app.socket.on("parted", function(data){ + delete base.users[data.nick] + base.update() + }) }, - update: function(users){ - + update: function(){ + base.el.empty() + Object.keys(base.users).sort().forEach(function(nick){ + var el = document.createElement("div") + base.el.appendChild(el) + }) }, })
\ No newline at end of file |
