comparison mod_conversejs/mod_conversejs.lua @ 5871:1c8197075d04

mod_conversejs: Allow installation as PWA
author BetaRays <BetaRays@proton.me>
date Sun, 17 Mar 2024 15:05:29 +0100
parents 079ca766193b
children
comparison
equal deleted inserted replaced
5870:1ac4a59ac575 5871:1c8197075d04
116 return converse_options; 116 return converse_options;
117 end 117 end
118 118
119 local add_tags = module:get_option_array("conversejs_tags", {}); 119 local add_tags = module:get_option_array("conversejs_tags", {});
120 120
121 local service_name = module:get_option_string("name", "Prosody IM and Converse.js");
122 local service_short_name = module:get_option_string("short_name", "Converse");
123 local service_description = module:get_option_string("description", "Messaging Freedom")
124 local pwa_color = module:get_option_string("pwa_color", "#397491")
125
121 module:provides("http", { 126 module:provides("http", {
122 title = "Converse.js"; 127 title = "Converse.js";
123 route = { 128 route = {
124 GET = function (event) 129 GET = function (event)
125 local converse_options = get_converse_options(); 130 local converse_options = get_converse_options();
126 131
127 event.response.headers.content_type = "text/html"; 132 event.response.headers.content_type = "text/html";
128 return render(html_template, { 133 return render(html_template, {
129 service_name = module:get_option_string("name"); 134 service_name = service_name;
135 -- note that using a relative path won’t work as this URL doesn’t end in a /
136 manifest_url = module:http_url().."/manifest.json",
130 header_scripts = { js_url }; 137 header_scripts = { js_url };
131 header_style = { css_url }; 138 header_style = { css_url };
132 header_tags = add_tags; 139 header_tags = add_tags;
133 conversejs = { 140 conversejs = {
134 options = converse_options; 141 options = converse_options;
140 ["GET /prosody-converse.js"] = function (event) 147 ["GET /prosody-converse.js"] = function (event)
141 local converse_options = get_converse_options(); 148 local converse_options = get_converse_options();
142 149
143 event.response.headers.content_type = "application/javascript"; 150 event.response.headers.content_type = "application/javascript";
144 return js_template:format(json_encode(converse_options)); 151 return js_template:format(json_encode(converse_options));
152 end;
153 ["GET /manifest.json"] = function (event)
154 -- See manifest.json in the root of Converse.js’s git repository
155 local data = {
156 short_name = service_short_name,
157 name = service_name,
158 description = service_description,
159 categories = {"social"},
160 icons = module:get_option_array("manifest_icons", {
161 {
162 src = cdn_url..version.."/dist/images/logo/conversejs-filled-512.png",
163 sizes = "512x512",
164 },
165 {
166 src = cdn_url..version.."/dist/images/logo/conversejs-filled-192.png",
167 sizes = "192x192",
168 },
169 {
170 src = cdn_url..version.."/dist/images/logo/conversejs-filled-192.svg",
171 sizes = "192x192",
172 },
173 {
174 src = cdn_url..version.."/dist/images/logo/conversejs-filled-512.svg",
175 sizes = "512x512",
176 },
177 }),
178 start_url = module:http_url(),
179 background_color = pwa_color,
180 display = "standalone",
181 scope = module:http_url().."/",
182 theme_color = pwa_color,
183 }
184 return {
185 headers = { content_type = "application/schema+json" },
186 body = json_encode(data),
187 }
145 end; 188 end;
146 ["GET /dist/*"] = serve_dist; 189 ["GET /dist/*"] = serve_dist;
147 } 190 }
148 }); 191 });
149 192