Changeset

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
parents 1241:2380a5d71448
children 1243:c2bf6b2102aa
files mod_pubsub_eventsource/mod_pubsub_eventsource.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pubsub_eventsource/mod_pubsub_eventsource.lua	Mon Dec 02 03:06:10 2013 +0000
+++ b/mod_pubsub_eventsource/mod_pubsub_eventsource.lua	Mon Dec 02 03:07:48 2013 +0000
@@ -45,7 +45,11 @@
 	module:log("debug", "Item published: %q", event.node);
 	local node = event.node;
 	local clientlist = streams[node];
-	local data = "data: "..tostring(event.item):gsub("\n", "\ndata: \n").."\n\n";
+	local item = event.item;
+	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
+		item = item[1];
+	end
+	local data = "data: "..tostring(item):gsub("\n", "\ndata: \n").."\n\n";
 	if not clientlist then module:log("debug", "No clients for %q", node); return; end
 	for response, conn in pairs(clientlist) do
 		conn:write(data);