|
@@ -43,7 +43,7 @@ module.exports = {
|
|
|
},
|
|
|
|
|
|
initializeStation: function(stationId, cb) {
|
|
|
- console.log(112233, stationId);
|
|
|
+ console.log(112233, stationId, cb);
|
|
|
if (typeof cb !== 'function') cb = ()=>{};
|
|
|
let _this = this;
|
|
|
_this.getStation(stationId, (err, station) => {
|
|
@@ -63,18 +63,26 @@ module.exports = {
|
|
|
if (isNaN(timeLeft)) timeLeft = -1;
|
|
|
if (station.currentSong.duration * 1000 < timeLeft || timeLeft < 0) {
|
|
|
console.log("Test");
|
|
|
- _this.skipStation(station._id)();
|
|
|
+ this.skipStation(station._id)((err, station) => {
|
|
|
+ console.log(45, err, station);
|
|
|
+ cb(err, station);
|
|
|
+ });
|
|
|
} else {
|
|
|
notifications.schedule(`stations.nextSong?id=${station._id}`, timeLeft);
|
|
|
+ cb(null, station);
|
|
|
}
|
|
|
} else {
|
|
|
- _this.skipStation(station._id)();
|
|
|
+ _this.skipStation(station._id)((err, station) => {
|
|
|
+ console.log(47, err, station);
|
|
|
+ cb(err, station);
|
|
|
+ });
|
|
|
}
|
|
|
} else {
|
|
|
notifications.unschedule(`stations.nextSong?id${station._id}`);
|
|
|
+ cb(null, station);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+ } else cb("Station not found.");
|
|
|
+ } else cb(err);
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -175,7 +183,8 @@ module.exports = {
|
|
|
|
|
|
skipStation: function(stationId) {
|
|
|
let _this = this;
|
|
|
- return () => {
|
|
|
+ return (cb) => {
|
|
|
+ if (typeof cb !== 'function') cb = ()=>{};
|
|
|
console.log("###2");
|
|
|
console.log("NOTIFICATION!!!");
|
|
|
_this.getStation(stationId, (err, station) => {
|
|
@@ -349,13 +358,16 @@ module.exports = {
|
|
|
console.log("22", !!(station.currentSong));
|
|
|
utils.socketsLeaveSongRooms(io.io.to(`station.${station._id}`).sockets, `song.${station.currentSong._id}`);
|
|
|
}
|
|
|
- }
|
|
|
+ console.log(33, null, station, cb);
|
|
|
+ cb(null, station);
|
|
|
+ } else cb(err);
|
|
|
});
|
|
|
}
|
|
|
// the station doesn't exist anymore, unsubscribe from it
|
|
|
else {
|
|
|
console.log(112233445566, "REMOVE NOTIFICATION");
|
|
|
notifications.remove(notification);
|
|
|
+ cb("Station not found.");
|
|
|
}
|
|
|
});
|
|
|
}
|