comparison mod_turn_external/mod_turn_external.lua @ 4894:bfa2cca2bdd5

mod_turn_external: Import from prosody trunk @ ed23bbf3b946
author Matthew Wild <mwild1@gmail.com>
date Mon, 14 Feb 2022 14:36:32 +0000
parents
children 2542fd80cd15
comparison
equal deleted inserted replaced
4893:d4ce29c772ac 4894:bfa2cca2bdd5
1 local set = require "util.set";
2
3 local secret = module:get_option_string("turn_external_secret");
4 local host = module:get_option_string("turn_external_host", module.host);
5 local user = module:get_option_string("turn_external_user");
6 local port = module:get_option_number("turn_external_port", 3478);
7 local ttl = module:get_option_number("turn_external_ttl", 86400);
8 local tcp = module:get_option_boolean("turn_external_tcp", false);
9 local tls_port = module:get_option_boolean("turn_external_tls_port");
10
11 if not secret then error("mod_" .. module.name .. " requires that 'turn_external_secret' be set") end
12
13 local services = set.new({ "stun-udp"; "turn-udp" });
14 if tcp then
15 services:add("stun-tcp");
16 services:add("turn-tcp");
17 end
18 if tls_port then
19 services:add("turns-tcp");
20 end
21
22 module:depends "external_services";
23
24 for _, type in ipairs({ "stun"; "turn"; "turns" }) do
25 for _, transport in ipairs({"udp"; "tcp"}) do
26 if services:contains(type .. "-" .. transport) then
27 module:add_item("external_service", {
28 type = type;
29 transport = transport;
30 host = host;
31 port = type == "turns" and tls_port or port;
32
33 username = type == "turn" and user or nil;
34 secret = type == "turn" and secret or nil;
35 ttl = type == "turn" and ttl or nil;
36 })
37 end
38 end
39 end