From 23608321549df020dc0a2c79fc00f5edd1ffe2e6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 4 Aug 2015 22:14:25 -0400 Subject: pull in video stuff and write bg wrapper :) --- public/js/lib/video.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 public/js/lib/video.js (limited to 'public/js/lib/video.js') diff --git a/public/js/lib/video.js b/public/js/lib/video.js new file mode 100644 index 0000000..45e6043 --- /dev/null +++ b/public/js/lib/video.js @@ -0,0 +1,91 @@ +var video = (function(){ + var video = {} + var mx + + video.init = function(opt){ + video.build() + } + + video.build = function(media){ + switch (media.type) { + case 'video': + mxType = MX.Video + break + case 'vimeo': + mxType = MX.Vimeo + break + case 'youtube': + mxType = MX.Youtube + break + } + if (app.muted) { + media.mute = true + } + mx = new mxType({ + media: media, + backface: false, + }) + video.el.innerHTML = "" + video.el.appendChild(mx.el) + + mx.load() + } + + video.play = function(){ + mx.play() + } + + video.pause = function(){ + mx.pause() + } + + video.toggle = function(shouldPause){ + if (typeof shouldPause !== "boolean") { + shouldPause = ! mx.paused + } + shouldPause ? mx.pause() : mx.play() + return shouldPause + } + + video.toggleMuted = function(shouldMute){ + if (typeof shouldMute !== "boolean") { + shouldMute = ! mx.muted + } + shouldMute ? mx.mute() : mx.unmute() + return shouldMute + } + + video.paused = function(){ + return mx.paused + } + + video.muted = function(){ + return mx.muted + } + + video.seek = function(n){ + mx.seek(n) + } + + video.setLoop = function(shouldLoop){ + mx.setLoop(shouldLoop) + } + + video.mute = function(muted){ + if (muted) { + mx.mute() + } + else { + mx.unmute() + } + } + + video.unmute = function(){ + mx.unmute() + } + + video.setVolume = function(n){ + mx.setVolume(n) + } + +})() -- 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 'public/js/lib/video.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