Software /
code /
prosody
Annotate
plugins/mod_turn_external.lua @ 12282:fe5a87b5972f
mod_turn_external: Simplify configuration
Much harder to get boolean options wrong than accidentally adding
something unrecognised to a Set.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 10 Feb 2022 15:39:15 +0100 |
parent | 11599:ed405b6357a8 |
child | 12283:b5686debb497 |
rev | line source |
---|---|
12282
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
1 local set = require "util.set"; |
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
2 |
11599
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local secret = module:get_option_string("turn_external_secret"); |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local host = module:get_option_string("turn_external_host", module.host); |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local user = module:get_option_string("turn_external_user"); |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local port = module:get_option_number("turn_external_port", 3478); |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local ttl = module:get_option_number("turn_external_ttl", 86400); |
12282
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
8 local tcp = module:get_option_boolean("turn_external_tcp", false); |
11599
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 if not secret then error("mod_" .. module.name .. " requires that 'turn_external_secret' be set") end |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 |
12282
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
12 local services = set.new({ "stun-udp"; "turn-udp" }); |
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
13 if tcp then |
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
14 services:add("stun-tcp"); |
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
15 services:add("turn-tcp"); |
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
16 end |
fe5a87b5972f
mod_turn_external: Simplify configuration
Kim Alvefur <zash@zash.se>
parents:
11599
diff
changeset
|
17 |
11599
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 module:depends "external_services"; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 for _, type in ipairs({"stun"; "turn"}) do |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 for _, transport in ipairs({"udp"; "tcp"}) do |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 if services:contains(type .. "-" .. transport) then |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 module:add_item("external_service", { |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 type = type; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 transport = transport; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 host = host; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 port = port; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 username = type == "turn" and user or nil; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 secret = type == "turn" and secret or nil; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 ttl = type == "turn" and ttl or nil; |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 }) |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 end |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
ed405b6357a8
mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end |