kind: ConfigMap
apiVersion: v1
metadata:
  namespace: jitsi
  name: jicofo-base
data:
  jicofo.conf: |
    {{ $ENABLE_AUTH := .Env.ENABLE_AUTH | default "0" | toBool }}
    {{ $AUTH_TYPE := .Env.AUTH_TYPE | default "internal" }}
    {{ $ENABLE_RECORDING := .Env.ENABLE_RECORDING | default "0" | toBool }}
    {{ $ENABLE_JIBRI_SIP := .Env.ENABLE_JIBRI_SIP | default "0" | toBool }}

    jicofo {
        {{ if $ENABLE_AUTH }}  
        // Authentication with external services
        authentication {
          enabled = true
          // The type of authentication. Supported values are XMPP, JWT or SHIBBOLETH (default).
          {{ if eq $AUTH_TYPE "jwt" }}
          type = JWT
          {{ else }}
          type = XMPP
          {{ end }}
          login-url = "{{ .Env.XMPP_DOMAIN }}"
        }
        {{ end }}

        // Configuration related to jitsi-videobridge
        bridge {
          // The maximum number of participants in a single conference to put on one bridge (use -1 for no maximum).
          {{ if .Env.MAX_BRIDGE_PARTICIPANTS }}
          max-bridge-participants = "{{ .Env.MAX_BRIDGE_PARTICIPANTS }}"
          {{ end }}

          {{ if .Env.BRIDGE_AVG_PARTICIPANT_STRESS }}
          // The assumed average stress per participant. default is 0.01
          average-participant-stress = "{{ .Env.BRIDGE_AVG_PARTICIPANT_STRESS }}"
          {{ end }}

          {{ if .Env.BRIDGE_STRESS_THRESHOLD }}  
          // The stress level above which a bridge is considered overstressed. 0.8 is the default value 
          stress-threshold = "{{ .Env.BRIDGE_STRESS_THRESHOLD }}"
          {{ end }}

          // The bridge selection strategy. The built-in strategies are:
          // SingleBridgeSelectionStrategy: Use the least loaded bridge, do not split a conference between bridges (Octo).
          // SplitBridgeSelectionStrategy: Use a separate bridge for each participant (for testing).
          // RegionBasedBridgeSelectionStrategy: Attempt to put each participant in a bridge in their local region (i.e. use
          //    Octo for geo-location).
          // IntraRegionBridgeSelectionStrategy: Use additional bridges when a bridge becomes overloaded (i.e. use Octo for
          //    load balancing).
          //
          // Additionally, you can use the fully qualified class name for custom BridgeSelectionStrategy implementations.
          {{ if .Env.OCTO_BRIDGE_SELECTION_STRATEGY }}
          selection-strategy = "{{ .Env.OCTO_BRIDGE_SELECTION_STRATEGY }}"
          {{ end }}

          {{ if .Env.JICOFO_ENABLE_BRIDGE_HEALTH_CHECKS }}
          health-checks {
            // Whether jicofo should perform periodic health checks to the connected bridges.
            enabled = "{{ .Env.JICOFO_ENABLE_BRIDGE_HEALTH_CHECKS }}"
          }
          {{ end }}
      
          // The JID of the MUC to be used as a brewery for bridge instances.
          brewery-jid = "{{ .Env.JVB_BREWERY_MUC }}@{{ .Env.XMPP_INTERNAL_MUC_DOMAIN }}"
        }
        // Configure the codecs and RTP extensions to be used in the offer sent to clients.
        codec {
          video {
            {{ if .Env.ENABLE_CODEC_VP8 }}
            vp8 {
              enabled = "{{ .Env.ENABLE_CODEC_VP8 }}"
            }
            {{ end }}
            {{ if .Env.ENABLE_CODEC_VP9 }}
            vp9 {
              enabled = "{{ .Env.ENABLE_CODEC_VP9 }}"
            }
            {{ end }}
            {{ if .Env.ENABLE_CODEC_H264 }}
            h264 {
              enabled = "{{ .Env.ENABLE_CODEC_H264 }}"
            }
            {{ end }}
          }
        }
      
        conference {
          {{ if .Env.ENABLE_AUTO_OWNER }}
          // Whether to automatically grant the 'owner' role to the first participant in the conference (and subsequently to
          // the next in line when the current owner leaves).
          enable-auto-owner = "{{ .Env.ENABLE_AUTO_OWNER }}"
          {{ end }}

          {{ if .Env.JICOFO_CONF_INITIAL_PARTICIPANT_WAIT_TIMEOUT }}
          // How long to wait for the initial participant in a conference.
          initial-timeout = "{{ .Env.JICOFO_CONF_INITIAL_PARTICIPANT_WAIT_TIMEOUT }}"
          {{ end }}

          {{ if .Env.JICOFO_CONF_SINGLE_PARTICIPANT_TIMEOUT }}
          // How long a participant's media session will be kept alive once it remains the only participant in the room.
          single-participant-timeout = "{{ .Env.JICOFO_CONF_SINGLE_PARTICIPANT_TIMEOUT }}"
          {{ end }}
        }
      
        {{ if .Env.JICOFO_ENABLE_HEALTH_CHECKS }}
        // Configuration for the internal health checks performed by jicofo.
        health {
          // Whether to perform health checks.
          enabled = "{{ .Env.JICOFO_ENABLE_HEALTH_CHECKS }}"
        }
        {{ end }}
      
        {{ if $ENABLE_RECORDING }}
        jibri {
          // The JID of the MUC to be used as a brewery for jibri instances for streaming.
          brewery-jid = "{{ .Env.JIBRI_BREWERY_MUC }}@{{ .Env.XMPP_INTERNAL_MUC_DOMAIN }}"

          {{ if .Env.JIBRI_REQUEST_RETRIES }}
          // How many times to retry a given Jibri request before giving up. Set to -1 to allow infinite retries.
          num-retries = "{{ .Env.JIBRI_REQUEST_RETRIES }}"
          {{ end }}

          {{ if .Env.JIBRI_PENDING_TIMEOUT }}
          // How long to wait for Jibri to start recording from the time it accepts a START request.
          pending-timeout = "{{ .Env.JIBRI_PENDING_TIMEOUT }}"
          {{ end }}
        }
        {{ end }}
      
        {{ if $ENABLE_JIBRI_SIP }}
        jibri-sip {
          // The JID of the MUC to be used as a brewery for jibri instances for SIP.
          # brewery-jid = "jibrisipbrewery@example.com"
        }
        {{ end }}
      
        {{ if and .Env.JIGASI_SIP_URI .Env.JIGASI_BREWERY_MUC }}
        jigasi {
          // The JID of the MUC to be used as a brewery for jigasi instances.
          brewery-jid = "{{ .Env.JIGASI_BREWERY_MUC}}@{{ .Env.XMPP_INTERNAL_MUC_DOMAIN }}"
        }
        {{ end }}
      
        octo {
          // An identifier of the Jicofo instance, used for the purpose of generating conference IDs unique across a set of
          // Jicofo instances. Valid values are [1, 65535]. The value 0 is used when none is explicitly configured.
          id = "{{ .Env.JICOFO_SHORT_ID | default "1" }}"
        }

        {{ if .Env.ENABLE_SCTP }}
        sctp {
          // Whether to allocate SCTP channels on the bridge (only when the client advertises support, and SCTP is
          // enabled in the per-conference configuration).
          enabled = "{{ .Env.ENABLE_SCTP }}"
        }
        {{ end }}
      
        xmpp {
          // The separate XMPP connection used for communication with clients (endpoints).
          client {
            enabled = true
            hostname = "{{ .Env.XMPP_SERVER }}"
            domain = "{{ .Env.XMPP_AUTH_DOMAIN }}"
            username = "{{ .Env.JICOFO_AUTH_USER }}"
            password = "{{ .Env.JICOFO_AUTH_PASSWORD }}"
      
            // The JID/domain of the MUC service used for conferencing.
            conference-muc-jid = "{{ .Env.XMPP_MUC_DOMAIN }}"

            // A flag to suppress the TLS certificate verification.
            disable-certificate-verification = true

            // The JID of the mod_client_proxy component if used. It will be trusted to encode the JID of the original
            // sender in the resource part of the JID.
            client-proxy = "{{ .Env.JICOFO_AUTH_USER }}.{{ .Env.XMPP_DOMAIN }}"
          }
        }

        {{ if .Env.JICOFO_RESERVATION_ENABLED | default "false" | toBool }}
        reservation {
          enabled = {{ .Env.JICOFO_RESERVATION_ENABLED }}
          base-url = {{ .Env.JICOFO_RESERVATION_REST_BASE_URL }}
        }
        {{ end }}
    }