Browse Source

Temporary fix for when node crashes, caused by removal of passport/passport.socketio

theflametrooper 8 years ago
parent
commit
a0b8ac039b
2 changed files with 27 additions and 29 deletions
  1. 16 16
      backend/logic/coreHandler.js
  2. 11 13
      backend/logic/socketHandler.js

+ 16 - 16
backend/logic/coreHandler.js

@@ -54,7 +54,7 @@ module.exports = {
 
 	// core route handlers
 
-	'/users/register': (session, username, email, password, recaptcha, cb) => {
+	'/users/register': (user, username, email, password, recaptcha, cb) => {
 
 		waterfall([
 
@@ -130,7 +130,7 @@ module.exports = {
 		});
 	},
 
-	'/users/login': (session, identifier, password, cb) => {
+	'/users/login': (user, identifier, password, cb) => {
 
 		waterfall([
 
@@ -190,7 +190,7 @@ module.exports = {
 		cb({ status: 'success', message: `You've been successfully logged out` });
 	},
 
-	'/stations': (session, cb) => {
+	'/stations': cb => {
 		cb(stations.getStations().map(station => {
 			return {
 				id: station.id,
@@ -203,13 +203,13 @@ module.exports = {
 		}));
 	},
 
-	'/stations/join/:id': (session, id, cb) => {
+	'/stations/join/:id': (id, cb) => {
 
 		let station = stations.getStation(id);
 
 		if (!station) return cb({ status: 'error', message: `Station with id '${id}' does not exist` });
 
-		session.station_id = id;
+		// session.station_id = id;
 		station.users++;
 
 		cb({ status: 'success', users: station.users });
@@ -217,19 +217,19 @@ module.exports = {
 
 	// leaves the users current station
 	// returns the count of users that are still in that station
-	'/stations/leave': (session, cb) => {
-
-		let station = stations.getStation(session.station_id);
+	'/stations/leave': cb => {
 
+		// let station = stations.getStation(session.station_id);
+		let station = stations.getStation("edm"); // will be removed
 		if (!station) return cb({ status: 'failure', message: `Not currently in a station, or station doesn't exist` });
 
-		session.station_id = "";
-		station.users--;
+		// session.station_id = "";
+		// station.users--;
 
 		cb({ status: 'success', users: station.users });
 	},
 
-	'/youtube/getVideo/:query': (session, query, cb) => {
+	'/youtube/getVideo/:query': (query, cb) => {
 
 		const params = [
 			'part=snippet',
@@ -250,9 +250,9 @@ module.exports = {
 		});
 	},
 
-	'/stations/add/:song': (session, station, song, cb) => {
+	'/stations/add/:song': (station, song, cb) => {
 
-		if (!session.logged_in) return cb({ status: 'failure', message: 'You must be logged in to add a song' });
+		// if (!session.logged_in) return cb({ status: 'failure', message: 'You must be logged in to add a song' });
 
 		const params = [
 			'part=snippet,contentDetails,statistics,status',
@@ -291,21 +291,21 @@ module.exports = {
 		});
 	},
 
-	'/songs': (session, cb) => {
+	'/songs': cb => {
 		globals.db.models.song.find({}, (err, songs) => {
 			if (err) throw err;
 			cb(songs);
 		});
 	},
 
-	'/songs/:song/update': (session, song, cb) => {
+	'/songs/:song/update': (song, cb) => {
 		globals.db.models.song.findOneAndUpdate({ id: song.id }, song, { upsert: true }, (err, updatedSong) => {
 			if (err) throw err;
 			cb(updatedSong);
 		});
 	},
 
-	'/songs/:song/remove': (session, song, cb) => {
+	'/songs/:song/remove': (song, cb) => {
 		globals.db.models.song.find({ id: song.id }).remove().exec();
 	}
 };

+ 11 - 13
backend/logic/socketHandler.js

@@ -8,29 +8,27 @@ module.exports = (core, io) => {
 
 		console.log("socketHandler: User has connected");
 
-		let session = "socket.request.user";
+		// let session = socket.request.user;
 
 		socket.on('disconnect', _ => {
-			core['/stations/leave'](session, result => {});
+			core['/stations/leave'](result => {});
 			console.log('socketHandler: User has disconnected');
 		});
 
 		socket.on('error', err => console.log(err));
 
-		socket.on('/users/logout', (cb) => core['/users/logout'](socket.request, result => cb(result)));
+		socket.on('/u/:username', (cb) => core['/u/:username'](result => cb(result)));
 
-		socket.on('/u/:username', (cb) => core['/users/logout'](socket.request, result => cb(result)));
+		socket.on('/stations', (cb) => core['/stations'](result => cb(result)));
+		socket.on('/stations/join/:id', (id, cb) => core['/stations/join/:id'](id, result => cb(result)));
+		socket.on('/stations/leave', cb => core['/stations/leave'](result => cb(result)));
+		socket.on('/stations/add/:song', (station, song, cb) => core['/stations/add/:song'](station, song, result => cb(result)));
 
-		socket.on('/stations', (cb) => core['/stations'](session, result => cb(result)));
-		socket.on('/stations/join/:id', (id, cb) => core['/stations/join/:id'](session, id, result => cb(result)));
-		socket.on('/stations/leave', cb => core['/stations/leave'](session, result => cb(result)));
-		socket.on('/stations/add/:song', (station, song, cb) => core['/stations/add/:song'](session, station, song, result => cb(result)));
+		socket.on('/songs', (cb) => core['/songs'](result => cb(result)));
+		socket.on('/songs/:song/update', (song, cb) => core['/songs/:song/update'](song, result => cb(result)));
+		socket.on('/songs/:song/remove', (song, cb) => core['/songs/:song/remove'](song, result => cb(result)));
 
-		socket.on('/songs', (cb) => core['/songs'](session, result => cb(result)));
-		socket.on('/songs/:song/update', (song, cb) => core['/songs/:song/update'](session, song, result => cb(result)));
-		socket.on('/songs/:song/remove', (song, cb) => core['/songs/:song/remove'](session, song, result => cb(result)));
-
-		socket.on('/youtube/getVideo/:query', (query, cb) => core['/youtube/getVideo/:query'](session, query, result => cb(result)));
+		socket.on('/youtube/getVideo/:query', (query, cb) => core['/youtube/getVideo/:query'](query, result => cb(result)));
 
 		// this lets the client socket know that they can start making request
 		socket.emit('ready', false); // socket.request.user.logged_in