diff --git a/htdocs/js/bootstrap-notify.js b/htdocs/js/bootstrap-notify.js
index caa3f12..e82fbac 100644
--- a/htdocs/js/bootstrap-notify.js
+++ b/htdocs/js/bootstrap-notify.js
@@ -46,7 +46,7 @@
this.$note.html(this.options.message);
if(this.options.closable)
- var link = $('×');
+ var link = $(' ×');
$(link).on('click', $.proxy(onClose, this));
this.$note.prepend(link);
diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js
index 7dd87b3..d40c96b 100644
--- a/htdocs/js/mpd.js
+++ b/htdocs/js/mpd.js
@@ -5,7 +5,6 @@ var current_song = new Object();
var app = $.sammy(function() {
this.before('/', function(e, data) {
- socket.send("MPD_API_GET_TRACK_INFO");
$('#nav_links > li').removeClass('active');
});
@@ -74,8 +73,8 @@ function webSocketConnect() {
try {
socket.onopen = function() {
$('.top-right').notify({
- message:{text:"Connected"},
- fadeOut: { enabled: true, delay: 1000 }
+ message:{text:"Connected to ympd"},
+ fadeOut: { enabled: true, delay: 500 }
}).show();
app.run();
@@ -102,10 +101,10 @@ function webSocketConnect() {
var seconds = obj.data[song].duration - minutes * 60;
$('#salamisandwich > tbody').append(
- "" + obj.data[song].pos + " | " +
+ "
" + (obj.data[song].pos + 1) + " | " +
""+ obj.data[song].title +" | " +
""+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
- " |
");
+ " | ");
}
$('#salamisandwich > tbody > tr').on({
@@ -139,7 +138,7 @@ function webSocketConnect() {
"" +
" | " +
"" + basename(obj.data[item].dir) + " | " +
- " |
");
+ " | | ");
break;
case "song":
var minutes = Math.floor(obj.data[item].duration / 60);
@@ -149,7 +148,7 @@ function webSocketConnect() {
"" +
" | " +
"" + obj.data[item].title +" | " +
- ""+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +" |
");
+ ""+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +" | | ");
break;
case "playlist":
@@ -157,29 +156,33 @@ function webSocketConnect() {
}
}
+ function appendClickableIcon(appendTo, onClickAction, glyphicon) {
+ $(appendTo).children().last().append(
+ "" +
+ "")
+ .find('a').click(function(e) {
+ e.stopPropagation();
+ socket.send(onClickAction + "," + $(this).parents("tr").attr("uri"));
+ $('.top-right').notify({
+ message:{
+ text: $('td:nth-child(2)', $(this).parents("tr")).text() + " added"
+ } }).show();
+ }).fadeTo('fast',1);
+ }
+
$('#salamisandwich > tbody > tr').on({
- mouseenter: function(){
- if($(this).is(".dir")) {
- $(this).children().last().append(
- "" +
- "Add Directory ")
- .find('a').click(function(e) {
- e.stopPropagation();
- socket.send("MPD_API_ADD_TRACK," + $(this).parents("tr").attr("uri"));
- $('.top-right').notify({
- message:{
- text:"Added " + $('td:nth-child(2)', $(this).parents("tr")).text() + " to playlist "
- }
- }).show();
- }).fadeTo('fast',1);
- }
+ mouseenter: function() {
+ if($(this).is(".dir"))
+ appendClickableIcon($(this), 'MPD_API_ADD_TRACK', 'plus');
+ else if($(this).is(".song"))
+ appendClickableIcon($(this), 'MPD_API_ADD_PLAY_TRACK', 'play');
},
click: function() {
if($(this).is(".song")) {
socket.send("MPD_API_ADD_TRACK," + $(this).attr("uri"));
$('.top-right').notify({
message:{
- text:"Added " + $('td:nth-child(2)', this).text() + " to playlist "
+ text: $('td:nth-child(2)', this).text() + " added"
}
}).show();
@@ -239,9 +242,6 @@ function webSocketConnect() {
else
$('#btnrepeat').removeClass("active");
- if(obj.data.elapsedTime <= 1)
- socket.send("MPD_API_GET_TRACK_INFO");
-
last_state = obj;
break;
case "disconnected":
@@ -256,12 +256,23 @@ function webSocketConnect() {
if(current_app === 'playlist')
$.get( "/api/get_playlist", socket.onmessage);
break;
- case "current_song":
+ case "song_change":
$('#currenttrack').text(" " + obj.data.title);
- if(obj.data.album)
+ var notification = "" + obj.data.title + "
";
+
+ if(obj.data.album) {
$('#album').text(obj.data.album);
- if(obj.data.artist)
+ notification += obj.data.album + "
";
+ }
+ if(obj.data.artist) {
$('#artist').text(obj.data.artist);
+ notification += obj.data.artist + "
";
+ }
+
+ $('.top-right').notify({
+ message:{html: notification},
+ type: "info",
+ }).show();
break;
case "error":
$('.top-right').notify({
@@ -350,14 +361,20 @@ var updatePlayIcon = function(state)
}
}
-function updateDB()
-{
+function updateDB() {
socket.send('MPD_API_UPDATE_DB');
$('.top-right').notify({
message:{text:"Updating MPD Database... "}
}).show();
}
+function clickPlay() {
+ if($('#track-icon').hasClass('glyphicon-stop'))
+ socket.send('MPD_API_SET_PLAY');
+ else
+ socket.send('MPD_API_SET_PAUSE');
+}
+
function basename(path) {
return path.split('/').reverse()[0];
}
diff --git a/src/http_server.c b/src/http_server.c
index 511f7c9..15e8bbf 100644
--- a/src/http_server.c
+++ b/src/http_server.c
@@ -20,7 +20,6 @@ struct serveable {
static const struct serveable whitelist[] = {
{ "/css/bootstrap.css", "text/css" },
- { "/css/slider.css", "text/css" },
{ "/css/mpd.css", "text/css" },
{ "/js/bootstrap.min.js", "text/javascript" },
diff --git a/src/mpd_client.c b/src/mpd_client.c
index 6ceb56a..c38f74f 100644
--- a/src/mpd_client.c
+++ b/src/mpd_client.c
@@ -16,7 +16,6 @@
struct mpd_connection *conn = NULL;
enum mpd_conn_states mpd_conn_state = MPD_DISCONNECTED;
enum mpd_state mpd_play_state = MPD_STATE_UNKNOWN;
-unsigned queue_version;
int callback_ympd(struct libwebsocket_context *context,
struct libwebsocket *wsi,
@@ -53,10 +52,9 @@ int callback_ympd(struct libwebsocket_context *context,
else if(mpd_conn_state != MPD_CONNECTED) {
n = snprintf(p, MAX_SIZE, "{\"type\":\"disconnected\"}");
}
- else if((pss->queue_version != queue_version) || (pss->do_send & DO_SEND_PLAYLIST)) {
+ else if(pss->do_send & DO_SEND_PLAYLIST) {
/*n = mpd_put_playlist(p);*/
n = snprintf(p, MAX_SIZE, "{\"type\":\"update_playlist\"}");
- pss->queue_version = queue_version;
pss->do_send &= ~DO_SEND_PLAYLIST;
}
else if(pss->do_send & DO_SEND_TRACK_INFO) {
@@ -68,8 +66,24 @@ int callback_ympd(struct libwebsocket_context *context,
pss->do_send &= ~DO_SEND_BROWSE;
free(pss->browse_path);
}
- else
- n = mpd_put_state(p);
+ else {
+ /* Default Action */
+ int current_song_id;
+ unsigned queue_version;
+
+ n = mpd_put_state(p, ¤t_song_id, &queue_version);
+ if(current_song_id != pss->current_song_id)
+ {
+ pss->current_song_id = current_song_id;
+ pss->do_send |= DO_SEND_TRACK_INFO;
+ libwebsocket_callback_on_writable(context, wsi);
+ }
+ else if(pss->queue_version != queue_version) {
+ pss->queue_version = queue_version;
+ pss->do_send |= DO_SEND_PLAYLIST;
+ libwebsocket_callback_on_writable(context, wsi);
+ }
+ }
if(n > 0)
m = libwebsocket_write(wsi, (unsigned char *)p, n, LWS_WRITE_TEXT);
@@ -105,6 +119,8 @@ int callback_ympd(struct libwebsocket_context *context,
unsigned id;
if(sscanf(in, "MPD_API_RM_TRACK,%u", &id))
mpd_run_delete_id(conn, id);
+
+ libwebsocket_callback_on_writable(context, wsi);
}
else if(!strncmp((const char *)in, MPD_API_PLAY_TRACK, sizeof(MPD_API_PLAY_TRACK)-1)) {
unsigned id;
@@ -156,6 +172,16 @@ int callback_ympd(struct libwebsocket_context *context,
free(uri);
}
}
+ else if(!strncmp((const char *)in, MPD_API_ADD_PLAY_TRACK, sizeof(MPD_API_ADD_PLAY_TRACK)-1)) {
+ char *uri;
+ if(sscanf(in, "MPD_API_ADD_PLAY_TRACK,%m[^\t\n]", &uri) && uri != NULL) {
+ int added_song = mpd_run_add_id(conn, uri);
+ if(added_song != -1)
+ mpd_run_play_id(conn, added_song);
+ free(uri);
+ }
+ }
+
if(mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
pss->do_send |= DO_SEND_ERROR;
@@ -226,7 +252,7 @@ char* mpd_get_title(struct mpd_song const *song)
return basename(str);
}
-int mpd_put_state(char *buffer)
+int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version)
{
struct mpd_status *status;
int len;
@@ -256,7 +282,8 @@ int mpd_put_state(char *buffer)
mpd_status_get_total_time(status),
mpd_status_get_song_id(status));
- queue_version = mpd_status_get_queue_version(status);
+ *current_song_id = mpd_status_get_song_id(status);
+ *queue_version = mpd_status_get_queue_version(status);
mpd_status_free(status);
return len;
}
@@ -271,7 +298,7 @@ int mpd_put_current_song(char *buffer)
if(song == NULL)
return 0;
- cur += snprintf(cur, end - cur, "{\"type\": \"current_song\", \"data\":"
+ cur += snprintf(cur, end - cur, "{\"type\": \"song_change\", \"data\":"
"{\"pos\":%d, \"title\":\"%s\"",
mpd_song_get_pos(song),
mpd_get_title(song));
diff --git a/src/mpd_client.h b/src/mpd_client.h
index 287ecc1..ab6c422 100644
--- a/src/mpd_client.h
+++ b/src/mpd_client.h
@@ -17,6 +17,7 @@
#define MPD_API_GET_TRACK_INFO "MPD_API_GET_TRACK_INFO"
#define MPD_API_GET_BROWSE "MPD_API_GET_BROWSE"
#define MPD_API_ADD_TRACK "MPD_API_ADD_TRACK"
+#define MPD_API_ADD_PLAY_TRACK "MPD_API_ADD_PLAY_TRACK"
#define MPD_API_PLAY_TRACK "MPD_API_PLAY_TRACK"
#define MPD_API_RM_TRACK "MPD_API_RM_TRACK"
#define MPD_API_RM_ALL "MPD_API_RM_ALL"
@@ -36,6 +37,7 @@
struct per_session_data__ympd {
int do_send;
unsigned queue_version;
+ int current_song_id;
char *browse_path;
};
@@ -51,7 +53,7 @@ int callback_ympd(struct libwebsocket_context *context,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len);
void mpd_loop();
-int mpd_put_state(char *buffer);
+int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version);
int mpd_put_current_song(char *buffer);
int mpd_put_playlist(char *buffer);
int mpd_put_browse(char *buffer, char *path);
diff --git a/src/ympd_process.c b/src/ympd_process.c
deleted file mode 100644
index 40ab565..0000000
--- a/src/ympd_process.c
+++ /dev/null
@@ -1 +0,0 @@
-ympd_process.c
\ No newline at end of file