From 290d591c39f9dac29ec2b6e542bf2431b65c355a Mon Sep 17 00:00:00 2001 From: jcorporation Date: Thu, 14 Jun 2018 21:19:36 +0100 Subject: [PATCH] Initial websocket connection with mympd version --- src/mpd_client.c | 14 ++++++++++++++ src/mpd_client.h | 3 ++- src/mympd.c | 6 +----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mpd_client.c b/src/mpd_client.c index 4e6ccf8..2f0ef73 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -77,6 +77,8 @@ void callback_mpd(struct mg_connection *nc, const struct mg_str msg) switch(cmd_id) { + case MPD_API_WELCOME: + n = mympd_put_welcome(mpd.buf); case MPD_API_UPDATE_DB: mpd_run_update(mpd.conn, NULL); break; @@ -767,6 +769,18 @@ int mpd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsign return cur - buffer; } +int mympd_put_welcome(char *buffer) +{ + int len; + len = snprintf(buffer, MAX_SIZE, + "{\"type\":\"welcome\", \"data\":{" + "\"version\":\"%s\"}}", + MYMPD_VERSION + ); + + return len; +} + int mympd_put_settings(char *buffer) { struct mpd_status *status; diff --git a/src/mpd_client.h b/src/mpd_client.h index ba578ae..722901f 100644 --- a/src/mpd_client.h +++ b/src/mpd_client.h @@ -84,7 +84,8 @@ X(MPD_API_GET_ARTISTALBUMS) \ X(MPD_API_GET_ARTISTALBUMTITLES) \ X(MPD_API_GET_ARTISTS) \ - X(MPD_API_GET_CURRENT_SONG) + X(MPD_API_GET_CURRENT_SONG) \ + X(MPD_API_WELCOME) enum mpd_cmd_ids { MPD_CMDS(GEN_ENUM) diff --git a/src/mympd.c b/src/mympd.c index b508eb2..36f2db9 100644 --- a/src/mympd.c +++ b/src/mympd.c @@ -28,7 +28,6 @@ #include #include #include -//#include #include #include "mongoose/mongoose.h" @@ -59,10 +58,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { #ifdef DEBUG fprintf(stdout,"New Websocket connection\n"); #endif - struct mg_str d = {(char *) "MPD_API_GET_SETTINGS", 20 }; - callback_mpd(nc, d); - d.p="MPD_API_GET_OUTPUTS"; - d.len=19; + struct mg_str d = {(char *) "MPD_API_WELCOME" }; callback_mpd(nc, d); break; }