Package Exports
- playlist-combinator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (playlist-combinator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
playlist-combinator
A javascript module to rotate through multiple users' music queues.
#usage
Run this code:
var playlist = require('playlist-combinator')()
playlist.on('error', function (err) {
console.log(err)
})
playlist.addUser('josh@example.com', [ { id: 'hash', title: 'whatever' } ])
playlist.addUser('joseph@example.com')
playlist.addSong('joseph@example.com', { id: 'otherhash', title: 'whatever 2' })
playlist.addSong('joseph@example.com', { id: 'somemoreid', title: 'o, hi' })
playlist.addSong('joseph@example.com', { id: 'someid', title: 'thingy' })Internally:
userOrder: ['joseph@example.com', 'josh@example.com']
songs: {
"josh@example.com": [
{ id: 'hash', title: 'whatever' }
]
"joseph@example.com": [
{ id: 'otherhash', title: 'whatever 2' },
{ id: 'somemoreid', title: 'o, hi' },
{ id: 'someid', title: 'thingy' }
]
}Run this code:
var song = playlist.getNextSong() //returns => { id: 'otherhash', title: 'whatever 2' }Internally:
userOrder: ['josh@example.com', 'joseph@example.com'] //note that 'joseph' was moved to the back; it's 'josh's turn next
songs: {
"josh@example.com": [
{ id: 'hash', title: 'whatever' }
]
"joseph@example.com": [
{ id: 'somemoreid', title: 'o, hi' },
{ id: 'someid', title: 'thingy' }
]
}#api
##var playlist = require('playlist-combinator')
##var song = playlist.getNextSong()
- Removes the first song from the first user's queue.
- Moves the first user to the back of the user list.
- Returns the
songobject.
##playlist.addSong(userId, song)
userIdis a string. Each user must have their own unique string.songis any object.
##playlist.reorderSong(userId, newArray)
newArrayis an array of song ids in the new order. You can remove songs, add songs, and reorder songs.
##playlist.reorderSong(userId, songId, newQueueLocationIndex)
userIdis a string. Each user must have their own unique string.songIdis compared to eachsong.idin the queue. This is the only place thatsong.idis assumed to exist.newQueueLocationIndexis the number that the located song is relocated to.
##playlist.addUser(userId, userState)
userIdis a string. Each user must have their own unique string.userStateis an optional argument. It must come fromplaylist.removeUser().
##var userState = playlist.removeUser(userId)
- Returns a
userStateobject. This object can be passed intoplaylist.addUser()to start a new user with the same state that this user gave up. This could be used for changing auserIdwithout losing their state, or saving a user's state for later use.