annotate mod_conversejs/mod_conversejs.lua @ 4881:09b8144051ea

mod_invites_page: Fix templates including stray inviter name (thanks Menel) The util.interpolation syntax `{var?placeholder}` appears to have been intended as an if-not, but this syntax will always return either the variable or the placeholder-template.
author Kim Alvefur <zash@zash.se>
date Wed, 02 Feb 2022 11:22:50 +0100
parents 0c9128145bcf
children 99cdc7cde150
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;
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
5 local xml_escape = require "util.stanza".xml_escape;
4176
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
6 local urlencode = require "util.http".urlencode;
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
7 local render = require "util.interpolation".new("%b{}", xml_escape, { json = json_encode });
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
3329
43d0e298ddda mod_conversejs: Explicitly depend on mod_http
Kim Alvefur <zash@zash.se>
parents: 3324
diff changeset
9 module:depends"http";
3363
2681f74750b2 mod_conversejs: Weaken dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents: 3348
diff changeset
10
2681f74750b2 mod_conversejs: Weaken dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents: 3348
diff changeset
11 local has_bosh = pcall(function ()
2681f74750b2 mod_conversejs: Weaken dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents: 3348
diff changeset
12 module:depends"bosh";
2681f74750b2 mod_conversejs: Weaken dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents: 3348
diff changeset
13 end);
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 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
16 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
17 end);
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18
4855
0c9128145bcf mod_conversejs: Reduce mod_bookmarks dependency to a warning
Kim Alvefur <zash@zash.se>
parents: 4849
diff changeset
19 do
0c9128145bcf mod_conversejs: Reduce mod_bookmarks dependency to a warning
Kim Alvefur <zash@zash.se>
parents: 4849
diff changeset
20 local mods = module:get_option_inherited_set("modules_enabled") - module:get_option_inherited_set("modules_disabled");
0c9128145bcf mod_conversejs: Reduce mod_bookmarks dependency to a warning
Kim Alvefur <zash@zash.se>
parents: 4849
diff changeset
21 if not mods:contains("bookmarks") or mods:contains("bookmarks2") then
0c9128145bcf mod_conversejs: Reduce mod_bookmarks dependency to a warning
Kim Alvefur <zash@zash.se>
parents: 4849
diff changeset
22 module:log("warn", "Converse.js does not work well without mod_bookmarks, consider enabling it");
0c9128145bcf mod_conversejs: Reduce mod_bookmarks dependency to a warning
Kim Alvefur <zash@zash.se>
parents: 4849
diff changeset
23 end
4849
192b7aaa3888 mod_conversejs: Try to depend on mod_bookmarks in trunk else mod_bookmarks2
Kim Alvefur <zash@zash.se>
parents: 4843
diff changeset
24 end
3494
4feab7e87675 mod_conversejs: Add dependency on mod_bookmarks
Kim Alvefur <zash@zash.se>
parents: 3492
diff changeset
25
3331
d98341bca458 mod_conversejs: Allow overriding CDN URL, or script/css URLs independently
Matthew Wild <mwild1@gmail.com>
parents: 3329
diff changeset
26 local cdn_url = module:get_option_string("conversejs_cdn", "https://cdn.conversejs.org");
d98341bca458 mod_conversejs: Allow overriding CDN URL, or script/css URLs independently
Matthew Wild <mwild1@gmail.com>
parents: 3329
diff changeset
27
3348
f753cf4f7224 mod_conversejs: Default to latest version of Converse.js
Kim Alvefur <zash@zash.se>
parents: 3347
diff changeset
28 local version = module:get_option_string("conversejs_version", "");
3347
823156d5885b mod_conversejs: Strip extra slash if version is set to the empty string
Kim Alvefur <zash@zash.se>
parents: 3337
diff changeset
29 if version ~= "" then version = "/" .. version end
4147
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
30
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
31 local serve_dist = nil;
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
32 local resources = module:get_option_path("conversejs_resources");
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
33 if resources then
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
34 local serve;
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
35 if not pcall(function()
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
36 -- Prosody >= trunk / 0.12
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
37 local http_files = require "net.http.files";
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
38 serve = http_files.serve;
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
39 end) then
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
40 -- Prosody <= 0.11
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
41 serve = module:depends "http_files".serve;
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
42 end
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
43 local mime_map = module:shared("/*/http_files/mime").types or {css = "text/css"; js = "application/javascript"};
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
44 serve_dist = serve({path = resources; mime_map = mime_map});
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
45
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
46 cdn_url = module:http_url();
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
47 end
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
48
3347
823156d5885b mod_conversejs: Strip extra slash if version is set to the empty string
Kim Alvefur <zash@zash.se>
parents: 3337
diff changeset
49 local js_url = module:get_option_string("conversejs_script", cdn_url..version.."/dist/converse.min.js");
3641
58b49d883f0c mod_conversejs: Change CSS URL
Kim Alvefur <zash@zash.se>
parents: 3599
diff changeset
50 local css_url = module:get_option_string("conversejs_css", cdn_url..version.."/dist/converse.min.css");
3331
d98341bca458 mod_conversejs: Allow overriding CDN URL, or script/css URLs independently
Matthew Wild <mwild1@gmail.com>
parents: 3329
diff changeset
51
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
52 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
53
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
54 do
4165
6b2a1c9ef6e2 mod_conversejs: Move templates into a directory for easier install
Kim Alvefur <zash@zash.se>
parents: 4153
diff changeset
55 local template_filename = module:get_option_string(module.name .. "_html_template", "templates/template.html");
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
56 local template_file, err = module:load_resource(template_filename);
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
57 if template_file then
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
58 html_template, err = template_file:read("*a");
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
59 template_file:close();
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
60 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
61 if not html_template then
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
62 module:log("error", "Error loading HTML template: %s", err);
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
63 html_template = render("<h1>mod_{module} could not read the template</h1>\
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
64 <p>Tried to open <b>{filename}</b></p>\
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
65 <pre>{error}</pre>",
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
66 { module = module.name, filename = template_filename, error = err });
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
67 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
68 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
69
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
70 local js_template;
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
71 do
4165
6b2a1c9ef6e2 mod_conversejs: Move templates into a directory for easier install
Kim Alvefur <zash@zash.se>
parents: 4153
diff changeset
72 local template_filename = module:get_option_string(module.name .. "_js_template", "templates/template.js");
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
73 local template_file, err = module:load_resource(template_filename);
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
74 if template_file then
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
75 js_template, err = template_file:read("*a");
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
76 template_file:close();
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
77 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
78 if not js_template then
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
79 module:log("error", "Error loading JS template: %s", err);
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
80 js_template = render("console.log(\"mod_{module} could not read the JS template: %s\", {error|json})",
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
81 { module = module.name, filename = template_filename, error = err });
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
82 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
83 end
3312
e714be00aaad mod_conversejs: Factor JavaScript part out of HTML
Kim Alvefur <zash@zash.se>
parents: 3310
diff changeset
84
3332
4fdd8b77da54 mod_conversejs: Variable rename for clarity (user may override options)
Matthew Wild <mwild1@gmail.com>
parents: 3331
diff changeset
85 local user_options = module:get_option("conversejs_options");
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
86
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
87 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
88 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
89 local converse_options = {
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
90 -- Auto-detected connection endpoints
3363
2681f74750b2 mod_conversejs: Weaken dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents: 3348
diff changeset
91 bosh_service_url = has_bosh and module:http_url("bosh","/http-bind") or nil;
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
92 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
93 -- Since we provide those, XEP-0156 based auto-discovery should not be used
4047
36b6e3e3f9e2 mod_conversejs: Disable automatic BOSH/WS endpoint discovery
Kim Alvefur <zash@zash.se>
parents: 3737
diff changeset
94 discover_connection_methods = false;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
95 -- Authentication mode to use (normal or guest login)
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
96 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login";
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
97 -- Host to connect to for anonymous access
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
98 jid = module.host;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
99 -- Let users login with only username
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
100 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
101 domain_placeholder = module.host;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
102 -- If registration is enabled
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
103 allow_registration = allow_registration;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
104 -- and if it is, which domain to register with
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
105 registration_domain = allow_registration and module.host or nil;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
106 -- Path to resources like emoji, icons, sounds
4153
4ee2a90d3818 mod_conversejs: Generate 'assets_path' to fix locating certain resources
Kim Alvefur <zash@zash.se>
parents: 4147
diff changeset
107 assets_path = cdn_url..version.."/dist/";
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
108 -- Default most suited for use as a "normal" client
3737
49e65a7e9415 mod_conversejs: Use the fullscreen view mode by default
Kim Alvefur <zash@zash.se>
parents: 3641
diff changeset
109 view_mode = "fullscreen";
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
110 };
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
111
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
112 -- Let config override the above defaults
3332
4fdd8b77da54 mod_conversejs: Variable rename for clarity (user may override options)
Matthew Wild <mwild1@gmail.com>
parents: 3331
diff changeset
113 if type(user_options) == "table" then
4fdd8b77da54 mod_conversejs: Variable rename for clarity (user may override options)
Matthew Wild <mwild1@gmail.com>
parents: 3331
diff changeset
114 for k,v in pairs(user_options) do
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
115 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
116 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
117 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
118
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
119 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
120 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
121
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
122 local add_tags = module:get_option_array("conversejs_tags", {});
3333
5be90562e14b mod_conversejs: Allow custom tags to be inserted into the generated HTML
Matthew Wild <mwild1@gmail.com>
parents: 3332
diff changeset
123
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 module:provides("http", {
3337
b46bb9392efe mod_conversejs: Set a friendly name for mod_http_index
Kim Alvefur <zash@zash.se>
parents: 3333
diff changeset
125 title = "Converse.js";
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 route = {
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 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
128 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
129
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
130 event.response.headers.content_type = "text/html";
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
131 return render(html_template, {
3599
42fa833169bb mod_conversejs: Make title configurable (fixes #1362)
Kim Alvefur <zash@zash.se>
parents: 3598
diff changeset
132 service_name = module:get_option_string("name");
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
133 header_scripts = { js_url };
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
134 header_style = { css_url };
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
135 header_tags = add_tags;
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
136 conversejs = {
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
137 options = converse_options;
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
138 startup = { script = js_template:format(json_encode(converse_options)); }
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
139 };
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
140 });
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 end;
3314
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
142
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
143 ["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
144 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
145
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
146 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
147 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
148 end;
4147
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
149 ["GET /dist/*"] = serve_dist;
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 }
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 });
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152
4176
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
153 module:provides("site-app", {
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
154 name = "Converse.js";
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
155 text = [[A free and open-source XMPP chat client in your browser]];
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
156 image = "assets/logos/converse-js.svg";
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
157 link = "https://conversejs.org/";
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
158 magic_link_format = "/register?t={invite.token}&c=converse-js";
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
159 login_link_format = module:http_url();
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
160 platforms = { "Web" };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
161 download = {
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
162 buttons = {
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
163 {
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
164 text = "Open web chat";
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
165 url = module:http_url();
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
166 };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
167 };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
168 };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
169
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
170 });