Forráskód Böngészése

Fixed some issues, added debug for more issues.

Kris 8 éve
szülő
commit
f2433f9a98

+ 6 - 1
backend/logic/actions/stations.js

@@ -32,7 +32,9 @@ cache.sub('station.resume', stationId => {
 });
 
 cache.sub('station.create', stationId => {
-	stations.getStation(stationId, (err, station) => {
+	console.log(111);
+	stations.initializeStation(stationId, (err, station) => {
+		console.log(err, station);
 		//TODO Emit to homepage and admin station page
 		if (!err) {
 			io.io.to('home').emit("event:stations.created", station);
@@ -321,8 +323,11 @@ module.exports = {
 			}
 
 		], (err, station) => {
+			console.log(1234567);
 			if (err) throw err;
+			console.log(123456789);
 			cache.pub('station.create', data._id);
+			console.log(123456723213);
 			return cb(null, { 'status': 'success', 'message': 'Successfully created station.' });
 		});
 	}),

+ 8 - 5
backend/logic/cache/index.js

@@ -117,14 +117,15 @@ const lib = {
 	 */
 	pub: (channel, value, stringifyJson = true) => {
 
-		if (pubs[channel] === undefined) {
+		/*if (pubs[channel] === undefined) {
 			pubs[channel] = redis.createClient({ url: lib.url });
 			pubs[channel].on('error', (err) => console.error);
-		}
+		}*/
 
 		if (stringifyJson && ['object', 'array'].includes(typeof value)) value = JSON.stringify(value);
 
-		pubs[channel].publish(channel, value);
+		//pubs[channel].publish(channel, value);
+		lib.client.publish(channel, value);
 	},
 
 	/**
@@ -135,17 +136,19 @@ const lib = {
 	 * @param {Boolean} [parseJson=true] - parse the message as JSON
 	 */
 	sub: (channel, cb, parseJson = true) => {
-
 		if (subs[channel] === undefined) {
 			subs[channel] = { client: redis.createClient({ url: lib.url }), cbs: [] };
+			setInterval(() => {
+				console.log(channel, subs[channel].client.connected, lib.url);
+			}, 2000);
 			subs[channel].client.on('error', (err) => console.error);
 			subs[channel].client.on('message', (channel, message) => {
+				console.log("MESSAGE", channel, message);
 				if (parseJson) try { message = JSON.parse(message); } catch (e) {}
 				subs[channel].cbs.forEach((cb) => cb(message));
 			});
 			subs[channel].client.subscribe(channel);
 		}
-
 		subs[channel].cbs.push(cb);
 	}
 

+ 2 - 2
backend/logic/db/schemas/station.js

@@ -11,8 +11,8 @@ module.exports = {
 		duration: { type: Number, required: true },
 		skipDuration: { type: Number, required: true },
 		thumbnail: { type: String, required: true },
-		likes: { type: Number, required: true },
-		dislikes: { type: Number, required: true },
+		likes: { type: Number, default: -1, required: true },
+		dislikes: { type: Number, default: -1, required: true },
 	},
 	currentSongIndex: { type: Number, default: 0, required: true },
 	timePaused: { type: Number, default: 0, required: true },

+ 3 - 1
backend/logic/stations.js

@@ -34,7 +34,8 @@ module.exports = {
 		});
 	},
 
-	initializeStation: function(_station) {
+	initializeStation: function(_station, cb) {
+		if (typeof cb !== 'function') cb = ()=>{};
 		let _this = this;
 		_this.getStation(_station._id, (err, station) => {
 			if (!err) {
@@ -177,6 +178,7 @@ module.exports = {
 									if (!station.paused) {
 										notifications.schedule(`stations.nextSong?id=${station._id}`, station.currentSong.duration * 1000);
 									}
+									cb(err, station);
 								});
 							}
 							// the station doesn't exist anymore, unsubscribe from it