Skip to content

DJ Booth Contract

Renée Kooi edited this page Nov 11, 2016 · 2 revisions

Some plugins work on a DJ Booth, such as the ones on plug.dj or üWave servers. Users take turns playing a song or other media in the DJ Booth. Adapters that support a DJ Booth should expose a getDJBooth() method.

For an example implementation of a DJ Booth, check out the plug.dj Adapter.

import { Adapter } from 'munar-core'
import DJBooth from './DJBooth'

/**
 * Example implementation of an Adapter that supports the DJ Booth contract.
 */
class MyAdapter extends Adapter {
  // ...
  getDJBooth () {
    return new DJBooth(this)
  }
  // ...
}

DJBooth Methods

The DJ Booth object returned from the getDJBooth method may support the following methods:

getDJ(): User

Retrieve the User that is currently playing. The returned object should be an instance of, or extend from, the User class provided in munar-core. If nobody is playing, null should be returned.

getMedia(): object

Retrieve the currently playing media. A Media object can be a plain JavaScript object, or a custom class instance. A media object should have at least the following properties:

  • sourceType - A string indicating where the media is hosted, eg. "youtube", "dailymotion", "spotify".
  • sourceID - A string representation of the media's ID on the source service.
  • title - String title of the media.

And these optional properties, if available:

  • author - Author name, could be eg. the performing artist or video uploader.
  • duration - Duration in seconds of the media.

Adapters can decide to add additional properties freely.

DJBooth Events

The DJ Booth contract should receive the following events on the adapter:

djBooth:advance

The djBooth:advance event should be fired when a new song/media starts playing. It should receive one argument: an object with previous and next properties, containing the previous media, and the newly playing media, respectively. The media objects should be of the same format as the objects returned from getMedia(). If there was no previous media, or if the previous media is unknown, the previous property should be null.

The djBooth:advance event should also be fired when the previous song stops playing, and no new song starts. In this case, the next property should be null.

adapter.receive('djBooth:advance', {
  previous: previousMedia,
  next: nextMedia
})
Clone this wiki locally