comparison mod_candy/mod_candy.lua @ 2440:7814a5c7fee8

mod_candy: Provide websocket URI if mod_websocket is loaded, fall back to BOSH
author Kim Alvefur <zash@zash.se>
date Tue, 10 Jan 2017 14:11:56 +0100
parents 991a5f74f848
children c9372cfac3b7
comparison
equal deleted inserted replaced
2439:1f7820f68868 2440:7814a5c7fee8
1 -- mod_candy.lua 1 -- mod_candy.lua
2 -- Copyright (C) 2013 Kim Alvefur 2 -- Copyright (C) 2013-2017 Kim Alvefur
3 3
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 6
6 module:depends"bosh";
7 local serve = module:depends"http_files".serve; 7 local serve = module:depends"http_files".serve;
8 8
9 module:provides("http", { 9 module:provides("http", {
10 route = { 10 route = {
11 ["GET /prosody.js"] = function(event) 11 ["GET /prosody.js"] = function(event)
12 event.response.headers.content_type = "text/javascript"; 12 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
13 return ("// Generated by Prosody\n" 23 return ("// Generated by Prosody\n"
14 .."var Prosody = %s;\n") 24 .."var Prosody = %s;\n")
15 :format(json_encode({ 25 :format(json_encode({
16 bosh_path = module:http_url("bosh","/http-bind"); 26 connect_path = connect_path;
17 version = prosody.version; 27 version = prosody.version;
18 host = module:get_host(); 28 host = module:get_host();
19 anonymous = module:get_option_string("authentication") == "anonymous"; 29 anonymous = module:get_option_string("authentication") == "anonymous";
20 })); 30 }));
21 end; 31 end;