JSPM

playlist-combinator

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q47187F
  • License VOL

A thing to mix up users and their playlists.

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 song object.

##playlist.addSong(userId, song)

  • userId is a string. Each user must have their own unique string.
  • song is any object.

##playlist.reorderSong(userId, newArray)

  • newArray is an array of song ids in the new order. You can remove songs, add songs, and reorder songs.

##playlist.reorderSong(userId, songId, newQueueLocationIndex)

  • userId is a string. Each user must have their own unique string.
  • songId is compared to each song.id in the queue. This is the only place that song.id is assumed to exist.
  • newQueueLocationIndex is the number that the located song is relocated to.

##playlist.addUser(userId, userState)

  • userId is a string. Each user must have their own unique string.
  • userState is an optional argument. It must come from playlist.removeUser().

##var userState = playlist.removeUser(userId)

  • Returns a userState object. This object can be passed into playlist.addUser() to start a new user with the same state that this user gave up. This could be used for changing a userId without losing their state, or saving a user's state for later use.