Continued work on channel-wide playlists.
This commit is contained in:
parent
72a89ae5ff
commit
70a68d9336
7 changed files with 151 additions and 89 deletions
|
|
@ -18,6 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
const validator = require('validator');
|
||||
|
||||
//Local imports
|
||||
const queuedMedia = require('./queuedMedia');
|
||||
const loggerUtils = require('../../../utils/loggerUtils');
|
||||
const yanker = require('../../../utils/media/yanker');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||
|
|
@ -35,8 +36,10 @@ module.exports = class{
|
|||
socket.on("getChannelPlaylists", () => {this.getChannelPlaylists(socket)});
|
||||
socket.on("createChannelPlaylist", (data) => {this.createChannelPlaylist(socket, data)});
|
||||
socket.on("addToChannelPlaylist", (data) => {this.addToChannelPlaylist(socket, data)});
|
||||
socket.on("queueChannelPlaylist", (data) => {this.queueChannelPlaylist(socket, data)});
|
||||
}
|
||||
|
||||
//--- USER-FACING PLAYLIST FUNCTIONS ---
|
||||
async getChannelPlaylists(socket, chanDB){
|
||||
//if we wherent handed a channel document
|
||||
if(chanDB == null){
|
||||
|
|
@ -84,4 +87,30 @@ module.exports = class{
|
|||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
}
|
||||
|
||||
async queueChannelPlaylist(socket, data, chanDB){
|
||||
//if we wherent handed a channel document
|
||||
if(chanDB == null){
|
||||
//Pull it based on channel name
|
||||
chanDB = await channelModel.findOne({name: this.channel.name});
|
||||
}
|
||||
|
||||
//Pull a valid start time from input, or make one up if we can't
|
||||
let start = this.channel.queue.getStart(data.start);
|
||||
|
||||
//Grab playlist from the DB
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//Create an empty array to hold our media list
|
||||
const mediaList = [];
|
||||
|
||||
//Iterate through playlist media
|
||||
for(let item of playlist.media){
|
||||
//Rehydrate playlist item and push it into the media list
|
||||
mediaList.push(item.rehydrate());
|
||||
}
|
||||
|
||||
//Convert array of standard media objects to queued media objects, and push to schedule
|
||||
this.channel.queue.scheduleMedia(queuedMedia.fromMediaArray(mediaList, start), socket, chanDB);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue