mod_conversejs/mod_conversejs.lua
author Kim Alvefur <zash@zash.se>
Mon, 03 Apr 2017 16:15:15 +0200
changeset 2668 5b97b04e9d1b
parent 2662 b0f4014cb5b4
child 2698 38c66b58b470
permissions -rw-r--r--
mod_conversejs: Include a <body> tag in HTML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2661
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>
2668
5b97b04e9d1b mod_conversejs: Include a <body> tag in HTML
Kim Alvefur <zash@zash.se>
parents: 2662
diff changeset
    17
<body><script>converse.initialize(%s);</script>
2661
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
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    20
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
    21
	route = {
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    22
		GET = function (event)
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    23
			event.response.headers.content_type = "text/html";
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    24
			return template:format(json_encode({
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    25
				-- debug = true,
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";
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    29
			}));
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    30
		end;
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    31
	}
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    32
});
6f5c99c9f6cc mod_conversejs: Simple demo module for serving converse.js from internal http server
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    33