
plugin_paths = { "{{ jitsi_root_dir }}/prosody/modules" }

muc_mapper_domain_base = "{{ jitsi_domain }}";
admins = { "{{ jitsi_jicofo_xmpp_user }}@{{ jitsi_auth_domain }}" };
component_admins_as_room_owners = true;
http_default_host = "{{ jitsi_domain }}";

-- Enable use of native prosody 0.11 support for epoll over select
network_backend = "epoll";
-- Set the TCP backlog to 511 since the kernel rounds it up to the next power of 2: 512.
network_settings = {
  tcp_backlog = 511;
}

{% if jitsi_turn_secret is defined %}
external_service_secret = "{{ jitsi_turn_secret }}";
{% endif %}

external_services = {
{% for stun in jitsi_stun_servers %}
  {
    type = "{{ stun | urlsplit('scheme') }}",
    host = "{{ stun | regex_replace('(turns?|stun):([^:]+)(:\d+)?.*', '\\2') }}",
{% if stun | regex_replace('(turns?|stun):.+:(\d+)?.*', '\\2') | int > 0 and stun | regex_replace('(turns?|stun):.+:(\d+)?.*', '\\2') | int < 65535 %}
    port = {{ stun | regex_replace('(turns?|stun):.+:(\d+)?.*', '\\2') }},
{% endif %}
{% if stun | urlsplit('query') is search('transport=') %}
    transport = "{{ stun | urlsplit('query') | regex_replace('.*transport=(udp|tcp).*', '\\1') }}",
{% endif %}
    secret = {{ jitsi_turn_secret is defined | ternary('true', 'false') }},
{% if stun | urlsplit('scheme') == 'turn' or stun | urlsplit('scheme') == 'turns' %}
    algorithm = "turn",
{% endif %}
    ttl = 86400
  },
{% endfor %}
};

-- cross_domain_bosh = false;
cross_domain_websocket = true;
consider_bosh_secure = true;

unlimited_jids = {
  "{{ jitsi_jicofo_xmpp_user }}@{{ jitsi_auth_domain }}",
  "{{ jitsi_videobridge_xmpp_user }}@{{ jitsi_videobridge_xmpp_domain }}"
}

VirtualHost "{{ jitsi_domain }}"
{% if jitsi_auth == 'ldap' %}
  authentication = "ldap"
  ldap_base = "{{ jitsi_ldap_base }}"
  ldap_server = "{{ jitsi_ldap_servers | join(' ') }}"
{% if jitsi_ldap_bind_dn is defined and jitsi_ldap_bind_pass is defined %}
  ldap_rootdn = "{{ jitsi_ldap_bind_dn }}"
  ldap_password = "{{ jitsi_ldap_bind_pass }}"
{% endif %}
  ldap_filter = "{{ jitsi_ldap_filter }}"
  ldap_scope = "subtree"
  ldap_tls = {{ jitsi_ldap_starttls | ternary('true','false') }}
{% elif jitsi_auth == 'token' %}
  authentication = "token"
  app_id = "{{ jitsi_token_app_id }}";
  asap_accepted_issuers = "{{ jitsi_token_iss }}";
  asap_accepted_audiences = "{{ jitsi_token_aud }}";
{% if jitsi_token_app_secret is defined %}
  app_secret = "{{ jitsi_token_app_secret }}";
{% elif jitsi_token_asap_key_server is defined %}
  asap_key_server = "{{ jitsi_token_asap_key_server }}";
{% endif %}
  allow_empty_token = false;
{% else %}
  authentication = "jitsi-anonymous"
{% endif %}
  ssl = {
    key = "{{ jitsi_key_path }}";
    certificate = "{{ jitsi_cert_path }}";
  }

  c2s_require_encryption = false
  allow_unencrypted_plain_auth = true
  av_moderation_component = "avmoderation.{{ jitsi_domain }}"
  speakerstats_component = "speakerstats.{{ jitsi_domain }}"
  end_conference_component = "endconference.{{ jitsi_domain }}"

  modules_enabled = {
    "bosh";
    "pubsub";
    "websocket";
    "ping";
    "speakerstats";
    "external_services";
    "conference_duration";
    "end_conference";
    "muc_lobby_rooms";
    "muc_breakout_rooms";
    "av_moderation";
    "room_metadata";
    "participant_metadata";
    "presence_identity";
  }

  conference_duration_component = "conferenceduration.{{ jitsi_domain }}"
  lobby_muc = "lobby.{{ jitsi_domain }}"
  breakout_rooms_muc = "breakout.{{ jitsi_domain }}"
  room_metadata_component = "metadata.{{ jitsi_domain }}"
  main_muc = "conference.{{ jitsi_domain }}"
  muc_lobby_whitelist = { "recorder.{{ jitsi_domain }}" }

