From 39f3e69d477a605ae676a64222e2486f67856b8e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 4 Aug 2015 22:22:30 -0400 Subject: css --- server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/index.js') diff --git a/server/index.js b/server/index.js index 89ba350..d375351 100644 --- a/server/index.js +++ b/server/index.js @@ -15,8 +15,8 @@ var app = express() var server app.set('port', config.port) -app.set('views', path.join(__dirname, '../views')) app.set('view engine', 'ejs') +app.set('views', path.join(__dirname, '../views')) app.use(express.static(path.join(__dirname, '../public'))) app.use(require('morgan')("combined", {})) app.use(require("express-json")()) -- cgit v1.2.3-70-g09d2 From d0b4cd4f7e6364a35a420f2f3b0fcdbb502d8a9a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 5 Aug 2015 00:51:32 -0400 Subject: basic routing --- public/css/css.css | 2 +- public/js/index.js | 16 +++++++++++++++- public/js/lib/views/index.js | 22 ++++++++++++++++++++++ public/js/lib/views/lobby/index.js | 9 +++++++++ public/js/lib/views/room/index.js | 9 +++++++++ public/js/lib/ws.js | 7 ++++--- server/index.js | 6 ++++-- server/ws.js | 37 +++++++++++++++++++++++++++++++++++++ views/pages/index.ejs | 17 ----------------- views/pages/lobby.ejs | 22 ++++++++++++++++++++++ views/pages/room.ejs | 6 +++++- views/partials/scripts.ejs | 1 + 12 files changed, 129 insertions(+), 25 deletions(-) create mode 100644 public/js/lib/views/index.js create mode 100644 public/js/lib/views/lobby/index.js create mode 100644 public/js/lib/views/room/index.js create mode 100644 server/ws.js delete mode 100644 views/pages/index.ejs create mode 100644 views/pages/lobby.ejs (limited to 'server/index.js') 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/index.ejs deleted file mode 100644 index 9a1a900..0000000 --- a/views/pages/index.ejs +++ /dev/null @@ -1,17 +0,0 @@ - - - -yt-chat - - - - - -
- - - - -<% include ../partials/scripts %> - \ No newline at end of file diff --git a/views/pages/lobby.ejs b/views/pages/lobby.ejs new file mode 100644 index 0000000..46b634c --- /dev/null +++ b/views/pages/lobby.ejs @@ -0,0 +1,22 @@ + + + +yt-chat + + + + + +
+ +
+ please enter your nick..
+ +
+ + + + +<% include ../partials/scripts %> + \ No newline at end of file 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 @@ +
+ please enter your nick..
+ +
+ - [[ include ../partials/scripts ]] \ 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 @@ + -- cgit v1.2.3-70-g09d2 From 9be8b15c7efbd84193c74c99ce2c043f025f7ee6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 5 Aug 2015 01:27:59 -0400 Subject: util --- public/css/css.css | 9 +++++++-- server/index.js | 6 +++++- server/util.js | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 server/util.js (limited to 'server/index.js') diff --git a/public/css/css.css b/public/css/css.css index a8d3df1..5536d6c 100644 --- a/public/css/css.css +++ b/public/css/css.css @@ -16,11 +16,16 @@ body{background:transparent;} top: 50%; left: 50%; -webkit-transform: translate(-50%,-50%); transform: translate(-50%,-50%); - background: #fff; padding: 20px; } +#login form { + background: #fff; +} + #lobby input { font-size: 3vw; - width: 40vw; + width: 60vw; + background: rgba(0,0,0,0.9); + color: #fff; } \ No newline at end of file diff --git a/server/index.js b/server/index.js index 657cdc8..8b8c738 100644 --- a/server/index.js +++ b/server/index.js @@ -10,7 +10,8 @@ var http = require('http'), bodyParser = require('body-parser'), multer = require('multer'), path = require('path'), - ws = require("./ws"); + ws = require("./ws"), + util = require("./util"); var app = express() var server @@ -34,6 +35,9 @@ app.use(express.query()) app.get("/", function(req,res){ res.render("pages/lobby", {}) }) +app.post("/v/", function(req,res){ + res.render("pages/room") +}) app.get("/v/:room", function(req,res){ res.render("pages/room") }) diff --git a/server/util.js b/server/util.js new file mode 100644 index 0000000..11c0cac --- /dev/null +++ b/server/util.js @@ -0,0 +1,3 @@ +var util = module.exports = {} + +util.sanitizeName = function (s){ return (s || "").replace(new RegExp("[^-_a-zA-Z0-9]", 'g'), "") } -- cgit v1.2.3-70-g09d2 From 3b7da491072e5c366738ff549e8958d97948076a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 5 Aug 2015 10:45:17 -0400 Subject: hook into ws --- public/js/lib/video.js | 2 +- public/js/lib/views/lobby/index.js | 2 +- public/js/vendor/util.js | 2 ++ server/index.js | 6 +++++- server/ws.js | 3 +++ 5 files changed, 12 insertions(+), 3 deletions(-) (limited to 'server/index.js') diff --git a/public/js/lib/video.js b/public/js/lib/video.js index 45e6043..2eb5c82 100644 --- a/public/js/lib/video.js +++ b/public/js/lib/video.js @@ -2,7 +2,7 @@ var video = (function(){ var video = {} var mx - video.init = function(opt){ + video.init = function(media){ video.build() } diff --git a/public/js/lib/views/lobby/index.js b/public/js/lib/views/lobby/index.js index 70b63c4..0306445 100644 --- a/public/js/lib/views/lobby/index.js +++ b/public/js/lib/views/lobby/index.js @@ -9,7 +9,7 @@ var LobbyView = View.extend({ }, join: function(){ - var name = this.$createRoom.sanitize() + var name = this.$createRoom.sanitizeName() if (! name) { return } window.location.href = "/v/" + name } diff --git a/public/js/vendor/util.js b/public/js/vendor/util.js index 7c73ae2..73a25ad 100644 --- a/public/js/vendor/util.js +++ b/public/js/vendor/util.js @@ -5,12 +5,14 @@ if (window.$) { $.fn.enable = function() { return $(this).attr("disabled",null) } $.fn.disable = function() { return $(this).attr("disabled","disabled") } $.fn.sanitize = function(s) { return trim(sanitize($(this).val())) } + $.fn.sanitizeName = function(s) { return trim(sanitizeName($(this).val())) } $.fn.htmlSafe = function(s) { return $(this).html(sanitize(s)) } $.fn.toDollars = function(i) { return $(this).html((i/100).toFixed(2)) } } function trim (s){ return s.replace(/^\s+/,"").replace(/\s+$/,"") } function sanitize (s){ return (s || "").replace(new RegExp("[<>&]", 'g'), "") } +function sanitizeName (s){ return (s || "").replace(new RegExp("[^-_a-zA-Z0-9]", 'g'), "") } function stripHTML (s){ return (s || "").replace(/<[^>]+>/g, "") } function capitalize (s){ return s.split(" ").map(capitalizeWord).join(" ") } function capitalizeWord (s){ return s.charAt(0).toUpperCase() + s.slice(1) } diff --git a/server/index.js b/server/index.js index 8b8c738..d08cf2e 100644 --- a/server/index.js +++ b/server/index.js @@ -35,10 +35,14 @@ app.use(express.query()) app.get("/", function(req,res){ res.render("pages/lobby", {}) }) -app.post("/v/", function(req,res){ +app.post("/v/:room", function(req,res){ + var room = util.sanitizeName(req.params.room) + ws.add(room) res.render("pages/room") }) app.get("/v/:room", function(req,res){ + var room = util.sanitizeName(req.params.room) + ws.add(room) res.render("pages/room") }) diff --git a/server/ws.js b/server/ws.js index 4715d34..860319a 100644 --- a/server/ws.js +++ b/server/ws.js @@ -3,10 +3,13 @@ var server = require('socket.io') var ws = module.exports = {} +var rooms = {} + ws.listen = function(app){ ws.io = server(app) } ws.add = function(name){ + if (name in rooms) { return } var room = {} room.users = {} -- cgit v1.2.3-70-g09d2