1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-27 03:10:26 +00:00

Initial websocket connection with mympd version

This commit is contained in:
jcorporation 2018-06-14 21:19:36 +01:00
parent f119a69b96
commit 290d591c39
3 changed files with 17 additions and 6 deletions

View File

@ -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;

View File

@ -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)

View File

@ -28,7 +28,6 @@
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
//#include <pthread.h>
#include <pwd.h>
#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;
}