{% if jitsi_auth == 'ldap' or jitsi_auth == 'token' %}
-- Guest virtual domain
VirtualHost "guest.{{ jitsi_domain }}"
  authentication = "jitsi-anonymous"
  c2s_require_encryption = false
  modules_enabled = {
    "participant_metadata";
  }
{% endif %}

VirtualHost "{{ jitsi_auth_domain }}"
  ssl = {
    key = "{{ jitsi_key_path }}";
    certificate = "{{ jitsi_cert_path }}";
  }
  modules_enabled = {
    "limits_exception";
  }
  authentication = "internal_hashed"

VirtualHost "recorder.{{ jitsi_domain }}"
  modules_enabled = { "ping"; }
  authentication = "internal_hashed"
  c2s_require_encryption = false

Component "conference.{{ jitsi_domain }}" "muc"
  restrict_room_creation = true
  storage = "memory"
  modules_enabled = {
    "ping";
    "jibri_bypass_pwd";
    "muc_hide_all";
    "muc_meeting_id";
    "muc_domain_mapper";
    "polls";
    "muc_rate_limit";
  }
  admins = { "{{ jitsi_jicofo_xmpp_user }}@{{ jitsi_auth_domain }}" }
  muc_room_locking = false
  muc_room_default_public_jids = true
  muc_password_whitelist = {
    "{{ jitsi_jicofo_xmpp_user }}@{{ jitsi_auth_domain }}"
  }

Component "internal.{{ jitsi_auth_domain }}" "muc"
  storage = "memory"
  modules_enabled = {
    "muc_hide_all";
    "ping";
  }
  admins = { "{{ jitsi_jicofo_xmpp_user }}@{{ jitsi_auth_domain }}" }
  muc_room_locking = false
  muc_room_default_public_jids = true

Component "focus.{{ jitsi_domain }}" "client_proxy"
  target_address = "{{ jitsi_jicofo_xmpp_user }}@{{ jitsi_auth_domain }}"

Component "speakerstats.{{ jitsi_domain }}" "speakerstats_component"
  muc_component = "conference.{{ jitsi_domain }}"

Component "conferenceduration.{{ jitsi_domain }}" "conference_duration_component"
  muc_component = "conference.{{ jitsi_domain }}"

Component "endconference.{{ jitsi_domain }}" "end_conference"
  muc_component = "conference.{{ jitsi_domain }}"

Component "avmoderation.{{ jitsi_domain }}" "av_moderation_component"
  muc_component = "conference.{{ jitsi_domain }}"

Component "lobby.{{ jitsi_domain }}" "muc"
  storage = "memory"
  restrict_room_creation = true
  muc_room_locking = false
  muc_room_default_public_jids = true
  modules_enabled = {
    "muc_hide_all";
    "muc_rate_limit";
    "polls";
  }

Component "metadata.{{ jitsi_domain }}" "room_metadata_component"
  muc_component = "conference.{{ jitsi_domain }}"
  breakout_rooms_component = "breakout.{{ jitsi_domain }}"

Component "breakout.{{ jitsi_domain }}" "muc"
  restrict_room_creation = true
  storage = "memory"
  modules_enabled = {
    "muc_hide_all";
    "muc_meeting_id";
    "muc_domain_mapper";
    "muc_rate_limit";
    "polls";
  }
  admins = { "{{ jitsi_jicofo_xmpp_user }}@{{ jitsi_auth_domain }}" }
  muc_room_locking = false
  muc_room_default_public_jids = true
