Class Transistor
Defined in: transistor.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Transistor(cfg)
|
Method Attributes | Method Name and Description |
---|---|
auth(session)
Authenticate a user, or enter them into the web auth flow
|
|
ban(track, ok, error)
Ban's and skip's a track
|
|
deauth()
Deauthenticates the current user, clearing the transistor cookie
|
|
<private> |
getSession(token)
|
Get the username of the authorised user
|
|
love(track, ok, error)
Love a track.
|
|
next(ok, error)
Requests the next track from the playlist and starts
playing it.
|
|
<private> |
onFinished(id, track)
|
<private> |
onNowPlaying(id, track)
|
<private> |
onPlayback(id, track, timings)
|
pause()
Pause the currently playing track
|
|
play(ok, error)
Plays a new track if none is playing.
|
|
scrobble(track, ok, error)
Scrobble a track
|
|
scrobblePoint(track)
Return the point at which a given track should be scrobbled
|
|
setScrobble(scrobble)
Should the player send scrobble and now player notifications
|
|
setVolume(vol)
Set the player volume
|
|
skip(ok, error)
Skips the current track and starts playing the next
item on the playlist.
|
|
tune(url, ok, error)
Tune the authenticated user to the given station url
|
|
unlove(track, ok, error)
Unlove a track.
|
Class Detail
Transistor(cfg)
- Parameters:
- cfg
- Configuration object
- cfg.player Optional
- A player
- cfg.sm2 Optional
- SoundManager instance, else window.soundManager used
- cfg.api Optional
- Api client to use
- {String} cfg.key Optional
- Your api key
- {String} cfg.secret Optional
- Your api secret
- {String} cfg.session Optional
- Your api session
- {String} cfg.scrobble Optional, Default: true
- Should tracks be scrobbled and now playing notifications be sent?
Method Detail
auth(session)
Authenticate a user, or enter them into the web auth flow
- Parameters:
- {String} session Optional
- The session key
{Promise}
ban(track, ok, error)
Ban's and skip's a track
- Parameters:
- track Optional
- The track to ban
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback
- Returns:
- {Promise} The promise return by the api request, with callbacks attached
deauth()
Deauthenticates the current user, clearing the transistor cookie
<private>
getSession(token)
- Parameters:
- {String} token
- The token to exchange for a session
{String|Boolean}
getUsername()
Get the username of the authorised user
- Returns:
- {String|Boolean} Username if authed or false
love(track, ok, error)
Love a track.
- Parameters:
- track Optional
- The track to love, if not supplied uses currently playing track
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback
{Promise}
next(ok, error)
Requests the next track from the playlist and starts
playing it.
This method does not fire any amplify events
- Parameters:
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback
- Returns:
- {Promise} The promise return by the api request, with callbacks attached
<private>
onFinished(id, track)
- Parameters:
- id
- The id of the player
- track
- The now playing track
<private>
onNowPlaying(id, track)
- Parameters:
- id
- The id of the player
- track
- The now playing track
<private>
onPlayback(id, track, timings)
- Parameters:
- id
- The id of the player
- track
- The playing track
- timings
- The timings for the track
- timings.position
- The position of the track in milliseconds
- timings.duration
- The duration of the track as reported by the player (This may be adjusted as the track is downloaded).
pause()
Pause the currently playing track
{Promise}
play(ok, error)
Plays a new track if none is playing. Requests the next track from
the playlist. If the playlist is empty a request to the
radio.getPlaylist service is sent. If a track is paused this method
resumes it's playback.
- Parameters:
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback
- Returns:
- {Promise} The promise return by the api request, with callbacks attached
{Promise}
scrobble(track, ok, error)
Scrobble a track
- Parameters:
- track Optional
- The track to scrobble, uses currently playing track if none provided.
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback
- Returns:
- {Promise} The promise return by the api request, with callbacks attached
{Number}
scrobblePoint(track)
Return the point at which a given track should be scrobbled
- Parameters:
- track
- The track
- Returns:
- {Number} The position at which the track should be scrobbled, in milliseconds
setScrobble(scrobble)
Should the player send scrobble and now player notifications
- Parameters:
- {Boolean} scrobble
- true = scrobbling, false = private listening
setVolume(vol)
Set the player volume
- Parameters:
- {Number} vol
- The volume, valid ranges are 0-100
{Promise}
skip(ok, error)
Skips the current track and starts playing the next
item on the playlist.
- Parameters:
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback
- Returns:
- {Promise} The promise return by the api request, with callbacks attached
{Promise}
tune(url, ok, error)
Tune the authenticated user to the given station url
- Parameters:
- {String} url
- The station url, including the lastfm:// protocol
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback
- Returns:
- {Promise} The promise return by the api request, with callbacks attached
unlove(track, ok, error)
Unlove a track.
- Parameters:
- track Optional
- The track to unlove, if not supplied uses currently playing track
- {Function} ok Optional
- Success callback
- {Function} error Optional
- Failure callback