diff options
| -rw-r--r-- | public/css/css.css | 2 | ||||
| -rw-r--r-- | public/js/index.js | 16 | ||||
| -rw-r--r-- | public/js/lib/views/index.js | 22 | ||||
| -rw-r--r-- | public/js/lib/views/lobby/index.js | 9 | ||||
| -rw-r--r-- | public/js/lib/views/room/index.js | 9 | ||||
| -rw-r--r-- | public/js/lib/ws.js | 7 | ||||
| -rw-r--r-- | server/index.js | 6 | ||||
| -rw-r--r-- | server/ws.js | 37 | ||||
| -rw-r--r-- | views/pages/lobby.ejs (renamed from views/pages/index.ejs) | 5 | ||||
| -rw-r--r-- | views/pages/room.ejs | 6 | ||||
| -rw-r--r-- | views/partials/scripts.ejs | 1 |
11 files changed, 112 insertions, 8 deletions
diff --git a/public/css/css.css b/public/css/css.css index ec56cfe..1fce66f 100644 --- a/public/css/css.css +++ b/public/css/css.css @@ -1,5 +1,5 @@ html,body{width:100%;height:100%;margin:0;padding:0;} -#bg{position:absolute;top:0;left:0;z-index:-1;width:100%;height:100%;background-color:black;z-index:-1;background-position:center center;background-size:contain;} +#bg{position:absolute;top:0;left:0;z-index:-1;width:100%;height:100%;background-color:white;z-index:-1;background-position:center center;background-size:contain;} #bg.tile{background-size:auto auto;} html{background:black;} body{background:transparent;} diff --git a/public/js/index.js b/public/js/index.js index 560a2a1..30f5975 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2,11 +2,25 @@ var app = (function(){ var app = {} app.init = function(){ - // ws.connect() + user.init() + + app.socket = ws.connect() + + app.router = new SiteRouter () $(window).on("focus", app.focus) $(window).on("blur", app.blur) } + app.focused = true + + app.focus = function(){ + app.focused = true + } + + app.blur = function(){ + app.focused = false + } + document.addEventListener('DOMContentLoaded', app.init) })() diff --git a/public/js/lib/views/index.js b/public/js/lib/views/index.js new file mode 100644 index 0000000..d96bffb --- /dev/null +++ b/public/js/lib/views/index.js @@ -0,0 +1,22 @@ +var SiteRouter = Router.extend({ + el: "body", + + events: { + }, + + routes: { + "/": 'lobby', + "/v/:name": 'room', + }, + + initialize: function(){ + this.route() + }, + + lobby: function(){ + }, + + room: function(name){ + }, + +})
\ No newline at end of file diff --git a/public/js/lib/views/lobby/index.js b/public/js/lib/views/lobby/index.js new file mode 100644 index 0000000..5ed1966 --- /dev/null +++ b/public/js/lib/views/lobby/index.js @@ -0,0 +1,9 @@ +var LobbyView = View.extend({ + + events: { + }, + + initialize: function(){ + } + +})
\ No newline at end of file diff --git a/public/js/lib/views/room/index.js b/public/js/lib/views/room/index.js new file mode 100644 index 0000000..b266e29 --- /dev/null +++ b/public/js/lib/views/room/index.js @@ -0,0 +1,9 @@ +var RoomView = View.extend({ + + events: { + }, + + initialize: function(){ + } + +})
\ No newline at end of file diff --git a/public/js/lib/ws.js b/public/js/lib/ws.js index 37a8248..fbf9211 100644 --- a/public/js/lib/ws.js +++ b/public/js/lib/ws.js @@ -12,6 +12,7 @@ var ws = function(){ socket.on('connect', ws.connected) socket.on('reconnect', ws.reconnected) socket.on('disconnect', ws.disconnected) + return socket } ws.ready = function (obj) { @@ -19,11 +20,11 @@ var ws = function(){ // presumably we might have reconnected? if (socketIsReady) { - this.chatView.fetchAndDedupe() + // this.chatView.fetchAndDedupe() } else { socketIsReady = true - this.checkIfLoaded() + // this.checkIfLoaded() } } @@ -40,4 +41,4 @@ var ws = function(){ console.log(new Date(), "disconnected") // this.chatView.appendInfo({ content: "Disconnected." }) } -}
\ No newline at end of file +} diff --git a/server/index.js b/server/index.js index d375351..657cdc8 100644 --- a/server/index.js +++ b/server/index.js @@ -9,7 +9,8 @@ var http = require('http'), express = require('express'), bodyParser = require('body-parser'), multer = require('multer'), - path = require('path'); + path = require('path'), + ws = require("./ws"); var app = express() var server @@ -31,7 +32,7 @@ app.use(express.query()) // } app.get("/", function(req,res){ - res.render("pages/index", {}) + res.render("pages/lobby", {}) }) app.get("/v/:room", function(req,res){ res.render("pages/room") @@ -42,3 +43,4 @@ server.listen(app.get('port'), function () { console.log('asdf-yt server listening on port ' + app.get('port')); }) +ws.listen(server)
\ No newline at end of file diff --git a/server/ws.js b/server/ws.js new file mode 100644 index 0000000..4715d34 --- /dev/null +++ b/server/ws.js @@ -0,0 +1,37 @@ + +var server = require('socket.io') + +var ws = module.exports = {} + +ws.listen = function(app){ + ws.io = server(app) +} +ws.add = function(name){ + var room = {} + room.users = {} + + var ns = base.io.of('/' + name) + + ns.on('connection', function(socket){ + + var username + + socket.on('join', function(data){ + username = data.username + if (room.users[username]) { + // already connected? + room.users[username].disconnect() + room.users[username] = socket + } + }) + + socket.on('message', function(data){ + ns.emit('message', data) + }) + + socket.on('disconnect', function(){ + delete room.users[username] + }) + + }) +} diff --git a/views/pages/index.ejs b/views/pages/lobby.ejs index 9a1a900..46b634c 100644 --- a/views/pages/index.ejs +++ b/views/pages/lobby.ejs @@ -10,6 +10,11 @@ <div id="bg"></div> +<div id="login"> + please enter your nick..<br> + <input type="text" id="username"> +</div> + <input type="text" id="create-room" placeholder="enter a url to make a room"> </body> diff --git a/views/pages/room.ejs b/views/pages/room.ejs index fb14a6f..568a136 100644 --- a/views/pages/room.ejs +++ b/views/pages/room.ejs @@ -18,6 +18,11 @@ </form> </div> +<div id="login"> + please enter your nick..<br> + <input type="text" id="username"> +</div> + <script type="text/html" id="message_template"> <div class="row"> <span class="nick"></span> @@ -25,7 +30,6 @@ </div> </script> - </body> [[ include ../partials/scripts ]] </html>
\ No newline at end of file diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs index d946f86..5908ee7 100644 --- a/views/partials/scripts.ejs +++ b/views/partials/scripts.ejs @@ -16,6 +16,7 @@ <script src="js/lib/user.js"></script> <script src="js/lib/video.js"></script> <script src="js/lib/ws.js"></script> +<script src="js/lib/views/lobby/index.js"></script> <script src="js/index.js"></script> <script type="text/javascript" src="http://www.youtube.com/player_api"></script> |
