Annotate

mod_conversejs/mod_conversejs.lua @ 6301:fa45ae704b79

mod_cloud_notify: Update Readme diff --git a/mod_cloud_notify/README.md b/mod_cloud_notify/README.md --- a/mod_cloud_notify/README.md +++ b/mod_cloud_notify/README.md @@ -1,109 +1,106 @@ ---- -labels: -- 'Stage-Beta' -summary: 'XEP-0357: Cloud push notifications' ---- +# Introduction -Introduction -============ +This module enables support for sending "push notifications" to clients +that need it, typically those running on certain mobile devices. -This module enables support for sending "push notifications" to clients that -need it, typically those running on certain mobile devices. +As well as this module, your client must support push notifications (the +apps that need it generally do, of course) and the app developer's push +gateway must be reachable from your Prosody server (this happens over a +normal XMPP server-to-server 's2s' connection). -As well as this module, your client must support push notifications (the apps -that need it generally do, of course) and the app developer's push gateway -must be reachable from your Prosody server (this happens over a normal XMPP -server-to-server 's2s' connection). - -Details -======= +# Details Some platforms, notably Apple's iOS and many versions of Android, impose -limits that prevent applications from running or accessing the network in the -background. This makes it difficult or impossible for an XMPP application to -remain reliably connected to a server to receive messages. - -In order for messaging and other apps to receive notifications, the OS vendors -run proprietary servers that their OS maintains a permanent connection to in -the background. Then they provide APIs to application developers that allow -sending notifications to specific devices via those servers. +limits that prevent applications from running or accessing the network +in the background. This makes it difficult or impossible for an XMPP +application to remain reliably connected to a server to receive +messages. -When you connect to your server with an app that requires push notifications, -it will use this module to set up a "push registration". When you receive -a message but your device is not connected to the server, this module will -generate a notification and send it to the push gateway operated by your -application's developers). Their gateway will then connect to your device's -OS vendor and ask them to forward the notification to your device. When your -device receives the notification, it will display it or wake up the app so it -can connect to XMPP and receive any pending messages. +In order for messaging and other apps to receive notifications, the OS +vendors run proprietary servers that their OS maintains a permanent +connection to in the background. Then they provide APIs to application +developers that allow sending notifications to specific devices via +those servers. -This protocol is described for developers in [XEP-0357: Push Notifications]. +When you connect to your server with an app that requires push +notifications, it will use this module to set up a "push registration". +When you receive a message but your device is not connected to the +server, this module will generate a notification and send it to the push +gateway operated by your application's developers). Their gateway will +then connect to your device's OS vendor and ask them to forward the +notification to your device. When your device receives the notification, +it will display it or wake up the app so it can connect to XMPP and +receive any pending messages. -For this module to work reliably, you must have [mod_smacks], [mod_mam] and -[mod_carbons] also enabled on your server. +This protocol is described for developers in \[XEP-0357: Push +Notifications\]. + +For this module to work reliably, you must have \[mod_smacks\], +\[mod_mam\] and \[mod_carbons\] also enabled on your server. -Some clients, notably Siskin and Snikket iOS need some additional extensions -that are not currently defined in a standard XEP. To support these clients, -see [mod_cloud_notify_extensions]. +Some clients, notably Siskin and Snikket iOS need some additional +extensions that are not currently defined in a standard XEP. To support +these clients, see \[mod_cloud_notify_extensions\]. -Configuration -============= +# Configuration - Option Default Description - ------------------------------------ ----------------- ------------------------------------------------------------------------------------------------------------------- - `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty - `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled - `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) - `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) - `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. - `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. + Option Default Description + -------------------------------------- ---------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty + `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled + `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) + `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) + `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. + `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. -(\*) There are privacy implications for enabling these options. +(\*) There are privacy implications for enabling these options.[^1] -Internal design notes -===================== +# Internal design notes -App servers are notified about offline messages, messages stored by [mod_mam] -or messages waiting in the smacks queue. -The business rules outlined [here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) are all honored[^2]. +App servers are notified about offline messages, messages stored by +\[mod_mam\] or messages waiting in the smacks queue. The business rules +outlined +[here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) +are all honored[^2]. -To cooperate with [mod_smacks] this module consumes some events: -`smacks-ack-delayed`, `smacks-hibernation-start` and `smacks-hibernation-end`. -These events allow this module to send out notifications for messages received -while the session is hibernated by [mod_smacks] or even when smacks -acknowledgements for messages are delayed by a certain amount of seconds -configurable with the [mod_smacks] setting `smacks_max_ack_delay`. +To cooperate with \[mod_smacks\] this module consumes some events: +`smacks-ack-delayed`, `smacks-hibernation-start` and +`smacks-hibernation-end`. These events allow this module to send out +notifications for messages received while the session is hibernated by +\[mod_smacks\] or even when smacks acknowledgements for messages are +delayed by a certain amount of seconds configurable with the +\[mod_smacks\] setting `smacks_max_ack_delay`. -The `smacks_max_ack_delay` setting allows to send out notifications to clients -which aren't already in smacks hibernation state (because the read timeout or -connection close didn't already happen) but also aren't responding to acknowledgement -request in a timely manner. This setting thus allows conversations to be smoother -under such circumstances. +The `smacks_max_ack_delay` setting allows to send out notifications to +clients which aren't already in smacks hibernation state (because the +read timeout or connection close didn't already happen) but also aren't +responding to acknowledgement request in a timely manner. This setting +thus allows conversations to be smoother under such circumstances. -The new event `cloud-notify-ping` can be used by any module to send out a cloud -notification to either all registered endpoints for the given user or only the endpoints -given in the event data. +The new event `cloud-notify-ping` can be used by any module to send out +a cloud notification to either all registered endpoints for the given +user or only the endpoints given in the event data. -The config setting `push_notification_important_body` can be used to specify an alternative -body text to send to the remote pubsub node if the stanza is encrypted or has a body. -This way the real contents of the message aren't revealed to the push appserver but it -can still see that the push is important. -This is used by Chatsecure on iOS to send out high priority pushes in those cases for example. +The config setting `push_notification_important_body` can be used to +specify an alternative body text to send to the remote pubsub node if +the stanza is encrypted or has a body. This way the real contents of the +message aren't revealed to the push appserver but it can still see that +the push is important. This is used by Chatsecure on iOS to send out +high priority pushes in those cases for example. -Compatibility -============= - -**Note:** This module should be used with Lua 5.2 and higher. Using it with -Lua 5.1 may cause push notifications to not be sent to some clients. +# Compatibility ------- ----------------------------------------------------------------------------- - trunk Works - 0.12 Works - 0.11 Works - 0.10 Works - 0.9 Support dropped, use last supported version [675726ab06d3](//hg.prosody.im/prosody-modules/raw-file/675726ab06d3/mod_cloud_notify/mod_cloud_notify.lua) ------- ----------------------------------------------------------------------------- +**Note:** This module should be used with Lua 5.2 and higher. Using it +with Lua 5.1 may cause push notifications to not be sent to some +clients. + ------- ----------------------------------------------------------------- + trunk Works as of 25-06-13 + 13 Works + 0.12 Works + ------- ----------------------------------------------------------------- -[^1]: The service which is expected to forward notifications to something like Google Cloud Messaging or Apple Notification Service -[^2]: [business_rules.markdown](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.markdown) +[^1]: The service which is expected to forward notifications to + something like Google Cloud Messaging or Apple Notification Service + +[^2]: [business_rules.md](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.md)
author Menel <menel@snikket.de>
date Fri, 13 Jun 2025 10:36:52 +0200
parent 6241:303fcfe3a7e8
child 6310:30adcea825c3
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
4914
f2c918fe8cf0 mod_conversejs: Bump Copyright year
Kim Alvefur <zash@zash.se>
parents: 4891
diff changeset
2 -- Copyright (C) 2017-2022 Kim Alvefur
2657
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
4891
99cdc7cde150 mod_conversejs: Revert back to depending on mod_bookmarks
Kim Alvefur <zash@zash.se>
parents: 4855
diff changeset
19 pcall(function ()
99cdc7cde150 mod_conversejs: Revert back to depending on mod_bookmarks
Kim Alvefur <zash@zash.se>
parents: 4855
diff changeset
20 module:depends("bookmarks");
99cdc7cde150 mod_conversejs: Revert back to depending on mod_bookmarks
Kim Alvefur <zash@zash.se>
parents: 4855
diff changeset
21 end);
3494
4feab7e87675 mod_conversejs: Add dependency on mod_bookmarks
Kim Alvefur <zash@zash.se>
parents: 3492
diff changeset
22
3331
d98341bca458 mod_conversejs: Allow overriding CDN URL, or script/css URLs independently
Matthew Wild <mwild1@gmail.com>
parents: 3329
diff changeset
23 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
24
3348
f753cf4f7224 mod_conversejs: Default to latest version of Converse.js
Kim Alvefur <zash@zash.se>
parents: 3347
diff changeset
25 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
26 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
27
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
28 local serve_dist = nil;
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
29 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
30 if resources then
6223
767b8594fb9d mod_conversejs: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents: 6199
diff changeset
31 local http_files = require "net.http.files";
4147
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
32 local mime_map = module:shared("/*/http_files/mime").types or {css = "text/css"; js = "application/javascript"};
6223
767b8594fb9d mod_conversejs: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents: 6199
diff changeset
33 serve_dist = http_files.serve({path = resources; mime_map = mime_map});
4147
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
34
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
35 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
36 end
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
37
3347
823156d5885b mod_conversejs: Strip extra slash if version is set to the empty string
Kim Alvefur <zash@zash.se>
parents: 3337
diff changeset
38 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
39 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
40
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
41 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
42
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
43 do
4165
6b2a1c9ef6e2 mod_conversejs: Move templates into a directory for easier install
Kim Alvefur <zash@zash.se>
parents: 4153
diff changeset
44 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
45 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
46 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
47 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
48 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
49 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
50 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
51 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
52 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
53 <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
54 <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
55 { 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
56 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
57 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
58
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
59 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
60 do
4165
6b2a1c9ef6e2 mod_conversejs: Move templates into a directory for easier install
Kim Alvefur <zash@zash.se>
parents: 4153
diff changeset
61 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
62 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
63 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
64 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
65 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
66 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
67 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
68 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
69 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
70 { 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
71 end
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
72 end
3312
e714be00aaad mod_conversejs: Factor JavaScript part out of HTML
Kim Alvefur <zash@zash.se>
parents: 3310
diff changeset
73
5211
079ca766193b mod_conversejs: This one weird trick updates options on reload
Kim Alvefur <zash@zash.se>
parents: 4976
diff changeset
74 local function get_converse_options()
079ca766193b mod_conversejs: This one weird trick updates options on reload
Kim Alvefur <zash@zash.se>
parents: 4976
diff changeset
75 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
76
3313
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
77 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
78 local converse_options = {
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
79 -- Auto-detected connection endpoints
3363
2681f74750b2 mod_conversejs: Weaken dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents: 3348
diff changeset
80 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
81 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
82 -- 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
83 discover_connection_methods = false;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
84 -- 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
85 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
86 -- 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
87 jid = module.host;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
88 -- 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
89 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
90 domain_placeholder = module.host;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
91 -- 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
92 allow_registration = allow_registration;
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
93 -- 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
94 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
95 -- 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
96 assets_path = cdn_url..version.."/dist/";
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
97 -- 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
98 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
99 };
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
100
4209
37aa50ed79c1 mod_conversejs: Add comments about default settings
Kim Alvefur <zash@zash.se>
parents: 4176
diff changeset
101 -- 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
102 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
103 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
104 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
105 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
106 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
107
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
108 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
109 end
d6b922191aeb mod_conversejs: Factor out option handling into a function for future reuse
Kim Alvefur <zash@zash.se>
parents: 3312
diff changeset
110
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
111 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
112
6241
303fcfe3a7e8 mod_conversejs: Make PWA options match documentation
Kim Alvefur <zash@zash.se>
parents: 6223
diff changeset
113 local service_name = module:get_option_string("conversejs_name", module:get_option_string("name", "Prosody IM and Converse.js"));
303fcfe3a7e8 mod_conversejs: Make PWA options match documentation
Kim Alvefur <zash@zash.se>
parents: 6223
diff changeset
114 local service_short_name = module:get_option_string("conversejs_short_name", "Converse");
303fcfe3a7e8 mod_conversejs: Make PWA options match documentation
Kim Alvefur <zash@zash.se>
parents: 6223
diff changeset
115 local service_description = module:get_option_string("conversejs_description", "Messaging Freedom")
303fcfe3a7e8 mod_conversejs: Make PWA options match documentation
Kim Alvefur <zash@zash.se>
parents: 6223
diff changeset
116 local pwa_color = module:get_option_string("conversejs_pwa_color", "#397491")
5895
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
117
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 module:provides("http", {
3337
b46bb9392efe mod_conversejs: Set a friendly name for mod_http_index
Kim Alvefur <zash@zash.se>
parents: 3333
diff changeset
119 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
120 route = {
6199
fe8222112cf4 mod_conversejs: Serve base app at /
Matthew Wild <mwild1@gmail.com>
parents: 5895
diff changeset
121 ["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
122 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
123
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
124 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
125 return render(html_template, {
5895
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
126 service_name = service_name;
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
127 -- note that using a relative path won’t work as this URL doesn’t end in a /
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
128 manifest_url = module:http_url().."/manifest.json",
3598
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
129 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
130 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
131 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
132 conversejs = {
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
133 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
134 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
135 };
1921ae4449b8 mod_conversejs: Separate out templates into separate configurable files (breaks 0.9 compat)
Kim Alvefur <zash@zash.se>
parents: 3494
diff changeset
136 });
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 end;
3314
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
138
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
139 ["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
140 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
141
ab67f222d88b mod_conversejs: Add an endpoint returning only initialization snippet
Kim Alvefur <zash@zash.se>
parents: 3313
diff changeset
142 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
143 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
144 end;
5895
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
145 ["GET /manifest.json"] = function (event)
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
146 -- See manifest.json in the root of Converse.js’s git repository
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
147 local data = {
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
148 short_name = service_short_name,
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
149 name = service_name,
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
150 description = service_description,
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
151 categories = {"social"},
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
152 icons = module:get_option_array("manifest_icons", {
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
153 {
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
154 src = cdn_url..version.."/dist/images/logo/conversejs-filled-512.png",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
155 sizes = "512x512",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
156 },
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
157 {
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
158 src = cdn_url..version.."/dist/images/logo/conversejs-filled-192.png",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
159 sizes = "192x192",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
160 },
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
161 {
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
162 src = cdn_url..version.."/dist/images/logo/conversejs-filled-192.svg",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
163 sizes = "192x192",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
164 },
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
165 {
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
166 src = cdn_url..version.."/dist/images/logo/conversejs-filled-512.svg",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
167 sizes = "512x512",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
168 },
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
169 }),
6199
fe8222112cf4 mod_conversejs: Serve base app at /
Matthew Wild <mwild1@gmail.com>
parents: 5895
diff changeset
170 start_url = module:http_url().."/",
5895
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
171 background_color = pwa_color,
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
172 display = "standalone",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
173 scope = module:http_url().."/",
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
174 theme_color = pwa_color,
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
175 }
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
176 return {
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
177 headers = { content_type = "application/schema+json" },
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
178 body = json_encode(data),
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
179 }
1c8197075d04 mod_conversejs: Allow installation as PWA
BetaRays <BetaRays@proton.me>
parents: 5211
diff changeset
180 end;
4147
3a06dea21ea1 mod_conversejs: Enable serving resources from built-in http server
Kim Alvefur <zash@zash.se>
parents: 4047
diff changeset
181 ["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
182 }
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 });
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184
4176
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 platforms = { "Web" };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
193 download = {
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
194 buttons = {
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
195 {
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
196 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
197 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
198 };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
199 };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
200 };
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
201
0016618e0975 mod_conversejs: Automatically register as a site app (see mod_register_apps)
Matthew Wild <mwild1@gmail.com>
parents: 4165
diff changeset
202 });