1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-10-09 11:00:41 +00:00

Revert "Fix handling of multiple client sessions (browsers)"

This reverts commit ac7ad51a0e.
This commit is contained in:
SuperBFG7 2021-08-24 14:13:23 +02:00
parent ac7ad51a0e
commit 7a725e648d

View File

@ -52,7 +52,6 @@ static inline enum mpd_cmd_ids get_cmd_id(char *cmd) {
}
int callback_mpd(struct mg_connection *c) {
struct t_mpd_client_session *s;
enum mpd_cmd_ids cmd_id = get_cmd_id(c->content);
size_t n = 0;
unsigned int uint_buf, uint_buf_2;
@ -62,7 +61,7 @@ int callback_mpd(struct mg_connection *c) {
if (!c->connection_param)
c->connection_param = calloc(1, sizeof(struct t_mpd_client_session));
s = (struct t_mpd_client_session *)c->connection_param;
struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->connection_param;
if (!s->authorized && (cmd_id != MPD_API_AUTHORIZE)) {
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"error\",\"data\":\"not authorized\"}");
@ -363,11 +362,9 @@ int callback_mpd(struct mg_connection *c) {
}
int mpd_close_handler(struct mg_connection *c) {
struct t_mpd_client_session *s;
/* Cleanup session data */
if (c->connection_param) {
s = (struct t_mpd_client_session *)c->connection_param;
struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->connection_param;
if (s->auth_token)
free(s->auth_token);
free(c->connection_param);
@ -377,7 +374,6 @@ int mpd_close_handler(struct mg_connection *c) {
}
static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
struct t_mpd_client_session *s;
size_t n;
if (!c->is_websocket)
@ -386,7 +382,7 @@ static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
if (!c->connection_param)
return MG_TRUE;
s = (struct t_mpd_client_session *)c->connection_param;
struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->connection_param;
if (!s->authorized)
return MG_TRUE;
@ -404,17 +400,7 @@ static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"disconnected\"}");
mg_websocket_write(c, 1, mpd.buf, n);
} else {
if (ev == MG_POLL) {
mpd.buf_size = mpd_put_state(mpd.buf, &mpd.song_id, &mpd.queue_version);
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
mpd.buf_size = mpd_put_outputs(mpd.buf, 0);
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
mpd.buf_size = mpd_put_channels(mpd.buf);
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
} else {
fprintf(stdout, "notify_callback: %i, %s\n", mpd.buf_size, mpd.buf);
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
}
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
if (s->song_id != mpd.song_id) {
n = mpd_put_current_song(mpd.buf);
@ -487,20 +473,21 @@ void mpd_poll(struct mg_server *s) {
break;
case MPD_CONNECTED:
// mpd.buf_size = mpd_put_state(mpd.buf, &mpd.song_id, &mpd.queue_version);
mpd.buf_size = mpd_put_state(mpd.buf, &mpd.song_id, &mpd.queue_version);
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
c->callback_param = NULL;
mpd_notify_callback(c, MG_POLL);
}
mpd.buf_size = mpd_put_outputs(mpd.buf, 0);
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
c->callback_param = NULL;
mpd_notify_callback(c, MG_POLL);
}
mpd.buf_size = mpd_put_channels(mpd.buf);
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
c->callback_param = NULL;
mpd_notify_callback(c, MG_POLL);
}
/* mpd.buf_size = mpd_put_outputs(mpd.buf, 0);
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s,
c)) { c->callback_param = NULL; mpd_notify_callback(c, MG_POLL);
}
mpd.buf_size = mpd_put_channels(mpd.buf);
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s,
c)) { c->callback_param = NULL; mpd_notify_callback(c, MG_POLL);
}
*/
break;
}
}