Annotate

mod_conversejs/mod_conversejs.lua @ 3325:d92a6daf3c8f

mod_auth_ldap: fix ldap_admins documentation
author Maxime “pep” Buquet <pep@bouah.net>
date Sat, 22 Sep 2018 16:25:26 +0100
parent 3324:3114b403362d
child 3329:43d0e298ddda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- mod_conversejs
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2017 Kim Alvefur
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local json_encode = require"util.json".encode;
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 module:depends"bosh";
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local has_ws = pcall(function ()
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 module:depends("websocket");
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 end);
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
3312
e714be00aaad mod_conversejs: Factor JavaScript part out of HTML
Kim Alvefur <zash@zash.se>
parents: 3310
diff changeset
12 local html_template = [[
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 <!DOCTYPE html>
3038
48cbf6a3f112 mod_conversejs: Make HTML more well-formed
Kim Alvefur <zash@zash.se>
parents: 2998
diff changeset
14 <html>
48cbf6a3f112 mod_conversejs: Make HTML more well-formed
Kim Alvefur <zash@zash.se>
parents: 2998
diff changeset
15 <head>
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 <meta charset="utf-8">
3323
2cf82cad1910 mod_conversejs: Update to Conversejs 4.0.1
Kim Alvefur <zash@zash.se>
parents: 3314
diff changeset
17 <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.conversejs.org/4.0.1/css/converse.min.css"/>
2cf82cad1910 mod_conversejs: Update to Conversejs 4.0.1
Kim Alvefur <zash@zash.se>
parents: 3314
diff changeset
18 <script charset="utf-8" src="https://cdn.conversejs.org/4.0.1/dist/converse.min.js"></script>
3324
3114b403362d mod_conversejs: Add a page title
Kim Alvefur <zash@zash.se>
parents: 3323
diff changeset
19 <title>Prosody IM and Converse.js</title>
3038
48cbf6a3f112 mod_conversejs: Make HTML more well-formed
Kim Alvefur <zash@zash.se>
parents: 2998
diff changeset
20 </head>
3039
df77580be2f0 mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents: 3038
diff changeset
21 <body>
df77580be2f0 mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents: 3038
diff changeset
22 <noscript>
df77580be2f0 mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents: 3038
diff changeset
23 <h1>Converse.js</h1>
df77580be2f0 mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents: 3038
diff changeset
24 <p>I&apos;m sorry, but this XMPP client application won&apos;t work without JavaScript.</p>
3040
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
25 <p>Perhaps you would like to try one of these clients:</p>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
26 <dl>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
27 <dt>Desktop</dt>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
28 <dd><ul>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
29 <li><a href="https://gajim.org/">Gajim</a></li>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
30 <li><a href="https://poez.io/">Poezio</a></li>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
31 <li><a href="https://swift.im/">Swift</a></li>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
32 </ul></dd>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
33 <dt>Mobile</dt>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
34 <dd><ul>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
35 <li><a href="https://github.com/siacs/Conversations">Conversations</a></li>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
36 <li><a href="https://yaxim.org/">Yaxim</a></li>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
37 </ul></dd>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
38 </dl>
81b75086a781 mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents: 3039
diff changeset
39 <p><a href="https://xmpp.org/software/clients.html">More clients...</a></p>
3039
df77580be2f0 mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents: 3038
diff changeset
40 </noscript>
3312
e714be00aaad mod_conversejs: Factor JavaScript part out of HTML
Kim Alvefur <zash@zash.se>
parents: 3310
diff changeset
41 <script>%s</script>
3039
df77580be2f0 mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents: 3038
diff changeset
42 </body>
3038
48cbf6a3f112 mod_conversejs: Make HTML more well-formed
Kim Alvefur <zash@zash.se>
parents: 2998
diff changeset
43 </html>
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 ]]
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45
3312
e714be00aaad mod_conversejs: Factor JavaScript part out of HTML
Kim Alvefur <zash@zash.se>
parents: 3310
diff changeset
46 js_template = "converse.initialize(%s);";
e714be00aaad mod_conversejs: Factor JavaScript part out of HTML
Kim Alvefur <zash@zash.se>
parents: 3310
diff changeset
47
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
48 local more_options = module:get_option("conversejs_options");
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
49
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
50 local function get_converse_options()
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
51 local allow_registration = module:get_option_boolean("allow_registration", false);
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
52 local converse_options = {
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
53 bosh_service_url = module:http_url("bosh","/http-bind");
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
54 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
55 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login";
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
56 jid = module.host;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
57 default_domain = module.host;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
58 domain_placeholder = module.host;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
59 allow_registration = allow_registration;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
60 registration_domain = allow_registration and module.host or nil;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
61 };
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
62
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
63 if type(more_options) == "table" then
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
64 for k,v in pairs(more_options) do
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
65 converse_options[k] = v;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
66 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
67 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
68
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
69 return converse_options;
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
70 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
71
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 module:provides("http", {
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 route = {
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 GET = function (event)
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
75 local converse_options = get_converse_options();
3310
908b2bc05d26 mod_conversejs: Restore accidentally removed configuration option handling
Kim Alvefur <zash@zash.se>
parents: 3309
diff changeset
76
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
77 event.response.headers.content_type = "text/html";
3312
e714be00aaad mod_conversejs: Factor JavaScript part out of HTML
Kim Alvefur <zash@zash.se>
parents: 3310
diff changeset
78 return html_template:format(js_template:format(json_encode(converse_options)));
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 end;
3314
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
80
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
81 ["GET /prosody-converse.js"] = function (event)
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
82 local converse_options = get_converse_options();
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
83
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
84 event.response.headers.content_type = "application/javascript";
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
85 return js_template:format(json_encode(converse_options));
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
86 end;
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 }
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 });
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89