add topic to JSON directed at Websocket clients

This commit is contained in:
Jan-Piet Mens 2015-09-08 16:03:19 +02:00
parent f84947360c
commit dc20cf3a7e
3 changed files with 11 additions and 4 deletions

View File

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

View File

@ -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" ] }

View File

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