mirror of
https://github.com/SuperBFG7/ympd
synced 2025-01-13 10:50:36 +00:00
Feat: get outputnames and outputstates in single command
This commit is contained in:
parent
674ff60b09
commit
3980ac3bc4
@ -83,7 +83,8 @@ var modalSavequeue = new Modal(document.getElementById('modalSaveQueue'));
|
||||
var modalSongDetails = new Modal(document.getElementById('modalSongDetails'));
|
||||
var modalAddToPlaylist = new Modal(document.getElementById('modalAddToPlaylist'));
|
||||
var modalRenamePlaylist = new Modal(document.getElementById('modalRenamePlaylist'));
|
||||
var mainMenu = new Dropdown(document.getElementById('mainMenu'));
|
||||
//var mainMenu = new Dropdown(document.getElementById('mainMenu'));
|
||||
//var volumeMenu = new Dropdown(document.getElementById('volumeIcon'));
|
||||
|
||||
function appPrepare(scrollPos) {
|
||||
if (app.current.app != app.last.app || app.current.tab != app.last.tab || app.current.view != app.last.view) {
|
||||
@ -287,7 +288,7 @@ function appRoute() {
|
||||
|
||||
function appInit() {
|
||||
getSettings();
|
||||
sendAPI({"cmd":"MPD_API_GET_OUTPUTNAMES"}, parseOutputnames);
|
||||
// sendAPI({"cmd":"MPD_API_GET_OUTPUTS"}, parseOutputnames);
|
||||
|
||||
webSocketConnect();
|
||||
|
||||
@ -303,6 +304,10 @@ function appInit() {
|
||||
sendAPI({"cmd": "MPD_API_SET_SEEK", "data": {"songid": current_song.currentSongId, "seek": seekVal}});
|
||||
}
|
||||
}, false);
|
||||
|
||||
document.getElementById('volumeIcon').parentNode.addEventListener('show.bs.dropdown', function () {
|
||||
sendAPI({"cmd":"MPD_API_GET_OUTPUTS"}, parseOutputnames);
|
||||
});
|
||||
|
||||
document.getElementById('modalAbout').addEventListener('shown.bs.modal', function () {
|
||||
sendAPI({"cmd": "MPD_API_GET_STATS"}, parseStats);
|
||||
@ -640,7 +645,6 @@ function webSocketConnect() {
|
||||
showNotification('Connected to myMPD', '', '', 'success');
|
||||
modalConnectionError.hide();
|
||||
appRoute();
|
||||
sendAPI({"cmd":"MPD_API_GET_OUTPUTNAMES"}, parseOutputnames);
|
||||
}
|
||||
|
||||
socket.onmessage = function got_packet(msg) {
|
||||
@ -807,8 +811,10 @@ function parseOutputnames(obj) {
|
||||
var btns = '';
|
||||
var outputsLen = obj.data.outputs.length;
|
||||
for (var i = 0; i < outputsLen; i++) {
|
||||
btns += '<button id="btnoutput' + obj.data.outputs[i].id +'" data-output-id="' + obj.data.outputs[i].id + '" class="btn btn-secondary btn-block">'+
|
||||
'<span class="material-icons float-left">volume_up</span> ' + obj.data.outputs[i].name + '</button>';
|
||||
btns += '<button data-output-id="' + obj.data.outputs[i].id + '" class="btn btn-secondary btn-block';
|
||||
if (obj.data.outputs[i].state == 1)
|
||||
btns += ' active';
|
||||
btns += '"><span class="material-icons float-left">volume_up</span> ' + obj.data.outputs[i].name + '</button>';
|
||||
}
|
||||
domCache.outputs.innerHTML = btns;
|
||||
}
|
||||
@ -899,11 +905,7 @@ function parseState(obj) {
|
||||
if (last_state == undefined || obj.data.queue_version != last_state.data.queue_version)
|
||||
sendAPI({"cmd": "MPD_API_GET_CURRENT_SONG"}, songChange);
|
||||
|
||||
// Set outputs state
|
||||
var outputsLen = obj.data.outputs.length;
|
||||
for (var i = 0; i < outputsLen; i++) {
|
||||
toggleBtn('btnoutput' + obj.data.outputs[i].id, obj.data.outputs[i].state);
|
||||
}
|
||||
|
||||
|
||||
//clear playback card if not playing
|
||||
if (obj.data.songpos == '-1') {
|
||||
|
@ -214,8 +214,8 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg)
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
}
|
||||
break;
|
||||
case MPD_API_GET_OUTPUTNAMES:
|
||||
n = mympd_put_outputnames(mpd.buf);
|
||||
case MPD_API_GET_OUTPUTS:
|
||||
n = mympd_put_outputs(mpd.buf);
|
||||
break;
|
||||
case MPD_API_TOGGLE_OUTPUT:
|
||||
je = json_scanf(msg.p, msg.len, "{ data: { output:%u, state:%u } }", &uint_buf1, &uint_buf2);
|
||||
@ -619,9 +619,7 @@ char* mympd_get_tag(struct mpd_song const *song, enum mpd_tag_type tag) {
|
||||
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version) {
|
||||
struct mpd_status *status;
|
||||
const struct mpd_audio_format *audioformat;
|
||||
struct mpd_output *output;
|
||||
int len;
|
||||
int nr;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
status = mpd_run_status(mpd.conn);
|
||||
@ -656,24 +654,7 @@ int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsi
|
||||
mpd_status_get_queue_version(status)
|
||||
);
|
||||
|
||||
len += json_printf(&out, ",outputs: [");
|
||||
|
||||
mpd_send_outputs(mpd.conn);
|
||||
nr=0;
|
||||
while ((output = mpd_recv_output(mpd.conn)) != NULL) {
|
||||
if (nr++) len += json_printf(&out, ",");
|
||||
len += json_printf(&out, "{id: %d, state: %d}",
|
||||
mpd_output_get_id(output),
|
||||
mpd_output_get_enabled(output)
|
||||
);
|
||||
mpd_output_free(output);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
len += json_printf(&out, "]}}");
|
||||
len += json_printf(&out, "}}");
|
||||
|
||||
*current_song_id = mpd_status_get_song_id(status);
|
||||
*next_song_id = mpd_status_get_next_song_id(status);
|
||||
@ -756,21 +737,22 @@ int mympd_put_settings(char *buffer) {
|
||||
}
|
||||
|
||||
|
||||
int mympd_put_outputnames(char *buffer) {
|
||||
int mympd_put_outputs(char *buffer) {
|
||||
struct mpd_output *output;
|
||||
int len;
|
||||
int nr;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
len = json_printf(&out,"{type: outputnames, data: { outputs: [");
|
||||
len = json_printf(&out,"{type: outputs, data: { outputs: [");
|
||||
|
||||
mpd_send_outputs(mpd.conn);
|
||||
nr=0;
|
||||
while ((output = mpd_recv_output(mpd.conn)) != NULL) {
|
||||
if (nr++) len += json_printf(&out, ",");
|
||||
len += json_printf(&out,"{id: %d, name: %Q}",
|
||||
len += json_printf(&out,"{id: %d, name: %Q, state: %d}",
|
||||
mpd_output_get_id(output),
|
||||
mpd_output_get_name(output)
|
||||
mpd_output_get_name(output),
|
||||
mpd_output_get_enabled(output)
|
||||
);
|
||||
mpd_output_free(output);
|
||||
}
|
||||
|
@ -77,7 +77,7 @@
|
||||
X(MPD_API_SET_NEXT) \
|
||||
X(MPD_API_SET_PREV) \
|
||||
X(MPD_API_UPDATE_DB) \
|
||||
X(MPD_API_GET_OUTPUTNAMES) \
|
||||
X(MPD_API_GET_OUTPUTS) \
|
||||
X(MPD_API_TOGGLE_OUTPUT) \
|
||||
X(MPD_API_SEND_SHUFFLE) \
|
||||
X(MPD_API_GET_STATS) \
|
||||
@ -141,7 +141,7 @@ void mympd_poll(struct mg_mgr *s);
|
||||
void callback_mympd(struct mg_connection *nc, const struct mg_str msg);
|
||||
int mympd_close_handler(struct mg_connection *c);
|
||||
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version);
|
||||
int mympd_put_outputnames(char *buffer);
|
||||
int mympd_put_outputs(char *buffer);
|
||||
int mympd_put_current_song(char *buffer);
|
||||
int mympd_put_queue(char *buffer, unsigned int offset);
|
||||
int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter);
|
||||
|
Loading…
Reference in New Issue
Block a user