Skip to content

Commit

Permalink
Fetch and show stream title is available (Fixes pimusicbox#259).
Browse files Browse the repository at this point in the history
  • Loading branch information
kingosticks committed Mar 22, 2020
1 parent ab4da71 commit 14cffe5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
34 changes: 20 additions & 14 deletions mopidy_musicbox_webclient/static/js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,33 @@ function resetSong () {
data.track.artists = ''
data.track.length = 0
data.track.uri = ''
data.stream = ''
setSongInfo(data)
}

function setSongTitle (data) {
var name = data.track.name
if (data.stream) {
name = data.stream + ' || ' + data.track.name
console.log('Setting name %s', name)
}
$('#modalname').html('<a href="#" onclick="return controls.showInfoPopup(\'' + data.track.uri + '\', \'\', mopidy);">' + name + '</span></a>')
$('#infoname').html(name)
}

function setStreamTitle (title) {
songdata.stream = title
setSongTitle(songdata)
}

function resizeMb () {
if ($(window).width() < 880) {
$('#panel').panel('close')
} else {
$('#panel').panel('open')
}

$('#infoname').html(songdata.track.name)
setSongTitle(songdata)
$('#infoartist').html(artiststext)

if ($(window).width() > 960) {
Expand All @@ -35,14 +51,6 @@ function resizeMb () {
}
}

function setSongTitle (track, refresh_ui) {
songdata.track.name = track.name
$('#modalname').html('<a href="#" onclick="return controls.showInfoPopup(\'' + track.uri + '\', \'\', mopidy);">' + track.name + '</span></a>')
if (refresh_ui) {
resizeMb()
}
}

function setSongInfo (data) {
if (!data) { return }
if (data.tlid === songdata.tlid) { return }
Expand All @@ -63,10 +71,7 @@ function setSongInfo (data) {
}
}
}

songdata = data

setSongTitle(data.track, false)
songlength = Infinity

if (!data.track.length || data.track.length === 0) {
Expand Down Expand Up @@ -282,8 +287,9 @@ function initSocketevents () {
})

mopidy.on('event:streamTitleChanged', function (data) {
// Update all track info.
mopidy.playback.getCurrentTlTrack().then(processCurrenttrack, console.error)
// The stream title is separate from the current track.
setStreamTitle(data.title)
controls.setPlayState(true)
})
}

Expand Down
5 changes: 4 additions & 1 deletion mopidy_musicbox_webclient/static/js/process_ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
*/

/** ******************************************************
* process results of a (new) currently playing track
* process results of a (new) currently playing track and any stream title
*********************************************************/
function processCurrenttrack (data) {
setSongInfo(data)
mopidy.playback.getStreamTitle().then(function (title) {
setStreamTitle(title)
}, console.error)
}

/** ******************************************************
Expand Down

0 comments on commit 14cffe5

Please sign in to comment.