Comparison

mod_pubsub_eventsource/mod_pubsub_eventsource.lua @ 1242:4d1226220e58

mod_pubsub_eventsource: Publish only the content of known payload types (JSON, 'data' [from MQTT])
author Matthew Wild <mwild1@gmail.com>
date Mon, 02 Dec 2013 03:07:48 +0000
parent 1241:2380a5d71448
child 1343:7dbde05b48a9
comparison
equal deleted inserted replaced
1241:2380a5d71448 1242:4d1226220e58
43 43
44 function handle_update(event) 44 function handle_update(event)
45 module:log("debug", "Item published: %q", event.node); 45 module:log("debug", "Item published: %q", event.node);
46 local node = event.node; 46 local node = event.node;
47 local clientlist = streams[node]; 47 local clientlist = streams[node];
48 local data = "data: "..tostring(event.item):gsub("\n", "\ndata: \n").."\n\n"; 48 local item = event.item;
49 if (item.name == "json" and item.attr.xmlns == "urn:xmpp:json:0") or (item.name == "data" and item.attr.xmlns == "https://prosody.im/protocol/data") then
50 item = item[1];
51 end
52 local data = "data: "..tostring(item):gsub("\n", "\ndata: \n").."\n\n";
49 if not clientlist then module:log("debug", "No clients for %q", node); return; end 53 if not clientlist then module:log("debug", "No clients for %q", node); return; end
50 for response, conn in pairs(clientlist) do 54 for response, conn in pairs(clientlist) do
51 conn:write(data); 55 conn:write(data);
52 end 56 end
53 end 57 end