From 470de65821cef3d6fb66f1e52ce3da5c70859cd9 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 8 Sep 2015 12:57:09 +0200 Subject: [PATCH] send to WS for locations only --- ot-recorder.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/ot-recorder.c b/ot-recorder.c index 5692bbf..bb95a66 100644 --- a/ot-recorder.c +++ b/ot-recorder.c @@ -385,12 +385,6 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m time(&now); monitorhook(ud, now, m->topic); -#ifdef HAVE_HTTP - if (ud->mgserver) { - http_ws_push(ud->mgserver, m->payload); - } -#endif - if (m->payloadlen == 0) { return; } @@ -551,6 +545,33 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m * We have exactly three topic parts (owntracks/user/device), and valid JSON. */ +#ifdef HAVE_HTTP + if (ud->mgserver) { + + /* + * Create a new location object containing all the bits and + * pieces we need and push that into connected Websockets. + * TODO: clean up + */ + + JsonNode *geo, *wso = json_mkobject(); + char *js; + + json_copy_to_object(wso, json, TRUE); + + if ((geo = gcache_json_get(ud->gc, utstring_body(ghash))) != NULL) { + json_copy_to_object(wso, geo, FALSE); + json_delete(geo); + } + + if ((js = json_stringify(wso, NULL)) != NULL) { + http_ws_push(ud->mgserver, m->payload); + free(js); + } + json_delete(wso); + } +#endif + if ((jsonstring = json_stringify(json, NULL)) != NULL) { char *js;