Mercurial > prosody-modules
annotate mod_turn_external/mod_turn_external.lua @ 4974:807007913f67
mod_log_json: Prefer native Lua table.pack over Prosody util.table one
Prosody is removing support for Lua 5.1, which was the reason for
util.table.pack to exist in the first place, since Lua 5.2+ provides
table.pack. In prosody rev 5eaf77114fdb everything was switched over to
use table.pack, opening the door for removing util.table.pack at some
point. This change here is to prepare for that future eventuality.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 11 Jul 2022 20:08:41 +0200 |
parents | 2542fd80cd15 |
children |
rev | line source |
---|---|
4894
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local set = require "util.set"; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local secret = module:get_option_string("turn_external_secret"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local host = module:get_option_string("turn_external_host", module.host); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local user = module:get_option_string("turn_external_user"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local port = module:get_option_number("turn_external_port", 3478); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local ttl = module:get_option_number("turn_external_ttl", 86400); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local tcp = module:get_option_boolean("turn_external_tcp", false); |
4895
2542fd80cd15
mod_turn_external: Fix type of config option (thanks mirux)
Kim Alvefur <zash@zash.se>
parents:
4894
diff
changeset
|
9 local tls_port = module:get_option_number("turn_external_tls_port"); |
4894
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 if not secret then error("mod_" .. module.name .. " requires that 'turn_external_secret' be set") end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local services = set.new({ "stun-udp"; "turn-udp" }); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 if tcp then |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 services:add("stun-tcp"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 services:add("turn-tcp"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 if tls_port then |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 services:add("turns-tcp"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 module:depends "external_services"; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 for _, type in ipairs({ "stun"; "turn"; "turns" }) do |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 for _, transport in ipairs({"udp"; "tcp"}) do |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 if services:contains(type .. "-" .. transport) then |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 module:add_item("external_service", { |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 type = type; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 transport = transport; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 host = host; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 port = type == "turns" and tls_port or port; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 username = type == "turn" and user or nil; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 secret = type == "turn" and secret or nil; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 ttl = type == "turn" and ttl or nil; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 }) |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 end |