mirror of
https://github.com/SuperBFG7/ympd
synced 2025-04-07 11:17:02 +00:00
Feat: finished mpd idle usage
This commit is contained in:
parent
f69ec1820c
commit
f0b577378e
@ -646,6 +646,7 @@ function webSocketConnect() {
|
||||
showNotification('Connected to myMPD', '', '', 'success');
|
||||
modalConnectionError.hide();
|
||||
appRoute();
|
||||
sendAPI({"cmd":"MPD_API_GET_STATE"}, parseState);
|
||||
}
|
||||
|
||||
socket.onmessage = function got_packet(msg) {
|
||||
|
@ -37,9 +37,6 @@
|
||||
#include "config.h"
|
||||
#include "../dist/src/frozen/frozen.h"
|
||||
|
||||
/* forward declaration */
|
||||
void mympd_notify(struct mg_mgr *s);
|
||||
|
||||
const char * mpd_cmd_strs[] = {
|
||||
MPD_CMDS(GEN_STR)
|
||||
};
|
||||
@ -462,7 +459,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
||||
break;
|
||||
case MPD_API_GET_STATS:
|
||||
n = mympd_put_stats(mpd.buf);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (mpd.conn_state == MPD_CONNECTED && mpd_connection_get_error(mpd.conn) != MPD_ERROR_SUCCESS) {
|
||||
@ -497,11 +494,15 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
int mympd_close_handler(struct mg_connection *c) {
|
||||
/* Cleanup session data */
|
||||
if (c->user_data)
|
||||
free(c->user_data);
|
||||
return 0;
|
||||
void mympd_notify(struct mg_mgr *s) {
|
||||
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
|
||||
if (!is_websocket(c))
|
||||
continue;
|
||||
mg_send_websocket_frame(c, WEBSOCKET_OP_TEXT, mpd.buf, strlen(mpd.buf));
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"NOTIFY: %s\n", mpd.buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void mympd_poll(struct mg_mgr *s, int timeout) {
|
||||
@ -547,7 +548,6 @@ void mympd_poll(struct mg_mgr *s, int timeout) {
|
||||
fprintf(stderr, "MPD connection failed.\n");
|
||||
snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"disconnected\"}");
|
||||
mympd_notify(s);
|
||||
|
||||
case MPD_DISCONNECT:
|
||||
case MPD_RECONNECT:
|
||||
if (mpd.conn != NULL)
|
||||
@ -569,21 +569,8 @@ void mympd_poll(struct mg_mgr *s, int timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
void mympd_notify(struct mg_mgr *s) {
|
||||
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
|
||||
if (!is_websocket(c))
|
||||
continue;
|
||||
mg_send_websocket_frame(c, WEBSOCKET_OP_TEXT, mpd.buf, strlen(mpd.buf));
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"NOTIFY: %s\n", mpd.buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void mympd_parse_idle(struct mg_mgr *s) {
|
||||
// mpd_connection_set_timeout(mpd.conn, 60);
|
||||
enum mpd_idle idle_bitmask = mpd_recv_idle(mpd.conn, false);
|
||||
// mpd_connection_set_timeout(mpd.conn, mpd.timeout);
|
||||
int len;
|
||||
|
||||
for (unsigned j = 0;; ++j) {
|
||||
@ -659,13 +646,13 @@ int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsig
|
||||
mpd.conn_state = MPD_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
if (status) {
|
||||
else {
|
||||
audioformat = mpd_status_get_audio_format(status);
|
||||
}
|
||||
|
||||
len = json_printf(&out,"{type: update_state, data:{"
|
||||
len = json_printf(&out,"{type: update_state, data: {"
|
||||
"state:%d, volume:%d, songPos: %d, elapsedTime: %d, "
|
||||
"totalTime:%d, currentSongId: %d, kbitrate: %d, "
|
||||
"totalTime: %d, currentSongId: %d, kbitrate: %d, "
|
||||
"audioFormat: { sampleRate: %d, bits: %d, channels: %d}, "
|
||||
"queueLength: %d, nextSongPos: %d, nextSongId: %d, "
|
||||
"queueVersion: %d",
|
||||
@ -742,8 +729,8 @@ int mympd_put_settings(char *buffer) {
|
||||
}
|
||||
|
||||
len = json_printf(&out,
|
||||
"{type:settings, data:{"
|
||||
"repeat:%d, single:%d, crossfade:%d, consume:%d, random:%d, "
|
||||
"{type: settings, data: {"
|
||||
"repeat: %d, single: %d, crossfade: %d, consume: %d, random: %d, "
|
||||
"mixrampdb: %f, mixrampdelay: %f, mpdhost : %Q, mpdport: %d, passwort_set: %B, "
|
||||
"streamport: %d, coverimage: %Q, max_elements_per_page: %d, replaygain: %Q,"
|
||||
"notificationWeb: %d, notificationPage: %d"
|
||||
|
@ -122,30 +122,30 @@ struct t_mpd {
|
||||
} mpd;
|
||||
|
||||
typedef struct {
|
||||
int mpdport;
|
||||
const char* mpdhost;
|
||||
const char* mpdpass;
|
||||
const char* webport;
|
||||
bool ssl;
|
||||
const char* sslport;
|
||||
const char* sslcert;
|
||||
const char* sslkey;
|
||||
const char* user;
|
||||
int streamport;
|
||||
const char* coverimage;
|
||||
const char* statefile;
|
||||
int mpdport;
|
||||
const char* mpdhost;
|
||||
const char* mpdpass;
|
||||
const char* webport;
|
||||
bool ssl;
|
||||
const char* sslport;
|
||||
const char* sslcert;
|
||||
const char* sslkey;
|
||||
const char* user;
|
||||
int streamport;
|
||||
const char* coverimage;
|
||||
const char* statefile;
|
||||
} configuration;
|
||||
|
||||
configuration config;
|
||||
|
||||
static int is_websocket(const struct mg_connection *nc) {
|
||||
return nc->flags & MG_F_IS_WEBSOCKET;
|
||||
return nc->flags & MG_F_IS_WEBSOCKET;
|
||||
}
|
||||
|
||||
void mympd_poll(struct mg_mgr *sm, int timeout);
|
||||
void mympd_parse_idle(struct mg_mgr *s);
|
||||
void callback_mympd(struct mg_connection *nc, const struct mg_str msg);
|
||||
int mympd_close_handler(struct mg_connection *c);
|
||||
void mympd_notify(struct mg_mgr *s);
|
||||
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version);
|
||||
int mympd_put_outputs(char *buffer);
|
||||
int mympd_put_current_song(char *buffer);
|
||||
@ -166,4 +166,3 @@ int mympd_put_songdetails(char *buffer, char *uri);
|
||||
int mympd_queue_crop(char *buffer);
|
||||
void mympd_disconnect();
|
||||
#endif
|
||||
|
||||
|
@ -84,7 +84,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
#ifdef DEBUG
|
||||
printf("Websocket connection closed\n");
|
||||
#endif
|
||||
mympd_close_handler(nc);
|
||||
// mympd_close_handler(nc);
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG
|
||||
@ -255,10 +255,9 @@ int main(int argc, char **argv) {
|
||||
if (config.ssl == true)
|
||||
printf("myMPD started on ssl port %s\n", config.sslport);
|
||||
|
||||
//Main loop for http handling
|
||||
while (s_signal_received == 0) {
|
||||
mg_mgr_poll(&mgr, 100);
|
||||
mympd_poll(&mgr, 1);
|
||||
mympd_poll(&mgr, 0);
|
||||
}
|
||||
mg_mgr_free(&mgr);
|
||||
mympd_disconnect();
|
||||
|
Loading…
x
Reference in New Issue
Block a user