From dc20cf3a7e6c6dbc689d02e9c718a17eedfde3eb Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 8 Sep 2015 16:03:19 +0200 Subject: [PATCH] add topic to JSON directed at Websocket clients --- ot-recorder.c | 7 +++++++ storage.c | 2 +- wdocs/last/functions.js | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ot-recorder.c b/ot-recorder.c index eec4502..6cb8976 100644 --- a/ot-recorder.c +++ b/ot-recorder.c @@ -564,6 +564,13 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m json_delete(geo); } + /* + * I need a unique "key" in the Websocket clients to keep track + * of which device is being updated; use topic. + */ + + json_append_member(wso, "topic", json_mkstring(m->topic)); + if ((js = json_stringify(wso, NULL)) != NULL) { http_ws_push(ud->mgserver, js); free(js); diff --git a/storage.c b/storage.c index 0709853..fed8832 100644 --- a/storage.c +++ b/storage.c @@ -68,7 +68,7 @@ void get_geo(JsonNode *o, char *ghash) /* - * Populate a JSON object (`node') keyed by directory name; each element points + * Populate a JSON object (`obj') keyed by directory name; each element points * to a JSON array with a list of subdirectories on the first level. * * { "jpm": [ "5s", "nex4" ], "jjolie": [ "iphone5" ] } diff --git a/wdocs/last/functions.js b/wdocs/last/functions.js index 6923709..3b6cec6 100644 --- a/wdocs/last/functions.js +++ b/wdocs/last/functions.js @@ -28,11 +28,11 @@ function initialize() { function map_marker(loc) { - var id = loc.tid.replace(/\//g, '-'); + var id = loc.topic.replace(/\//g, '-'); var d; - if (loc.addr && loc.tid) { - d = loc.tid + " " + loc.addr; + if (loc.addr && loc.topic) { + d = loc.topic + " " + loc.addr; } else { d = 'unknown'; }