+
diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js
index 99fc70f..ce2fd8e 100644
--- a/htdocs/js/mpd.js
+++ b/htdocs/js/mpd.js
@@ -110,7 +110,6 @@ var app = $.sammy(function() {
$('#panel-heading').text("Search: "+searchstr);
});
-
this.get(/\#\/dirble\/(\d+)\/(\d+)/, function() {
prepare();
current_app = 'dirble';
@@ -134,14 +133,9 @@ var app = $.sammy(function() {
dirble_stations = true;
- if(dirble_api_token) {
- dirble_load_stations();
- } else {
- getDirbleApiToken();
- }
+ if (dirble_api_token) { dirble_load_stations(); }
});
-
this.get(/\#\/dirble\//, function() {
prepare();
current_app = 'dirble';
@@ -157,11 +151,7 @@ var app = $.sammy(function() {
dirble_stations = false;
- if(dirble_api_token) {
- dirble_load_categories();
- } else {
- getDirbleApiToken();
- }
+ if (dirble_api_token) { dirble_load_categories(); }
});
this.get("/", function(context) {
@@ -199,7 +189,6 @@ $(document).ready(function(){
add_filter();
});
-
function webSocketConnect() {
if (typeof MozWebSocket != "undefined") {
socket = new MozWebSocket(get_appropriate_ws_url());
@@ -217,7 +206,9 @@ function webSocketConnect() {
app.run();
/* emit initial request for output names */
- socket.send("MPD_API_GET_OUTPUTS");
+ socket.send('MPD_API_GET_OUTPUTS');
+ /* emit initial request for dirble api token */
+ socket.send('MPD_API_GET_DIRBLEAPITOKEN');
}
socket.onmessage = function got_packet(msg) {
@@ -446,7 +437,7 @@ function webSocketConnect() {
});
break;
- case "state":
+ case 'state':
updatePlayIcon(obj.data.state);
updateVolumeIcon(obj.data.volume);
@@ -500,16 +491,20 @@ function webSocketConnect() {
last_state = obj;
break;
- case "outputnames":
+ case 'outputnames':
$('#btn-outputs-block button').remove();
- $.each(obj.data, function(id, name){
- var btn = $('
');
- btn.appendTo($('#btn-outputs-block'));
- });
+ if (obj.data.length > 1) {
+ $.each(obj.data, function(id, name){
+ var btn = $('
');
+ btn.appendTo($('#btn-outputs-block'));
+ });
+ } else {
+ $('#btn-outputs-block').addClass('hide');
+ }
/* remove cache, since the buttons have been recreated */
last_outputs = '';
break;
- case "outputs":
+ case 'outputs':
if(JSON.stringify(obj) === JSON.stringify(last_outputs))
break;
$.each(obj.data, function(id, enabled){
@@ -520,7 +515,7 @@ function webSocketConnect() {
});
last_outputs = obj;
break;
- case "disconnected":
+ case 'disconnected':
if($('.top-right').has('div').length == 0)
$('.top-right').notify({
message:{text:"ympd lost connection to MPD "},
@@ -528,11 +523,11 @@ function webSocketConnect() {
fadeOut: { enabled: true, delay: 1000 },
}).show();
break;
- case "update_queue":
+ case 'update_queue':
if(current_app === 'queue')
socket.send('MPD_API_GET_QUEUE,'+pagination);
break;
- case "song_change":
+ case 'song_change':
$('#album').text("");
$('#artist').text("");
@@ -560,22 +555,26 @@ function webSocketConnect() {
}).show();
break;
- case "mpdhost":
+ case 'mpdhost':
$('#mpdhost').val(obj.data.host);
$('#mpdport').val(obj.data.port);
if(obj.data.passwort_set)
$('#mpd_password_set').removeClass('hide');
break;
- case "dirbleapitoken":
+ case 'dirbleapitoken':
dirble_api_token = obj.data;
- if(dirble_stations) {
- dirble_load_stations();
+ if (dirble_api_token) {
+ $('#dirble').removeClass('hide');
+
+ if (dirble_stations) { dirble_load_stations(); }
+ else { dirble_load_categories(); }
+
} else {
- dirble_load_categories();
- }
+ $('#dirble').addClass('hide');
+ }
break;
- case "error":
+ case 'error':
$('.top-right').notify({
message:{text: obj.data},
type: "danger",
@@ -583,9 +582,8 @@ function webSocketConnect() {
default:
break;
}
-
-
}
+
socket.onclose = function(){
console.log("disconnected");
$('.top-right').notify({
@@ -777,10 +775,6 @@ function getHost() {
$('#mpd_pw_con').keypress(onEnter);
}
-function getDirbleApiToken() {
- socket.send('MPD_API_GET_DIRBLEAPITOKEN');
-}
-
$('#search').submit(function () {
app.setLocation("#/search/"+$('#search > div > input').val());
$('#wait').modal('show');
diff --git a/src/ympd.c b/src/ympd.c
index a699b28..3aed7e6 100644
--- a/src/ympd.c
+++ b/src/ympd.c
@@ -80,8 +80,6 @@ int main(int argc, char **argv)
mpd.port = 6600;
strcpy(mpd.host, "127.0.0.1");
- strcpy(dirble_api_token, "2e223c9909593b94fc6577361a");
-
static struct option long_options[] = {
{"host", required_argument, 0, 'h'},
{"port", required_argument, 0, 'p'},