Software /
code /
prosody-modules
Annotate
mod_conversejs/mod_conversejs.lua @ 3257:f09d92579158
mod_atom: Add a brief README
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 24 Aug 2018 16:16:30 +0200 |
parent | 3040:81b75086a781 |
child | 3305:122767430a97 |
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 |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local template = [[ |
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"> |
2921
3264058ae54f
mod_conversejs: Hack in support for changing the CSS if InVerse mode is enabled
Kim Alvefur <zash@zash.se>
parents:
2919
diff
changeset
|
17 <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.conversejs.org/css/%s.min.css"> |
2980
ba6466fa6823
mod_conversejs: Specify a charset on script tag to prevent Browser from guessing
Kim Alvefur <zash@zash.se>
parents:
2934
diff
changeset
|
18 <script charset="utf-8" src="https://cdn.conversejs.org/dist/converse.min.js"></script> |
3038
48cbf6a3f112
mod_conversejs: Make HTML more well-formed
Kim Alvefur <zash@zash.se>
parents:
2998
diff
changeset
|
19 </head> |
3039
df77580be2f0
mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents:
3038
diff
changeset
|
20 <body> |
df77580be2f0
mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents:
3038
diff
changeset
|
21 <noscript> |
df77580be2f0
mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents:
3038
diff
changeset
|
22 <h1>Converse.js</h1> |
df77580be2f0
mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents:
3038
diff
changeset
|
23 <p>I'm sorry, but this XMPP client application won'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
|
24 <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
|
25 <dl> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
26 <dt>Desktop</dt> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
27 <dd><ul> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
28 <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
|
29 <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
|
30 <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
|
31 </ul></dd> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
32 <dt>Mobile</dt> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
33 <dd><ul> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
34 <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
|
35 <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
|
36 </ul></dd> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
37 </dl> |
81b75086a781
mod_conversejs: Suggest some alternative cliets if JavaScript is disabled
Kim Alvefur <zash@zash.se>
parents:
3039
diff
changeset
|
38 <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
|
39 </noscript> |
df77580be2f0
mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents:
3038
diff
changeset
|
40 <script>converse.initialize(%s);</script> |
df77580be2f0
mod_conversejs: Appologise for the JavaScript
Kim Alvefur <zash@zash.se>
parents:
3038
diff
changeset
|
41 </body> |
3038
48cbf6a3f112
mod_conversejs: Make HTML more well-formed
Kim Alvefur <zash@zash.se>
parents:
2998
diff
changeset
|
42 </html> |
2657
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 ]] |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 |
2919
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
45 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
|
46 |
2657
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 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
|
48 route = { |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 GET = function (event) |
2998
719b76ee0578
mod_conversejs: Offer the current domain if registration is enabled to skip the server selection and improve UX
Kim Alvefur <zash@zash.se>
parents:
2980
diff
changeset
|
50 local allow_registration = module:get_option_boolean("allow_registration", false); |
2919
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
51 local 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
|
52 bosh_service_url = module:http_url("bosh","/http-bind"); |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil; |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login"; |
2694
38c66b58b470
mod_conversejs: Pass host jid (needed for anonymous auth)
Kim Alvefur <zash@zash.se>
parents:
2664
diff
changeset
|
55 jid = module.host; |
2933
8858cef9ed27
mod_conversejs: Pass current domain as 'default_domain'
Kim Alvefur <zash@zash.se>
parents:
2921
diff
changeset
|
56 default_domain = module.host; |
2934
5c60df8b1a07
mod_conversejs: Pass information about if and how of account registration
Kim Alvefur <zash@zash.se>
parents:
2933
diff
changeset
|
57 domain_placeholder = module.host; |
2998
719b76ee0578
mod_conversejs: Offer the current domain if registration is enabled to skip the server selection and improve UX
Kim Alvefur <zash@zash.se>
parents:
2980
diff
changeset
|
58 allow_registration = allow_registration; |
719b76ee0578
mod_conversejs: Offer the current domain if registration is enabled to skip the server selection and improve UX
Kim Alvefur <zash@zash.se>
parents:
2980
diff
changeset
|
59 registration_domain = allow_registration and module.host or nil; |
2919
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
60 }; |
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
61 |
2921
3264058ae54f
mod_conversejs: Hack in support for changing the CSS if InVerse mode is enabled
Kim Alvefur <zash@zash.se>
parents:
2919
diff
changeset
|
62 local view_mode_css = "converse"; |
2919
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
63 if type(more_options) == "table" then |
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
64 for k,v in pairs(more_options) do |
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
65 converse_options[k] = v; |
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
66 end |
2921
3264058ae54f
mod_conversejs: Hack in support for changing the CSS if InVerse mode is enabled
Kim Alvefur <zash@zash.se>
parents:
2919
diff
changeset
|
67 if more_options.view_mode == "fullscreen" then |
3264058ae54f
mod_conversejs: Hack in support for changing the CSS if InVerse mode is enabled
Kim Alvefur <zash@zash.se>
parents:
2919
diff
changeset
|
68 view_mode_css = "inverse"; |
3264058ae54f
mod_conversejs: Hack in support for changing the CSS if InVerse mode is enabled
Kim Alvefur <zash@zash.se>
parents:
2919
diff
changeset
|
69 end |
2919
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
70 end |
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
71 |
0ea93da47db9
mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents:
2694
diff
changeset
|
72 event.response.headers.content_type = "text/html"; |
2921
3264058ae54f
mod_conversejs: Hack in support for changing the CSS if InVerse mode is enabled
Kim Alvefur <zash@zash.se>
parents:
2919
diff
changeset
|
73 return template:format(view_mode_css, 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
|
74 end; |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 } |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 }); |
6f5c99c9f6cc
mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 |