From 9dc770c46e1493f020faa2cb541423b927c304e0 Mon Sep 17 00:00:00 2001 From: Hadar Weiss Date: Sun, 24 Feb 2013 18:22:08 +0200 Subject: [PATCH 1/7] ui improvements room not found handling --- public/browser.html | 51 +---------- public/css/main.css | 42 +++++++++ public/index.html | 176 ++++++++++++++++++++++++-------------- public/js/sfClient.js | 10 +-- public/js/wsConnection.js | 9 +- signalingServer.js | 12 ++- 6 files changed, 178 insertions(+), 122 deletions(-) create mode 100644 public/css/main.css diff --git a/public/browser.html b/public/browser.html index f7f2782..6e93f9f 100644 --- a/public/browser.html +++ b/public/browser.html @@ -4,53 +4,8 @@ Sharefest + - -
-
+ +
+

Sorry! Your browser isn't supported yet.

Please use Chrome Canary or Firefox Nightly to try out Sharefest.

diff --git a/public/css/main.css b/public/css/main.css new file mode 100644 index 0000000..d041296 --- /dev/null +++ b/public/css/main.css @@ -0,0 +1,42 @@ +body { + padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ + font-family: "Courgette"; +} + +.text-pretty { + font-size: 1.5em; +} + +h3 { + font-size: 24px; +} + +h1 { + font-family: 'Courgette', 'IM Fell English', serif; + font-size: 5em; +} + +.dragdrop { + padding-top: 260px; + width: 900px; + height: 400px; + border: solid #000000; + line-height: 30px; + text-align: center; + font-weight: bold; + background-color: #FFFFFF; + opacity: 0.8; + +} + +.bg { + background-image: url('../img/1.jpg'); +} + +.info { + right: 10px; + float: right; + clear: both; + bottom: 10px; + position: absolute; +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index bb2d59f..127ee14 100644 --- a/public/index.html +++ b/public/index.html @@ -4,6 +4,7 @@ Sharefest + @@ -19,6 +20,13 @@ + + + + + + + - @@ -183,6 +218,8 @@

  • Sharefest
  • About
  • Contact
  • +
  • How it works
  • +
  • Upload file
  • @@ -193,11 +230,11 @@

    -
    +
    -
    - Loading +
    + Loading... + + + + + + + + + +
    diff --git a/public/js/sfClient.js b/public/js/sfClient.js index 384a98f..388e2b5 100644 --- a/public/js/sfClient.js +++ b/public/js/sfClient.js @@ -6,7 +6,7 @@ this.numOfChunksToAllocate; this.configureBrowserSpecific(); this.CHUNK_SIZE;//bytes - this.CHUNK_EXPIRATION_TIMEOUT = 2000 ; + this.CHUNK_EXPIRATION_TIMEOUT = 2000; this.peerConnectionImpl; this.dataChannels = {}; this.initiateClient(wsServerUrl); @@ -77,7 +77,7 @@ }, updateProgress:function () { - if(this.firstTime){ + if (this.firstTime) { this.startTime = Date.now(); this.firstTime = false; } @@ -95,8 +95,8 @@ this.lastCycleUpdateSizeInBytes = this.numOfChunksReceived * this.CHUNK_SIZE; } - if(this.numOfChunksReceived == this.numOfChunksInFile){ - this.totalAvarageBw = this.calcBwInKbps((currentTime - this.startTime)/1000 , this.numOfChunksInFile*this.CHUNK_SIZE) + if (this.numOfChunksReceived == this.numOfChunksInFile) { + this.totalAvarageBw = this.calcBwInKbps((currentTime - this.startTime) / 1000, this.numOfChunksInFile * this.CHUNK_SIZE) } /*if(this.numOfChunksReceived*this.CHUNK_SIZE - this.lastProgressUpdateSizeInSize > 50000){ @@ -104,7 +104,7 @@ }*/ - radio('downloadProgress').broadcast(percentage * 100, rate , this.totalAvarageBw); + radio('downloadProgress').broadcast(percentage * 100, rate, this.totalAvarageBw); }, diff --git a/public/js/wsConnection.js b/public/js/wsConnection.js index ae391bd..cca987b 100644 --- a/public/js/wsConnection.js +++ b/public/js/wsConnection.js @@ -14,10 +14,15 @@ //thi$.socket.removeAllListeners(); }); thi$.socket.on('created', function (msg) { - history.pushState({}, msg, msg) + radio('roomReady').broadcast(msg); }); thi$.socket.on('files', function (files) { - radio('receivedRoomMetadata').broadcast(files); + if (files) { + radio('receivedRoomMetadata').broadcast(files); + } else { + radio('roomNotFound').broadcast(); + } + }); thi$.socket.on('message', function (msg) { console.log(msg); diff --git a/signalingServer.js b/signalingServer.js index 680bd3d..86ac5d0 100644 --- a/signalingServer.js +++ b/signalingServer.js @@ -11,9 +11,15 @@ exports.start = function (server) { matcher.addRoom(null, '/test', {meta:'data'}); io.on('connection', function (socket) { var pathname = url.parse(socket.handshake.headers.referer).pathname; - if (!io.rooms[pathname] && pathname != '/test') { - //no room found! - console.warn(pathname + ' room id not found'); + var uploadPath = {'/upload':true, '/':true} + if (!io.rooms[pathname]) { + if (uploadPath[pathname] == true) { + console.log('uploader entered'); + } else { + //no room found! + console.warn(pathname + ' room id not found'); + socket.emit('files', null); + } } else { socket.room = pathname.substr(1); socket.join(socket.room); From 1e5b1cff238006310ea04806b15946c2f973af9b Mon Sep 17 00:00:00 2001 From: Hadar Weiss Date: Sun, 24 Feb 2013 19:13:49 +0200 Subject: [PATCH 2/7] room counter --- matcher.js | 2 +- public/css/main.css | 7 + public/index.html | 337 +++++++++++++++++++------------------- public/js/wsConnection.js | 7 +- rooms.js | 4 + signalingServer.js | 4 +- 6 files changed, 193 insertions(+), 168 deletions(-) diff --git a/matcher.js b/matcher.js index 880e0aa..b760734 100644 --- a/matcher.js +++ b/matcher.js @@ -11,7 +11,7 @@ exports.join = function (swarmId, peerId) { if (!room) return; var peers = room.getRandomK(MAX_PEERS_MATCH); room.addPeer(peerId); - return {peers:peers, metadata:room.getMetadata()}; + return {peers:peers, size: room.getCount(), metadata:room.getMetadata()}; } exports.addRoom = function (firstPeerId, swarmId, metadata) { diff --git a/public/css/main.css b/public/css/main.css index d041296..4ff6b42 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -39,4 +39,11 @@ h1 { clear: both; bottom: 10px; position: absolute; +} + +#countWrapper { + font-size: 0.8em; + /*position: absolute;*/ + /*left: 58px;*/ + /*top: 705px;*/ } \ No newline at end of file diff --git a/public/index.html b/public/index.html index 127ee14..977e610 100644 --- a/public/index.html +++ b/public/index.html @@ -1,203 +1,208 @@ - Sharefest - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + return str; + } + + + + diff --git a/public/js/wsConnection.js b/public/js/wsConnection.js index cca987b..7d7cb55 100644 --- a/public/js/wsConnection.js +++ b/public/js/wsConnection.js @@ -16,9 +16,14 @@ thi$.socket.on('created', function (msg) { radio('roomReady').broadcast(msg); }); + + thi$.socket.on('size', function (size) { + radio('roomSizedChanged').broadcast(size); + }); + thi$.socket.on('files', function (files) { if (files) { - radio('receivedRoomMetadata').broadcast(files); + radio('receivedRoomMetadata').broadcast(files.metadata); } else { radio('roomNotFound').broadcast(); } diff --git a/rooms.js b/rooms.js index 6b2ff3b..3928a38 100644 --- a/rooms.js +++ b/rooms.js @@ -10,6 +10,10 @@ function Room(id, metadata) { } Room.prototype = { + getCount:function() { + return this.count; + }, + getMetadata:function () { return this.metadata; }, diff --git a/signalingServer.js b/signalingServer.js index 86ac5d0..ec6d8b5 100644 --- a/signalingServer.js +++ b/signalingServer.js @@ -25,8 +25,10 @@ exports.start = function (server) { socket.join(socket.room); var result = matcher.join(socket.room, socket.id); - socket.emit('files', result.metadata); + socket.emit('files', result); socket.emit('match', new proto.Match(result.peers)) + socket.emit('size', result.size); + socket.broadcast.emit('size', result.size); } //TODO: notify other peers about this match (more secured) From b887caa19a80457e7aa1905be9a4c3be14038bfd Mon Sep 17 00:00:00 2001 From: Hadar Weiss Date: Sun, 24 Feb 2013 19:16:18 +0200 Subject: [PATCH 3/7] disconnect should update room count --- matcher.js | 1 + signalingServer.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/matcher.js b/matcher.js index b760734..a5c98a7 100644 --- a/matcher.js +++ b/matcher.js @@ -18,6 +18,7 @@ exports.addRoom = function (firstPeerId, swarmId, metadata) { rooms.addRoom(swarmId, metadata).addPeer(firstPeerId); } + exports.leave = function (swarmId, peerId) { var room = rooms.getRoom(swarmId); if (room) { diff --git a/signalingServer.js b/signalingServer.js index ec6d8b5..d474bba 100644 --- a/signalingServer.js +++ b/signalingServer.js @@ -85,6 +85,8 @@ exports.start = function (server) { if (socket.room) { socket.broadcast.to(socket.room).emit('message', 'bye from ' + socket.id); + //TODO: get real size from room + socket.broadcast.emit('size', result.size); socket.leave(socket.room); matcher.leave(socket.room, socket.id); } else { From 41cb7f8b98ec46b08682fca232b2133761fcf646 Mon Sep 17 00:00:00 2001 From: Hadar Weiss Date: Sun, 24 Feb 2013 23:52:56 +0200 Subject: [PATCH 4/7] google analytics integration --- public/index.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/public/index.html b/public/index.html index 977e610..357d431 100644 --- a/public/index.html +++ b/public/index.html @@ -21,6 +21,23 @@ + + + From 6be852549d5fceac36712540e401fef5d92ab0fa Mon Sep 17 00:00:00 2001 From: Hadar Weiss Date: Sun, 24 Feb 2013 23:53:33 +0200 Subject: [PATCH 5/7] updated readme, organizing code into server/lib --- README.md | 2 ++ server.js | 28 ++----------------- matcher.js => server/lib/matcher.js | 1 + rooms.js => server/lib/rooms.js | 2 +- server/lib/router.js | 26 +++++++++++++++++ .../lib/signalingServer.js | 9 +++--- 6 files changed, 37 insertions(+), 31 deletions(-) rename matcher.js => server/lib/matcher.js (96%) rename rooms.js => server/lib/rooms.js (95%) create mode 100644 server/lib/router.js rename signalingServer.js => server/lib/signalingServer.js (93%) diff --git a/README.md b/README.md index db4c400..342800d 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ test it out at: http://sharefest.peer5.com TODO: ===== * local storage +* RESTful API +* tests * see issues - https://github.com/Peer5/ShareFest/issues History diff --git a/server.js b/server.js index bad4718..bb58260 100644 --- a/server.js +++ b/server.js @@ -1,8 +1,8 @@ var express = require('express'); var app = express(); -var signaling = require('./signalingServer.js'); +var signaling = require('./server/lib/signalingServer.js'); +var router = require('./server/lib/router.js') var server; -var rooms = require('./rooms.js'); var allowCrossDomain = function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); @@ -27,26 +27,4 @@ app.configure('production', function () { signaling.start(server); }); -app.get('/browser', function (req, res) { - res.sendfile(__dirname + '/public/browser.html'); -}); - -app.get('/about', function (req, res) { - res.redirect("https://github.com/peer5/sharefest"); -}); - -app.get('/contact', function (req, res) { - res.redirect("https://github.com/peer5/sharefest"); -}); - - -app.get('/:id', function (req, res) { - var roomId = req.params.id; - var room = rooms.getRoom(roomId); -// displayRoom(room); - - //todo: bind the room info to the page and output - res.sendfile(__dirname + '/public/index.html'); - //res.send(room); -}); - +router.configure(app, __dirname); diff --git a/matcher.js b/server/lib/matcher.js similarity index 96% rename from matcher.js rename to server/lib/matcher.js index a5c98a7..6d00006 100644 --- a/matcher.js +++ b/server/lib/matcher.js @@ -24,4 +24,5 @@ exports.leave = function (swarmId, peerId) { if (room) { room.removePeer(peerId); } + return room.getCount(); } \ No newline at end of file diff --git a/rooms.js b/server/lib/rooms.js similarity index 95% rename from rooms.js rename to server/lib/rooms.js index 3928a38..2a1798e 100644 --- a/rooms.js +++ b/server/lib/rooms.js @@ -1,4 +1,4 @@ -var util = require('./util.js'); +var util = require('./../../util.js'); // an in memory placeholder for the rooms var rooms = {}; diff --git a/server/lib/router.js b/server/lib/router.js new file mode 100644 index 0000000..7d02777 --- /dev/null +++ b/server/lib/router.js @@ -0,0 +1,26 @@ +var rooms = require('./rooms.js'); + +exports.configure = function(app, rootdir) { + app.get('/browser', function (req, res) { + res.sendfile(rootdir + '/public/browser.html'); + }); + + app.get('/about', function (req, res) { + res.redirect("https://github.com/peer5/sharefest"); + }); + + app.get('/contact', function (req, res) { + res.redirect("https://github.com/peer5/sharefest"); + }); + + + app.get('/:id', function (req, res) { + var roomId = req.params.id; + var room = rooms.getRoom(roomId); +// displayRoom(room); + + //todo: bind the room info to the page and output + res.sendfile(rootdir + '/public/index.html'); + //res.send(room); + }); +}; \ No newline at end of file diff --git a/signalingServer.js b/server/lib/signalingServer.js similarity index 93% rename from signalingServer.js rename to server/lib/signalingServer.js index d474bba..947b651 100644 --- a/signalingServer.js +++ b/server/lib/signalingServer.js @@ -2,8 +2,8 @@ var socketio = require('socket.io'); var io; var url = require('url'); var matcher = require('./matcher.js'); -var proto = require('./public/shared/protocol.js'); -var util = require('./util.js'); +var proto = require('./../../public/shared/protocol.js'); +var util = require('./../../util.js'); //var rooms = require('rooms.js'); exports.start = function (server) { @@ -85,10 +85,9 @@ exports.start = function (server) { if (socket.room) { socket.broadcast.to(socket.room).emit('message', 'bye from ' + socket.id); - //TODO: get real size from room - socket.broadcast.emit('size', result.size); socket.leave(socket.room); - matcher.leave(socket.room, socket.id); + var size = matcher.leave(socket.room, socket.id); + socket.broadcast.emit('size', size); } else { console.warn('socket room is undefined'); } From 6dbc2b2bc81ef09899359c1f7022e956f29b7b82 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 26 Feb 2013 11:56:30 +0200 Subject: [PATCH 6/7] connection defaults to xhr-polling --- public/js/wsConnection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/wsConnection.js b/public/js/wsConnection.js index 7d7cb55..60d1e24 100644 --- a/public/js/wsConnection.js +++ b/public/js/wsConnection.js @@ -7,7 +7,7 @@ WsConnection.prototype = { initiateWebSocket:function (wsServerUrl) { var thi$ = this; - this.socket = io.connect(wsServerUrl,{'connect timeout': 1500}); + this.socket = io.connect(wsServerUrl,{'connect timeout': 1500,transports: ['xhr-polling']}); console.log('new websocket'); thi$.socket.on('disconnect', function () { From ee1952db0b42b7bf6865679f12946281cb2e3b8a Mon Sep 17 00:00:00 2001 From: Hadar Weiss Date: Tue, 26 Feb 2013 15:29:01 +0200 Subject: [PATCH 7/7] remove xhr long polling --- public/js/wsConnection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/wsConnection.js b/public/js/wsConnection.js index 60d1e24..7d7cb55 100644 --- a/public/js/wsConnection.js +++ b/public/js/wsConnection.js @@ -7,7 +7,7 @@ WsConnection.prototype = { initiateWebSocket:function (wsServerUrl) { var thi$ = this; - this.socket = io.connect(wsServerUrl,{'connect timeout': 1500,transports: ['xhr-polling']}); + this.socket = io.connect(wsServerUrl,{'connect timeout': 1500}); console.log('new websocket'); thi$.socket.on('disconnect', function () {