| 
														
															@@ -1,6 +1,7 @@ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 // custom modules 
														 | 
														
														 | 
														
															 // custom modules 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 const global = require('./global'); 
														 | 
														
														 | 
														
															 const global = require('./global'); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+var io = global.io; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 function Station (id, data) { 
														 | 
														
														 | 
														
															 function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -17,6 +18,10 @@ function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	var displayName = data.displayName; 
														 | 
														
														 | 
														
															 	var displayName = data.displayName; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	var description = data.description; 
														 | 
														
														 | 
														
															 	var description = data.description; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	var timer; 
														 | 
														
														 | 
														
															 	var timer; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	var nsp = io.of('/' + id); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	nsp.on('connection', function(socket){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		console.log('someone connected'); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.skipSong = function() { 
														 | 
														
														 | 
														
															 	this.skipSong = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		if (playlist.length > 0) { 
														 | 
														
														 | 
														
															 		if (playlist.length > 0) { 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -35,7 +40,7 @@ function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				self.skipSong(); 
														 | 
														
														 | 
														
															 				self.skipSong(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			}, currentSong.duration, paused); 
														 | 
														
														 | 
														
															 			}, currentSong.duration, paused); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			//io.emit("skipSong " + id, currentSong); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			nsp.emit("skippedSong", currentSong); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.toggleVoteSkip = function(userId) { 
														 | 
														
														 | 
														
															 	this.toggleVoteSkip = function(userId) { 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -45,7 +50,7 @@ function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			skipVotes = skipVotes.splice(skipVotes.indexOf(userId), 1); 
														 | 
														
														 | 
														
															 			skipVotes = skipVotes.splice(skipVotes.indexOf(userId), 1); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		//TODO Calculate if enough people voted to skip 
														 | 
														
														 | 
														
															 		//TODO Calculate if enough people voted to skip 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		//TODO Emit 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		nsp.emit("voteSkip", skipVotes); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.retrievePlaylist = function() { 
														 | 
														
														 | 
														
															 	this.retrievePlaylist = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		//TODO Use Rethink to get the Playlist for this station 
														 | 
														
														 | 
														
															 		//TODO Use Rethink to get the Playlist for this station 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -54,15 +59,15 @@ function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		if (!paused) { 
														 | 
														
														 | 
														
															 		if (!paused) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			paused = true; 
														 | 
														
														 | 
														
															 			paused = true; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			timer.pause(); 
														 | 
														
														 | 
														
															 			timer.pause(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			nsp.emit("pause"); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		//TODO Emit 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.unpause = function() { 
														 | 
														
														 | 
														
															 	this.unpause = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		if (paused) { 
														 | 
														
														 | 
														
															 		if (paused) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			paused = false; 
														 | 
														
														 | 
														
															 			paused = false; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			timer.resume(); 
														 | 
														
														 | 
														
															 			timer.resume(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			nsp.emit("unpause"); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		//TODO Emit 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.isPaused = function() { 
														 | 
														
														 | 
														
															 	this.isPaused = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		return paused; 
														 | 
														
														 | 
														
															 		return paused; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -73,14 +78,14 @@ function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.lock = function() { 
														 | 
														
														 | 
														
															 	this.lock = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		if (!locked) { 
														 | 
														
														 | 
														
															 		if (!locked) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			locked = true; 
														 | 
														
														 | 
														
															 			locked = true; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			nsp.emit("lock"); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		//TODO Emit 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.unlock = function() { 
														 | 
														
														 | 
														
															 	this.unlock = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		if (locked) { 
														 | 
														
														 | 
														
															 		if (locked) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			locked = false; 
														 | 
														
														 | 
														
															 			locked = false; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			nsp.emit("unlocked"); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		//TODO Emit 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.isLocked = function() { 
														 | 
														
														 | 
														
															 	this.isLocked = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		return locked; 
														 | 
														
														 | 
														
															 		return locked; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -88,10 +93,12 @@ function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.updateDisplayName = function(newDisplayName) { 
														 | 
														
														 | 
														
															 	this.updateDisplayName = function(newDisplayName) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		//TODO Update RethinkDB 
														 | 
														
														 | 
														
															 		//TODO Update RethinkDB 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		displayName = newDisplayName; 
														 | 
														
														 | 
														
															 		displayName = newDisplayName; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		nsp.emit("updateDisplayName", newDisplayName); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.updateDescription = function(newDescription) { 
														 | 
														
														 | 
														
															 	this.updateDescription = function(newDescription) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		//TODO Update RethinkDB 
														 | 
														
														 | 
														
															 		//TODO Update RethinkDB 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		description = newDescription; 
														 | 
														
														 | 
														
															 		description = newDescription; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		nsp.emit("updateDescription", newDescription); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.getId = function() { 
														 | 
														
														 | 
														
															 	this.getId = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		return id; 
														 | 
														
														 | 
														
															 		return id; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -104,9 +111,11 @@ function Station (id, data) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.addUser = function(user) { 
														 | 
														
														 | 
														
															 	this.addUser = function(user) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		users.add(user); 
														 | 
														
														 | 
														
															 		users.add(user); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		nsp.emit("updateUsers", users); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.removeUser = function(user) { 
														 | 
														
														 | 
														
															 	this.removeUser = function(user) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		users.splice(users.indexOf(user), 1); 
														 | 
														
														 | 
														
															 		users.splice(users.indexOf(user), 1); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		nsp.emit("updateUsers", users); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}; 
														 | 
														
														 | 
														
															 	}; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	this.getUsers = function() { 
														 | 
														
														 | 
														
															 	this.getUsers = function() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		return users; 
														 | 
														
														 | 
														
															 		return users; 
														 |