From 086bf17b18fe93ebd05d2336bb6c10316619a0d7 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Mon, 18 Sep 2017 21:39:59 +0800 Subject: [PATCH 01/25] hope --- views/djRoom.hbs | 9 +++++++-- views/home.hbs | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/views/djRoom.hbs b/views/djRoom.hbs index 17b0ac6..72e3607 100644 --- a/views/djRoom.hbs +++ b/views/djRoom.hbs @@ -145,6 +145,7 @@ else { socket.emit('specialClose', {"roomName": roomName, "roomId": roomId, spotifyId: localStorage.getItem('spotifyId')}); localStorage.setItem("closing", "true"); } + localStorage.setItem('active', 'false'); clearInterval(clearId); }); } @@ -154,6 +155,9 @@ else { socket.on('connect', function(){ //console.log('Connected!'); + if(localStorage.getItem('active') === 'true'){ + window.location.href = '/multipleTabs'; + } clearId = setInterval(function () { socket.emit("toRefresh", localStorage.getItem("refreshToken")); @@ -162,15 +166,16 @@ socket.on('connect', function(){ if(localStorage.getItem('closing') === "true"){ window.location.href = '/'; } - else{ - socket.emit('active',localStorage.getItem('spotifyId')) + socket.emit('active',localStorage.getItem('spotifyId')); + localStorage.setItem('active', 'true'); var djObject = { roomName: roomName, accessToken: localStorage.getItem('accessToken') } socket.emit('createRoom', djObject); } + }) /* sets new access token after refresh */ diff --git a/views/home.hbs b/views/home.hbs index 76d91be..da16310 100644 --- a/views/home.hbs +++ b/views/home.hbs @@ -189,11 +189,15 @@ and (max-device-width : 480px) { localStorage.setItem("spotifyId", spotifyId); localStorage.setItem("imageURL", imageURL); localStorage.setItem("username", username); - localStorage.setItem('closing', "false"); - localStorage.setItem('leaving', "false"); localStorage.setItem('accessToken', accessToken); localStorage.setItem('refreshToken', refreshToken); + var a = localStorage.getItem('active'); + if((a && a === 'false') || !localStorage.getItem('closing'))localStorage.setItem('closing', 'false'); + + localStorage.setItem('leaving', "false"); + getPlayback(); + $(document).on('click','#songTest' ,function() { $.ajax({ From 0475aba6fc35a619bddb9d4b2ec8de436bcc183e Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Mon, 18 Sep 2017 22:00:05 +0800 Subject: [PATCH 02/25] this works ? --- views/djRoom.hbs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/views/djRoom.hbs b/views/djRoom.hbs index 72e3607..45db704 100644 --- a/views/djRoom.hbs +++ b/views/djRoom.hbs @@ -100,6 +100,7 @@ var socket = io(); var clearId = -1; var isDJ = true; var userDJSpotifyId = ''; +var unload = 0; // set to 1 when refresh or duplicated tab is closing so that specialClose does not happen... new Clipboard('#shareable'); @@ -141,12 +142,12 @@ else { /* after refresh or close tab*/ $(window).on("unload", function(){ - if(localStorage.getItem('closing') === 'false'){ + if(localStorage.getItem('closing') === 'false' && unload === 0){ socket.emit('specialClose', {"roomName": roomName, "roomId": roomId, spotifyId: localStorage.getItem('spotifyId')}); localStorage.setItem("closing", "true"); + localStorage.setItem('active', 'false'); + clearInterval(clearId); } - localStorage.setItem('active', 'false'); - clearInterval(clearId); }); } @@ -156,24 +157,27 @@ socket.on('connect', function(){ //console.log('Connected!'); if(localStorage.getItem('active') === 'true'){ + unload = 1; window.location.href = '/multipleTabs'; } + else { + clearId = setInterval(function () { + socket.emit("toRefresh", localStorage.getItem("refreshToken")); + }, 20*60000); - clearId = setInterval(function () { - socket.emit("toRefresh", localStorage.getItem("refreshToken")); - }, 20*60000); - - if(localStorage.getItem('closing') === "true"){ - window.location.href = '/'; - } - else{ - socket.emit('active',localStorage.getItem('spotifyId')); - localStorage.setItem('active', 'true'); - var djObject = { - roomName: roomName, - accessToken: localStorage.getItem('accessToken') + if(localStorage.getItem('closing') === 'true'){ + unload = 1; + window.location.href = '/'; + } + else{ + socket.emit('active',localStorage.getItem('spotifyId')); + localStorage.setItem('active', 'true'); + var djObject = { + roomName: roomName, + accessToken: localStorage.getItem('accessToken') + } + socket.emit('createRoom', djObject); } - socket.emit('createRoom', djObject); } }) @@ -336,6 +340,8 @@ $('#djtalkform').on('submit', function(e) { $('#closeRoom').on('click', function(event){ console.log("reached front end destination"); localStorage.setItem('closing', 'true'); + localStorage.setItem('active', 'false'); + clearInterval(clearId); socket.emit('closingRoom', {"roomName": roomName, "roomId": roomId, spotifyId: localStorage.getItem('spotifyId')}); $(window).unbind('beforeunload'); window.location = $(this).attr('data-url'); From ff121dc7a09164b1a2bfe8ed94c447452ca66f76 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Mon, 18 Sep 2017 22:06:37 +0800 Subject: [PATCH 03/25] er --- views/createRoom.hbs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/views/createRoom.hbs b/views/createRoom.hbs index 025294b..cbcf862 100644 --- a/views/createRoom.hbs +++ b/views/createRoom.hbs @@ -32,11 +32,16 @@ and (max-device-width : 480px) { From de0e09390f4a3a61f9b5d35fe158eded6b6edba2 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Thu, 21 Sep 2017 17:44:31 +0800 Subject: [PATCH 11/25] here --- routes/socketPath.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routes/socketPath.js b/routes/socketPath.js index 40acf02..b7f784d 100644 --- a/routes/socketPath.js +++ b/routes/socketPath.js @@ -405,9 +405,10 @@ module.exports = function(io) { var id = setInterval(function(){ flag = false; socket.emit('ping'); - }, 30*60000); + }, 7000); socket.on('pong', function(){ + console.log("pong recieved"); flag = true; }) @@ -415,7 +416,7 @@ module.exports = function(io) { if(!flag){ console.log("THIS IS AMAZING"); } - }, 35*60000); + }, 9000); }) From f755994df3f53233ec491977100b8c77ec82ed2b Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Thu, 21 Sep 2017 18:02:17 +0800 Subject: [PATCH 12/25] here --- routes/socketPath.js | 3 ++- views/userRoom.hbs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/routes/socketPath.js b/routes/socketPath.js index b7f784d..7346361 100644 --- a/routes/socketPath.js +++ b/routes/socketPath.js @@ -410,9 +410,10 @@ module.exports = function(io) { socket.on('pong', function(){ console.log("pong recieved"); flag = true; - }) + }); var id2 = setInterval(function(){ + console.log("flag", flag); if(!flag){ console.log("THIS IS AMAZING"); } diff --git a/views/userRoom.hbs b/views/userRoom.hbs index 4d7b9a9..bc14c1d 100644 --- a/views/userRoom.hbs +++ b/views/userRoom.hbs @@ -451,6 +451,7 @@ socket.on('laflame', function(count) { socket.emit('startPinging', localStorage.getItem('spotifyId')); socket.on('ping', function(){ + console.log("reached here"); socket.emit('pong'); }) From dcef5cee129d5b972602af92c45fa0a5ee33ca35 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Fri, 22 Sep 2017 14:22:57 +0800 Subject: [PATCH 13/25] here --- routes/index.js | 5 +++-- routes/socketPath.js | 49 ++++++++++++++++++++++++++------------------ views/djRoom.hbs | 6 +++--- views/userRoom.hbs | 14 +++++++++---- 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/routes/index.js b/routes/index.js index 7ec24c5..0cb9397 100644 --- a/routes/index.js +++ b/routes/index.js @@ -107,10 +107,11 @@ module.exports = function() { djSpotifyId: req.user.spotifyId, imageURL: req.user.imageURL, djName: req.user.username - }) + }); + newRoom.save(function(err, newRoom) { if (err) { - res.redirect('/error') + res.redirect('/error'); } else { res.redirect('/djRoom/' + newRoom._id); } diff --git a/routes/socketPath.js b/routes/socketPath.js index 7346361..6a2d0de 100644 --- a/routes/socketPath.js +++ b/routes/socketPath.js @@ -322,6 +322,13 @@ module.exports = function(io) { } }); + socket.on('ping', function(data){ + if(Date.now() - data > 20*1000){ + console.log("DISCONNECT SOCKET"); + } + else socket.emit('pong', Date.now()); + }); + ////////////////// USER ENDS ////////////////// /////////////////// DJ /////////////////////// @@ -398,28 +405,30 @@ module.exports = function(io) { }) - socket.on('startPinging', function(spotifyId){ + // socket.on('startPinging', function(spotifyId){ + // + // socket.flag = true; + // socket.spotifyId = spotifyId; + // + // var id = setInterval(function(){ + // socket.flag = false; + // socket.emit('ping'); + // }, 7000); + // + // var id2 = setInterval(function(){ + // console.log("flag", socket.flag); + // if(!socket.flag){ + // console.log("THIS IS AMAZING"); + // } + // }, 9000); + // + // }) + // + // socket.on('pong', function(){ + // socket.flag = true; + // }) - var flag = true; - var id = setInterval(function(){ - flag = false; - socket.emit('ping'); - }, 7000); - - socket.on('pong', function(){ - console.log("pong recieved"); - flag = true; - }); - - var id2 = setInterval(function(){ - console.log("flag", flag); - if(!flag){ - console.log("THIS IS AMAZING"); - } - }, 9000); - - }) //////////////////// DJ ENDS /////////////////// }) diff --git a/views/djRoom.hbs b/views/djRoom.hbs index 3a289ad..6dc28a1 100644 --- a/views/djRoom.hbs +++ b/views/djRoom.hbs @@ -182,9 +182,9 @@ socket.on('connect', function(){ }) -socket.on('disconnect', function(){ - window.location.href = '/error'; -}) +// socket.on('disconnect', function(){ +// window.location.href = '/error'; +// }) /* sets new access token after refresh */ socket.on('setNewAccessToken', function(accessToken){ diff --git a/views/userRoom.hbs b/views/userRoom.hbs index bc14c1d..f120d35 100644 --- a/views/userRoom.hbs +++ b/views/userRoom.hbs @@ -448,11 +448,17 @@ socket.on('laflame', function(count) { }) -socket.emit('startPinging', localStorage.getItem('spotifyId')); +// socket.emit('startPinging', localStorage.getItem('spotifyId')); +// +// socket.on('ping', function(){ +// console.log("reached here"); +// socket.emit('pong'); +// }) -socket.on('ping', function(){ - console.log("reached here"); - socket.emit('pong'); +socket.emit('ping'); + +socket.on('pong', function(data){ + socket.emit('ping', data) }) From c33c7c731f2f41cbb3bb84efa0970df14101a892 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Fri, 22 Sep 2017 14:32:45 +0800 Subject: [PATCH 14/25] here --- views/djRoom.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/djRoom.hbs b/views/djRoom.hbs index 6dc28a1..3c8dc86 100644 --- a/views/djRoom.hbs +++ b/views/djRoom.hbs @@ -145,7 +145,7 @@ else { if(localStorage.getItem('closing') === 'false' && unload === 0){ socket.emit('specialClose', {"roomName": roomName, "roomId": roomId, spotifyId: localStorage.getItem('spotifyId')}); localStorage.setItem("closing", "true"); - localStorage.setItem('active', 'false'); + localStorage.setItem('active', 'false'); // changed this clearInterval(clearId); } }); From 1141cc0ab3954cc177d8a03761615fe033083707 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Fri, 22 Sep 2017 14:45:14 +0800 Subject: [PATCH 15/25] here --- views/djRoom.hbs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/views/djRoom.hbs b/views/djRoom.hbs index 3c8dc86..903c444 100644 --- a/views/djRoom.hbs +++ b/views/djRoom.hbs @@ -123,11 +123,12 @@ if(isSafari){ socket.emit('specialClose', {"roomName": roomName, "roomId": roomId, spotifyId:localStorage.getItem('spotifyId')}); clearInterval(clearId); localStorage.setItem("closing", "true"); + localStorage.setItem('active', 'false'); window.location.href = '/'; } } }); - window.history.pushState('forward', null, './#forward'); + window.history.pushState('forward', null, './#forward'); } }); } From 14dd65315615ade88d56fa7eac90096b07e0cc5c Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Fri, 22 Sep 2017 14:46:50 +0800 Subject: [PATCH 16/25] here --- views/createRoom.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/views/createRoom.hbs b/views/createRoom.hbs index cbcf862..062475f 100644 --- a/views/createRoom.hbs +++ b/views/createRoom.hbs @@ -54,6 +54,7 @@ $('#startRoom').on('click', function() { }) var existingRoomNames = '{{existingRoomNames}}'; +existingRoomNames = existingRoomNames.split(" "); console.log("existingRoomNames", existingRoomNames); $('#roomSubmit').on('submit', function (event) { From a89a28a6629e9cb2cdfdc07f193576c56808301c Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Fri, 22 Sep 2017 14:50:51 +0800 Subject: [PATCH 17/25] here --- routes/socketPath.js | 2 +- views/userRoom.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/socketPath.js b/routes/socketPath.js index 6a2d0de..235999e 100644 --- a/routes/socketPath.js +++ b/routes/socketPath.js @@ -323,7 +323,7 @@ module.exports = function(io) { }); socket.on('ping', function(data){ - if(Date.now() - data > 20*1000){ + if(Date.now() - data > 10*1000){ console.log("DISCONNECT SOCKET"); } else socket.emit('pong', Date.now()); diff --git a/views/userRoom.hbs b/views/userRoom.hbs index f120d35..8e847ce 100644 --- a/views/userRoom.hbs +++ b/views/userRoom.hbs @@ -455,7 +455,7 @@ socket.on('laflame', function(count) { // socket.emit('pong'); // }) -socket.emit('ping'); +socket.emit('ping', Date.now()); socket.on('pong', function(data){ socket.emit('ping', data) From 250c80af2f45bd75343f246f2e109ddd57d2a5da Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Fri, 22 Sep 2017 19:39:30 +0800 Subject: [PATCH 18/25] testing --- routes/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/index.js b/routes/index.js index 0cb9397..706c4fd 100644 --- a/routes/index.js +++ b/routes/index.js @@ -6,6 +6,8 @@ var User = models.User; var Room = models.Room; var existingRoomNames = []; +// testing + module.exports = function() { /* Check login page. */ From 0772b8f236dd35600d18cc07236eb6e47864c995 Mon Sep 17 00:00:00 2001 From: Yashvardhan Nevatia Date: Sun, 8 Oct 2017 10:38:55 +0800 Subject: [PATCH 19/25] here --- app.js | 2 +- routes/auth.js | 4 ++-- routes/index.js | 6 ------ views/createRoom.hbs | 5 +---- views/djRoom.hbs | 25 +++++++++++-------------- views/getRooms.hbs | 2 +- views/home.hbs | 6 +++--- views/userRoom.hbs | 2 -- 8 files changed, 19 insertions(+), 33 deletions(-) diff --git a/app.js b/app.js index 0325962..f71f49d 100644 --- a/app.js +++ b/app.js @@ -44,7 +44,7 @@ app.use('/static', express.static(path.join(__dirname, 'public'))); //passport stuff -var session=require('express-session'); +var session = require('express-session'); app.use(session({ secret: 'auxen production' })); //changed key. passport.serializeUser(function(user, done) { diff --git a/routes/auth.js b/routes/auth.js index 7bc5267..43dd461 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -11,9 +11,9 @@ module.exports = function(passport) { res.render('login'); }) - router.get('/auth/spotify', + router.get('/auth/spotify', passport.authenticate('spotify', { - scope: ['user-read-email', 'user-read-private', 'user-modify-playback-state', 'user-read-playback-state'] + scope: ['user-read-email', 'user-read-private', 'user-modify-playback-state', 'user-read-playback-state'] } )); diff --git a/routes/index.js b/routes/index.js index 706c4fd..a4884f1 100644 --- a/routes/index.js +++ b/routes/index.js @@ -25,15 +25,9 @@ module.exports = function() { function ifRedirected(req, res, next){ if(req.user){ if(req.user.premium === 'premium'){ - // User.findOne({spotifyId:req.user.spotifyId}) - // .then(user => { - // if(!user.active)next() - // else res.redirect('/multipleTabs') - // }) next(); } else res.redirect('/notPremium'); - } else{ if(req.session){ diff --git a/views/createRoom.hbs b/views/createRoom.hbs index 062475f..95c1f57 100644 --- a/views/createRoom.hbs +++ b/views/createRoom.hbs @@ -31,8 +31,6 @@ and (max-device-width : 480px) {