<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="stun1" class="org.bigbluebutton.web.services.turn.StunServer">
        <constructor-arg index="0" value="{{ .Env.STUN_SERVER }}"/>
    </bean>

    <bean id="turn0" class="org.bigbluebutton.web.services.turn.TurnServer">
        <constructor-arg index="0" value="{{ .Env.TURN_SECRET }}"/>
        <constructor-arg index="1" value="turn:{{ .Env.DOMAIN }}:3478"/>
        <constructor-arg index="2" value="86400"/>
    </bean>

    {{if and (isTrue .Env.ENABLE_HTTPS_PROXY) (not (isTrue .Env.IGNORE_TLS_CERT_ERRORS))  }}
    {{/* ignore when using a self signed certificate in dev mode */}}
    <bean id="turn1" class="org.bigbluebutton.web.services.turn.TurnServer">
        <constructor-arg index="0" value="{{ .Env.TURN_SECRET }}"/>
        <constructor-arg index="1" value="turns:{{ .Env.DOMAIN }}:443?transport=tcp"/>
        <constructor-arg index="2" value="86400"/>
    </bean>
    {{end}}


    {{if .Env.TURN_EXT_SERVER }}
        <bean id="turn2" class="org.bigbluebutton.web.services.turn.TurnServer">
            <constructor-arg index="0" value="{{ .Env.TURN_EXT_SECRET }}"/>
            <constructor-arg index="1" value="{{ .Env.TURN_EXT_SERVER }}"/>
            <constructor-arg index="2" value="86400"/>
        </bean>
    {{end}}

    <bean id="stunTurnService" class="org.bigbluebutton.web.services.turn.StunTurnService">
        <property name="stunServers">
            <set>
                <ref bean="stun1" />
            </set>
        </property>
        <property name="turnServers">
            <set>
                <ref bean="turn0" />
                
                {{if and (isTrue .Env.ENABLE_HTTPS_PROXY) (not (isTrue .Env.IGNORE_TLS_CERT_ERRORS))  }}
                <ref bean="turn1" />
                {{end}}

                {{if .Env.TURN_EXT_SERVER }}
                <ref bean="turn2" />
                {{end}}
            </set>
        </property>
        <property name="remoteIceCandidates">
            <set>
            </set>
        </property>
    </bean>
</beans>
