From 6960665111200a563e83b982a50c0ca0e71eaee8 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 16 Mar 2015 18:03:00 +0100 Subject: [PATCH] Support several STUN and TURN severs --- conf/settings.ini.dist | 8 +++++--- templates/default/documentation.html.ep | 13 +++++++------ vroom.pl | 34 +++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/conf/settings.ini.dist b/conf/settings.ini.dist index f74cbe7..98c1dbc 100644 --- a/conf/settings.ini.dist +++ b/conf/settings.ini.dist @@ -9,9 +9,11 @@ ;uri = 'https://vroom.exmple.com' [turn] -; The stun server sent to client. You can set it to your own stun server. Takes a full stun uri as defined by rfc7064 -;stun_server = 'stun:stun.l.google.com:19302' -; The turn server sent to cliet, you should set it to your own server. Takes a full turn uri as defined by rfc7065 +; The stun server sent to client. You can set it to your own stun server. Takes a comma separated list of full +; stun uri as defined by rfc7064 +;stun_server = 'stun:stun.l.google.com:19302','stun:vroom.example.net:3478' +; The turn server sent to cliet, you should set it to your own server. Takes a comma separated list of full +; turn uri as defined by rfc7065 ;turn_server = 'turns:my-turn-server.net:5349?transport=tcp' ; You can use fixed username/login to access turn. If you omit this, VROOM will generate credentials on the fly ; for rfc5766-turn-server in its database diff --git a/templates/default/documentation.html.ep b/templates/default/documentation.html.ep index b991476..40a8697 100644 --- a/templates/default/documentation.html.ep +++ b/templates/default/documentation.html.ep @@ -288,15 +288,16 @@ cp /opt/vroom/conf/settings.ini.dist /opt/vroom/conf/settings.ini If you plan to use VROOM only on a local network, where each peer can connect to each others, you can just omit this part. But if you want VROOM to work from anywhere, you'll need use STUN and most likely TURN too. diff --git a/vroom.pl b/vroom.pl index 43eaeef..34669ad 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1708,9 +1708,7 @@ any '/api' => sub { my $resp = { url => $config->{'signaling.uri'}, peerConnectionConfig => { - iceServers => [{ - url => $config->{'turn.stun_server'} - }] + iceServers => [] }, autoRequestMedia => Mojo::JSON::true, enableDataChannels => Mojo::JSON::true, @@ -1736,18 +1734,30 @@ any '/api' => sub { muted => Mojo::JSON::true } }; - # TODO: Support several TURN server in config + if ($config->{'turn.stun_server'}){ + if (ref $config->{'turn.stun_server'} ne 'ARRAY'){ + $config->{'turn.stun_server'} = [ $config->{'turn.stun_server'} ]; + } + foreach my $s (@{$config->{'turn.stun_server'}}){ + push @{$resp->{peerConnectionConfig}->{iceServers}}, { url => $s }; + } + } if ($config->{'turn.turn_server'}){ - my $turn = { url => $config->{'turn.turn_server'} }; - if ($config->{'turn.turn_user'} && $config->{'turn.turn_password'}){ - $turn->{username} = $config->{'turn.turn_user'}; - $turn->{credential} = $config->{'turn.turn_password'}; + if (ref $config->{'turn.turn_server'} ne 'ARRAY'){ + $config->{'turn.turn_server'} = [ $config->{'turn.turn_server'} ]; } - else{ - $turn->{username} = $room->{name}; - $turn->{credential} = $room->{token}; + foreach my $t (@{$config->{'turn.turn_server'}}){ + my $turn = { url => $t }; + if ($config->{'turn.turn_user'} && $config->{'turn.turn_password'}){ + $turn->{username} = $config->{'turn.turn_user'}; + $turn->{credential} = $config->{'turn.turn_password'}; + } + else{ + $turn->{username} = $room->{name}; + $turn->{credential} = $room->{token}; + } + push @{$resp->{peerConnectionConfig}->{iceServers}}, $turn; } - push @{$resp->{peerConnectionConfig}->{iceServers}}, $turn; } return $self->render( json => {