Annotate

mod_conversejs/mod_conversejs.lua @ 2919:0ea93da47db9

mod_conversejs: Allow passing arbitrary options trough to Converse.js
author Kim Alvefur <zash@zash.se>
date Sat, 10 Mar 2018 00:05:30 +0100
parent 2694:38c66b58b470
child 2921:3264058ae54f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- mod_conversejs
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2017 Kim Alvefur
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local json_encode = require"util.json".encode;
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 module:depends"bosh";
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local has_ws = pcall(function ()
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 module:depends("websocket");
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 end);
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
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>
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 <meta charset="utf-8">
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.conversejs.org/css/converse.min.css">
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 <script src="https://cdn.conversejs.org/dist/converse.min.js"></script>
2664
5b97b04e9d1b mod_conversejs: Include a <body> tag in HTML
Kim Alvefur <zash@zash.se>
parents: 2658
diff changeset
17 <body><script>converse.initialize(%s);</script>
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 ]]
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
20 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
21
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 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
23 route = {
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 GET = function (event)
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
25 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
26 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
27 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
28 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
29 jid = module.host;
2919
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
30 };
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
31
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
32 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
33 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
34 converse_options[k] = v;
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
35 end
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
36 end
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
37
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
38 event.response.headers.content_type = "text/html";
0ea93da47db9 mod_conversejs: Allow passing arbitrary options trough to Converse.js
Kim Alvefur <zash@zash.se>
parents: 2694
diff changeset
39 return template:format(json_encode(converse_options));
2657
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end;
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 }
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 });
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43