automatic configuration of TURN, with per-room credentials. version 0.6.0

This commit is contained in:
David Zhao
2021-03-07 23:30:21 -08:00
parent 048cdf9751
commit e20c831c14
18 changed files with 220 additions and 79 deletions
+20 -6
View File
@@ -5,6 +5,13 @@ locals {
port_range_start = var.udp_port_start
port_range_end = var.udp_port_end
}
turn = {
enabled = var.turn_enabled
tcp_port = var.turn_tcp_port
udp_port = var.turn_udp_port
port_range_start = var.turn_port_start
port_range_end = var.turn_port_end
}
development = true
keys = var.api_keys
redis = {
@@ -12,15 +19,22 @@ locals {
}
}
port_mapping = concat([{
// mapping contains only the main listening ports
// other UDP ports don't have to be mapped, due to
port_mapping = [
{
containerPort = var.http_port
protocol = "tcp"
}], [
for p in range(var.udp_port_start, var.udp_port_end): {
containerPort = p
},
{
containerPort = var.turn_tcp_port
protocol = "tcp"
},
{
containerPort = var.turn_udp_port
protocol = "udp"
}
])
},
]
task_config = [{
name = "livekit"
+6 -2
View File
@@ -23,13 +23,17 @@ resource "aws_ecs_service" "livekit" {
field = "instanceId"
}
// load balancer for TCP port
// load balancer for HTTP port
load_balancer {
target_group_arn = aws_lb_target_group.main.arn
target_group_arn = aws_lb_target_group.http.arn
container_name = "livekit"
container_port = var.http_port
}
depends_on = [
aws_lb_listener.http
]
// lifecycle {
// ignore_changes = [desired_count]
// }
+13 -2
View File
@@ -38,5 +38,16 @@ api_keys = {
"key" = "secret"
}
udp_port_start = 9000
udp_port_end = 9100
# UDP port range for WebRTC, uncomment to override
// udp_port_start = 9000
// udp_port_end = 11000
# Use embedded TURN server, defaults true
// turn_enabled = true
// turn_tcp_port = 3478
// turn_udp_port = 3479
# UDP port range for embedded TURN server
// turn_port_start = 11001
// turn_port_end = 13000
+4 -6
View File
@@ -1,23 +1,21 @@
// configure target group
resource "aws_lb_target_group" "main" {
name = "livekit-${var.name}"
resource "aws_lb_target_group" "http" {
name = "livekit-${var.name}-http"
port = 80
protocol = "HTTP"
vpc_id = data.aws_vpc.main.id
}
resource "aws_lb" "main" {
name = "livekit-${var.name}"
name = "livekit-${var.name}-http"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.lb.id]
subnets = var.subnet_ids
}
// TODO: HTTPS
resource "aws_lb_listener" "http" {
load_balancer_arn = aws_lb.main.arn
port = "80"
@@ -26,6 +24,6 @@ resource "aws_lb_listener" "http" {
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.main.arn
target_group_arn = aws_lb_target_group.http.arn
}
}
+26 -1
View File
@@ -77,7 +77,7 @@ variable "udp_port_start" {
variable "udp_port_end" {
type = number
default = 9100
default = 11000
}
variable "api_keys" {
@@ -89,6 +89,31 @@ variable "redis_address" {
default = ""
}
variable "turn_enabled" {
type = bool
default = true
}
variable "turn_tcp_port" {
type = number
default = 3478
}
variable "turn_udp_port" {
type = number
default = 3479
}
variable "turn_port_start" {
type = number
default = 12000
}
variable "turn_port_end" {
type = number
default = 14000
}
output "livekit_lb" {
value = aws_lb.main.dns_name
}
+26
View File
@@ -15,6 +15,32 @@ resource "aws_security_group" "main" {
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "UDP port for TURN"
from_port = var.turn_port_start
to_port = var.turn_port_end
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
// for TURN server
ingress {
description = "TURN TCP"
from_port = var.turn_tcp_port
to_port = var.turn_tcp_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
// for TURN server
ingress {
description = "TURN UDP"
from_port = var.turn_udp_port
to_port = var.turn_udp_port
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "internal traffic"
from_port = 0