Skip to content

Instantly share code, notes, and snippets.

@ghankerson
Created November 27, 2018 22:06
Show Gist options
  • Select an option

  • Save ghankerson/6dc354587cc0f4d8305bb5f85388ae62 to your computer and use it in GitHub Desktop.

Select an option

Save ghankerson/6dc354587cc0f4d8305bb5f85388ae62 to your computer and use it in GitHub Desktop.
$(function(){
'use strict';
// Note: The socket isn't established until the first callback registration.
const current_client = new NowPlayingClient({
// Note that if you care about IE9, you need to make sure that this
// is the same protocol scheme as your served site.
server: 'http://nowplaying.publicradio.org' // Defaults to nowplaying.publicradio.org. Not needed in production code.
});
// Get the service from an attribute of this link.
const service ="the-current";
// Register the callback for a schedule change.
var schedule_registration = current_client.register_callback(service, 'schedule', function(data) {
var schedule_data = data.schedule[0];
$('#scheduler-display').html(schedule_data.shows[0].name + ' with ' + schedule_data.people[0].name);
});
// Register the callback for a playlist change.
var playlist_registration = current_client.register_callback(service, 'playlist', function(data) {
var playlist_data = data.songs[0];
$('#playlist-display').html(playlist_data.title + ' by ' + playlist_data.artist + ' from ' + playlist_data.album);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment