mirror of
https://github.com/SuperBFG7/ympd
synced 2025-03-11 14:08:20 +00:00
Only show love button when either mpdas or mpdscribble channel is
present and use the correct channel to send the message of love
This commit is contained in:
parent
fd727cc20b
commit
2b461aafa2
@ -29,6 +29,7 @@ var current_song = new Object();
|
||||
var MAX_ELEMENTS_PER_PAGE = 512;
|
||||
var isTouch = Modernizr.touch ? 1 : 0;
|
||||
var filter = '';
|
||||
var scrobbler = '';
|
||||
|
||||
var app = $.sammy(function () {
|
||||
function runBrowse() {
|
||||
@ -264,6 +265,7 @@ function webSocketConnect() {
|
||||
app.run();
|
||||
/* emit initial request for output names */
|
||||
socket.send('MPD_API_GET_OUTPUTS');
|
||||
socket.send('MPD_API_GET_CHANNELS');
|
||||
};
|
||||
|
||||
socket.onmessage = function got_packet(msg) {
|
||||
@ -815,6 +817,22 @@ function webSocketConnect() {
|
||||
});
|
||||
last_outputs = obj;
|
||||
break;
|
||||
case 'channels':
|
||||
scrobbler = '';
|
||||
$('#love').addClass('hide');
|
||||
if (Object.keys(obj.data).length) {
|
||||
$.each(obj.data, function (id, name) {
|
||||
switch (name) {
|
||||
case 'mpdas':
|
||||
case 'mpdscribble':
|
||||
scrobbler = name;
|
||||
$('#love').removeClass('hide');
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'disconnected':
|
||||
if ($('.top-right').has('div').length == 0)
|
||||
$('.top-right')
|
||||
@ -1082,11 +1100,9 @@ function basename(path) {
|
||||
|
||||
function clickLove() {
|
||||
socket.send(
|
||||
'MPD_API_SEND_MESSAGE,mpdas,' +
|
||||
($('#btnlove').hasClass('active') ? 'unlove' : 'love')
|
||||
);
|
||||
socket.send(
|
||||
'MPD_API_SEND_MESSAGE,mpdscribble,' +
|
||||
'MPD_API_SEND_MESSAGE,' +
|
||||
scrobbler +
|
||||
',' +
|
||||
($('#btnlove').hasClass('active') ? 'unlove' : 'love')
|
||||
);
|
||||
if ($('#btnlove').hasClass('active')) $('#btnlove').removeClass('active');
|
||||
|
@ -259,6 +259,11 @@ int callback_mpd(struct mg_connection *c) {
|
||||
out_send_message:
|
||||
free(p_charbuf);
|
||||
break;
|
||||
case MPD_API_GET_CHANNELS:
|
||||
mpd.buf_size = mpd_put_channels(mpd.buf);
|
||||
c->callback_param = NULL;
|
||||
mpd_notify_callback(c, MG_POLL);
|
||||
break;
|
||||
#ifdef WITH_MPD_HOST_CHANGE
|
||||
/* Commands allowed when disconnected from MPD server */
|
||||
case MPD_API_SET_MPDHOST:
|
||||
@ -550,6 +555,32 @@ int mpd_put_outputs(char *buffer, int names) {
|
||||
return str - buffer;
|
||||
}
|
||||
|
||||
int mpd_put_channels(char *buffer) {
|
||||
struct mpd_pair *channel;
|
||||
int nchan;
|
||||
char *str, *strend;
|
||||
|
||||
str = buffer;
|
||||
strend = buffer + MAX_SIZE;
|
||||
str += snprintf(str, strend - str, "{\"type\":\"%s\", \"data\":{", "channels");
|
||||
|
||||
mpd_send_channels(mpd.conn);
|
||||
nchan = 0;
|
||||
while ((channel = mpd_recv_channel_pair(mpd.conn)) != NULL) {
|
||||
if (nchan++)
|
||||
*str++ = ',';
|
||||
str += snprintf(str, strend - str, " \"%d\":\"%s\"", nchan, channel->value);
|
||||
mpd_return_pair(mpd.conn, channel);
|
||||
}
|
||||
if (!mpd_response_finish(mpd.conn)) {
|
||||
fprintf(stderr, "MPD outputs: %s\n", mpd_connection_get_error_message(mpd.conn));
|
||||
mpd_connection_clear_error(mpd.conn);
|
||||
return 0;
|
||||
}
|
||||
str += snprintf(str, strend - str, " }}");
|
||||
return str - buffer;
|
||||
}
|
||||
|
||||
int mpd_put_current_song(char *buffer) {
|
||||
char *cur = buffer;
|
||||
const char *end = buffer + MAX_SIZE;
|
||||
|
@ -50,6 +50,7 @@
|
||||
X(MPD_API_RM_ALL) \
|
||||
X(MPD_API_MOVE_TRACK) \
|
||||
X(MPD_API_SEARCH) \
|
||||
X(MPD_API_GET_CHANNELS) \
|
||||
X(MPD_API_SEND_MESSAGE) \
|
||||
X(MPD_API_SET_VOLUME) \
|
||||
X(MPD_API_SET_PAUSE) \
|
||||
@ -109,6 +110,7 @@ int callback_mpd(struct mg_connection *c);
|
||||
int mpd_close_handler(struct mg_connection *c);
|
||||
int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version);
|
||||
int mpd_put_outputs(char *buffer, int putnames);
|
||||
int mpd_put_channels(char *buffer);
|
||||
int mpd_put_current_song(char *buffer);
|
||||
int mpd_put_queue(char *buffer, unsigned int offset);
|
||||
int mpd_put_browse(char *buffer, char *path, unsigned int offset);
|
||||
|
Loading…
x
Reference in New Issue
Block a user