Browse Source

Used shorter syntax in some places. Updated some code to reflect the new "globals" module structure

Cameron Kline 8 years ago
parent
commit
a898199a93
2 changed files with 14 additions and 23 deletions
  1. 6 3
      backend/logic/socketHandler.js
  2. 8 20
      backend/logic/stations.js

+ 6 - 3
backend/logic/socketHandler.js

@@ -5,17 +5,19 @@ const passport = require('passport');
 module.exports = (core, io, app) => {
 
 	io.on('connection', socket => {
+
 		console.log("User has connected");
+
 		let _user = socket.request.user;
 		let _currentStation = "";
 
-		socket.on('disconnect', () => {
+		socket.on('disconnect', _ => {
 			core['/stations/leave/:id'](_currentStation);
 			_currentStation = "";
 			console.log('User has disconnected');
 		});
 
-		socket.on('/users/logout', () => {
+		socket.on('/users/logout', _ => {
 			app.use((req, res) => {
 				req.logout();
 			});
@@ -76,7 +78,8 @@ module.exports = (core, io, app) => {
 		});
 
 		// this lets the client socket know that they can start making request
-		console.log(socket.request.user)
+		console.log(socket.request.user);
+
 		socket.emit('ready', socket.request.user.logged_in);
 	});
 };

+ 8 - 20
backend/logic/stations.js

@@ -1,12 +1,13 @@
 'use strict';
 
-const global = require('./global');
+const globals = require('./globals');
 const Promise = require('bluebird');
-const io = global.io;
+const io = globals.io;
 let stations = [];
 
 module.exports = {
 	Station: class Station {
+
 		constructor(id, data) {
 			this.nsp = io.of(id);
 			let local = this;
@@ -35,7 +36,7 @@ module.exports = {
 				local.playlist = [];
 				return arr.reduce((promise, id) => {
 					return promise.then(() => {
-						return global.db.song.find({ id }, (err, song) => {
+						return globals.db.models.song.find({ id }, (err, song) => {
 							if (err) throw err;
 							local.playlist.push(song[0]);
 						});
@@ -70,7 +71,7 @@ module.exports = {
 				this.currentSong = this.playlist[this.currentSongIndex];
 
 				let self = this;
-				this.timer = new global.Timer(() => {
+				this.timer = new globals.utils.Timer(() => {
 					self.nextSong();
 				}, this.currentSong.duration, this.paused);
 
@@ -101,20 +102,7 @@ module.exports = {
 			return this.timePaused + this.timer.getTimePaused();
 		}
 	},
-	addStation: (station) => {
-		stations.push(station);
-	},
-	getStation: id => {
-		let result;
-		stations.forEach(function(station) {
-			if (station.id === id) {
-				result = station;
-			}
-		});
-		return result;
-	},
-	// Returns stations list when POSTing to '/stations'
-	getStations: () => {
-		return stations;
-	}
+	addStation: station => stations.push(station),
+	getStation: id => stations.find(station => station.id === id),
+	getStations: _ => stations
 };