Skip to content

Commit

Permalink
ref: Use our own config source (no need to load sip-communicator prop…
Browse files Browse the repository at this point in the history
…erties). (#19)
  • Loading branch information
bgrozev authored Nov 19, 2024
1 parent fa4d4ff commit aa0d28a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@
<version>${kotest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jitsi</groupId>
<artifactId>jicoco-test-kotlin</artifactId>
<version>1.1-144-ga2c5ec1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
Expand Down
17 changes: 10 additions & 7 deletions src/main/kotlin/org/jitsi/recorder/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,41 @@
*/
package org.jitsi.recorder

import org.jitsi.config.JitsiConfig
import com.typesafe.config.ConfigFactory
import org.jitsi.config.ConfigSourceWrapper
import org.jitsi.config.TypesafeConfigSource
import org.jitsi.metaconfig.config
import org.jitsi.metaconfig.optionalconfig
import kotlin.time.Duration
import kotlin.time.toKotlinDuration

class Config {
companion object {
const val BASE = "jitsi-multitrack-recorder"
val configSource = ConfigSourceWrapper(TypesafeConfigSource("config", ConfigFactory.load()))
private const val BASE = "jitsi-multitrack-recorder"

val port: Int by config {
"$BASE.port".from(JitsiConfig.newConfig)
"$BASE.port".from(configSource)
}

val recordingDirectory: String by config {
"$BASE.recording.directory".from(JitsiConfig.newConfig)
"$BASE.recording.directory".from(configSource)
}

val recordingFormat: RecordingFormat by config {
"$BASE.recording.format".from(JitsiConfig.newConfig).convertFrom<String> {
"$BASE.recording.format".from(configSource).convertFrom<String> {
RecordingFormat.valueOf(it.uppercase())
}
}

val maxGapDuration: Duration by config {
"$BASE.recording.max-gap-duration".from(JitsiConfig.newConfig).convertFrom<java.time.Duration> {
"$BASE.recording.max-gap-duration".from(configSource).convertFrom<java.time.Duration> {
it.toKotlinDuration()
}
}

val finalizeScript: String? by optionalconfig {
"$BASE.finalize-script".from(JitsiConfig.newConfig)
"$BASE.finalize-script".from(configSource)
}

override fun toString(): String = """
Expand Down
24 changes: 21 additions & 3 deletions src/main/kotlin/org/jitsi/recorder/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import io.ktor.server.websocket.webSocket
import io.ktor.websocket.Frame
import io.ktor.websocket.readText
import org.jitsi.mediajson.Event
import org.jitsi.metaconfig.MetaconfigLogger
import org.jitsi.metaconfig.MetaconfigSettings
import org.jitsi.utils.logging2.LoggerImpl
import org.jitsi.utils.logging2.createLogger
import java.io.File
Expand Down Expand Up @@ -79,11 +81,11 @@ fun Application.module() {
}
}

fun main(args: Array<String>) {
fun main() {
setupMetaconfigLogger()
logger.info("Starting jitsi-multitrack-recorder with config:\n $Config")
metrics.sessionsStarted.inc()
embeddedServer(Netty, port = Config.port, host = "0.0.0.0", module = Application::module)
.start(wait = true)
embeddedServer(Netty, port = Config.port, host = "0.0.0.0", module = Application::module).start(wait = true)
}

class RecordingSession(private val meetingId: String) {
Expand Down Expand Up @@ -135,3 +137,19 @@ class RecordingSession(private val meetingId: String) {
}
}
}

/** Wire the jitsi-metaconfig logger into ours */
private fun setupMetaconfigLogger() {
val configLogger = LoggerImpl("org.jitsi.jibri.config")
MetaconfigSettings.logger = object : MetaconfigLogger {
override fun debug(block: () -> String) {
configLogger.debug(block)
}
override fun error(block: () -> String) {
configLogger.error(block())
}
override fun warn(block: () -> String) {
configLogger.warn(block)
}
}
}
3 changes: 1 addition & 2 deletions src/test/kotlin/org/jitsi/recorder/MkaRecorderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.ebml.Element
import org.ebml.MasterElement
import org.ebml.io.DataSource
import org.ebml.io.FileDataSource
import org.jitsi.config.withNewConfig
import org.jitsi.mediajson.Event
import org.jitsi.mediajson.MediaEvent
import org.jitsi.mediajson.StartEvent
Expand Down Expand Up @@ -81,7 +80,7 @@ class MkaRecorderTest : ShouldSpec() {
)
}
context("Test PLC with a big gap") {
withNewConfig("jitsi-multitrack-recorder.recording.max-gap-duration = 5 seconds") {
withConfig("jitsi-multitrack-recorder.recording.max-gap-duration = 5 seconds") {
Config.maxGapDuration shouldBe 5.seconds

val directory = Files.createTempDirectory("MediaJsonMkaRecorderTest").toFile()
Expand Down
13 changes: 13 additions & 0 deletions src/test/kotlin/org/jitsi/recorder/TestUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.jitsi.recorder

import com.typesafe.config.ConfigFactory
import org.jitsi.config.TypesafeConfigSource
import java.util.concurrent.Callable
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
Expand Down Expand Up @@ -57,3 +59,14 @@ internal fun setupInPlaceIoPool() {
TODO("Not yet implemented")
}
}

fun withConfig(config: String, block: () -> Unit) {
val originalConfigSource = Config.configSource.innerSource

Config.configSource.innerSource = TypesafeConfigSource(
"custom config",
ConfigFactory.parseString(config).run { withFallback(ConfigFactory.load()) }
)
block()
Config.configSource.innerSource = originalConfigSource
}

0 comments on commit aa0d28a

Please sign in to comment.