Browse Source

Fixed some issues with stations

theflametrooper 8 years ago
parent
commit
68008f3cdc

+ 2 - 1
backend/logic/actions/apis.js

@@ -1,6 +1,7 @@
 'use strict';
 
-const request = require('request');
+const request = require('request'),
+	  config  = require('config');
 
 module.exports = {
 

+ 11 - 8
backend/logic/actions/stations.js

@@ -1,7 +1,8 @@
 'use strict';
 
-const async = require('async');
-const request = require('request');
+const async   = require('async'),
+	  request = require('request'),
+	  config  = require('config');
 
 const io = require('../io');
 const db = require('../db');
@@ -209,11 +210,13 @@ module.exports = {
 				return cb({ status: 'error', message: 'Failed to find song from youtube' });
 			}
 
+			body = JSON.parse(body);
+
 			const newSong = new db.models.song({
-				id: json.items[0].id,
-				title: json.items[0].snippet.title,
-				duration: utils.convertTime(json.items[0].contentDetails.duration),
-				thumbnail: json.items[0].snippet.thumbnails.high.url
+				id: body.items[0].id,
+				title: body.items[0].snippet.title,
+				duration: utils.convertTime(body.items[0].contentDetails.duration),
+				thumbnail: body.items[0].snippet.thumbnails.high.url
 			});
 
 			// save the song to the database
@@ -224,9 +227,9 @@ module.exports = {
 					return cb({ status: 'error', message: 'Failed to save song from youtube to the database' });
 				}
 
-				stations.getStation(station).playlist.push(newSong);
+				// stations.getStation(station).playlist.push(newSong);
 
-				cb({ status: 'success', data: stations.getStation(station.playlist) });
+				// cb({ status: 'success', data: stations.getStation(station.playlist) });
 			});
 		});
 	}

+ 1 - 1
backend/logic/io.js

@@ -18,7 +18,7 @@ module.exports = {
 		this.io.use((socket, next) => {
 			let cookies = socket.request.headers.cookie;
 			// set the sessionId for the socket (this will have to be checked every request, this allows us to have a logout all devices option)
-			socket.sessionId = utils.cookies.parseCookies(cookies).SID;
+			if (cookies) socket.sessionId = utils.cookies.parseCookies(cookies).SID;
 			return next();
 		});
 

+ 1 - 3
frontend/App.vue

@@ -25,7 +25,7 @@
 			}
 		},
 		methods: {
-			logout() {
+			logout: function () {
 				this.socket.emit('users.logout');
 				document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
 				location.reload();
@@ -42,7 +42,6 @@
 		},
 		events: {
 			'register': function () {
-
 				let { register: { email, username, password } } = this;
 				this.socket.emit('users.register', email, username, password, grecaptcha.getResponse(), (result) => {
 					console.log(result);
@@ -50,7 +49,6 @@
 				});
 			},
 			'login': function () {
-
 				let { login: { email, password } } = this;
 
 				this.socket.emit('users.login', email, password, (result) => {

+ 24 - 19
frontend/components/pages/Station.vue

@@ -211,6 +211,7 @@
 				}
 			},
 			addSongToQueue: function(song) {
+				console.log('add', song)
 				let local = this;
 				local.socket.emit('stations.addSong', local.$route.params.id, song, function(data) {
 					if (data) console.log(data);
@@ -233,39 +234,43 @@
 			}
 		},
 		ready: function() {
+			let _this = this;
 
-			this.interval = 0;
+			_this.interval = 0;
 
-			this.socket = this.$parent.socket;
+			_this.socket = _this.$parent.socket;
 
-			this.socket.on('event:songs.next', (data) => {
-				let {currentSong, startedAt} = data;
+			_this.socket.on('event:songs.next', data => {
+				let { currentSong, startedAt } = data;
 				this.currentSong = currentSong;
 				this.startedAt = startedAt;
 				this.timePaused = 0;
 				this.playVideo();
 			});
 
-			/*this.stationSocket = io.connect(`${window.location.protocol + '//' + window.location.hostname + ':8081'}/${local.$route.params.id}`);
+			lofig.folder = '../config/default.json';
+			lofig.get('socket.url', function(res) {
+				_this.stationSocket = io(window.location.protocol + '//' + res + '/' + _this.$route.params.id);
+
+				_this.stationSocket.on("connected", (data) => {
+					console.log(data);
+					_this.currentSong = data.currentSong;
+					_this.startedAt = data.startedAt;
+					_this.paused = data.paused;
+					_this.timePaused = data.timePaused;
+					_this.currentTime  = data.currentTime;
+				});
 
-			this.stationSocket.on("connected", (data) => {
-				console.log(data);
-				local.currentSong = data.currentSong;
-				local.startedAt = data.startedAt;
-				local.paused = data.paused;
-				local.timePaused = data.timePaused;
-				local.currentTime  = data.currentTime;
+				_this.stationSocket.on("nextSong", (currentSong, startedAt) => {
+					_this.currentSong = currentSong;
+					_this.startedAt = startedAt;
+					_this.timePaused = 0;
+					_this.playVideo();
+				});
 			});
 
 			this.youtubeReady();
 
-			this.stationSocket.on("nextSong", (currentSong, startedAt) => {
-				this.currentSong = currentSong;
-				this.startedAt = startedAt;
-				this.timePaused = 0;
-				this.playVideo();
-			});*/
-
 			let volume = parseInt(localStorage.getItem("volume"));
 			volume = (typeof volume === "number") ? volume : 20;
 			$("#volumeSlider").val(volume);