Comparison

mod_conversejs/mod_conversejs.lua @ 2919:0ea93da47db9

mod_conversejs: Allow passing arbitrary options trough to Converse.js
author Kim Alvefur <zash@zash.se>
date Sat, 10 Mar 2018 00:05:30 +0100
parent 2694:38c66b58b470
child 2921:3264058ae54f
comparison
equal deleted inserted replaced
2918:d2d0715f30d9 2919:0ea93da47db9
15 <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.conversejs.org/css/converse.min.css"> 15 <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.conversejs.org/css/converse.min.css">
16 <script src="https://cdn.conversejs.org/dist/converse.min.js"></script> 16 <script src="https://cdn.conversejs.org/dist/converse.min.js"></script>
17 <body><script>converse.initialize(%s);</script> 17 <body><script>converse.initialize(%s);</script>
18 ]] 18 ]]
19 19
20 local more_options = module:get_option("conversejs_options");
21
20 module:provides("http", { 22 module:provides("http", {
21 route = { 23 route = {
22 GET = function (event) 24 GET = function (event)
23 event.response.headers.content_type = "text/html"; 25 local converse_options = {
24 return template:format(json_encode({
25 -- debug = true,
26 bosh_service_url = module:http_url("bosh","/http-bind"); 26 bosh_service_url = module:http_url("bosh","/http-bind");
27 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil; 27 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil;
28 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login"; 28 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login";
29 jid = module.host; 29 jid = module.host;
30 })); 30 };
31
32 if type(more_options) == "table" then
33 for k,v in pairs(more_options) do
34 converse_options[k] = v;
35 end
36 end
37
38 event.response.headers.content_type = "text/html";
39 return template:format(json_encode(converse_options));
31 end; 40 end;
32 } 41 }
33 }); 42 });
34 43