Software /
code /
prosody-modules
Comparison
mod_candy/mod_candy.lua @ 2449:c9372cfac3b7
mod_candy: Break out connect path into a function
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 20 Jan 2017 01:09:36 +0100 |
parent | 2440:7814a5c7fee8 |
child | 2450:36ffe9d11132 |
comparison
equal
deleted
inserted
replaced
2448:1f7f66272f73 | 2449:c9372cfac3b7 |
---|---|
4 local json_encode = require"util.json".encode; | 4 local json_encode = require"util.json".encode; |
5 local is_module_loaded = require "core.modulemanager".is_loaded; | 5 local is_module_loaded = require "core.modulemanager".is_loaded; |
6 | 6 |
7 local serve = module:depends"http_files".serve; | 7 local serve = module:depends"http_files".serve; |
8 | 8 |
9 local function get_connect_path() | |
10 if is_module_loaded(module.host, "websocket") then | |
11 return module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws"); | |
12 end | |
13 if not is_module_loaded(module.host, "bosh") then | |
14 module:depends("bosh"); | |
15 end | |
16 return module:http_url("bosh", "/http-bind"); | |
17 end | |
18 | |
9 module:provides("http", { | 19 module:provides("http", { |
10 route = { | 20 route = { |
11 ["GET /prosody.js"] = function(event) | 21 ["GET /prosody.js"] = function(event) |
12 event.response.headers.content_type = "text/javascript"; | 22 event.response.headers.content_type = "text/javascript"; |
13 local connect_path; | |
14 if is_module_loaded(module.host, "websocket") then | |
15 connect_path = module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws"); | |
16 else | |
17 if not is_module_loaded(module.host, "bosh") then | |
18 module:depends("bosh"); | |
19 end | |
20 connect_path = module:http_url("bosh", "/http-bind"); | |
21 end | |
22 | 23 |
23 return ("// Generated by Prosody\n" | 24 return ("// Generated by Prosody\n" |
24 .."var Prosody = %s;\n") | 25 .."var Prosody = %s;\n") |
25 :format(json_encode({ | 26 :format(json_encode({ |
26 connect_path = connect_path; | 27 connect_path = get_connect_path(); |
27 version = prosody.version; | 28 version = prosody.version; |
28 host = module:get_host(); | 29 host = module:get_host(); |
29 anonymous = module:get_option_string("authentication") == "anonymous"; | 30 anonymous = module:get_option_string("authentication") == "anonymous"; |
30 })); | 31 })); |
31 end; | 32 end; |