diff --git a/doc/example_xmpp_envs.conf b/doc/example_xmpp_envs.conf index 445a529c..af6ac6fb 100644 --- a/doc/example_xmpp_envs.conf +++ b/doc/example_xmpp_envs.conf @@ -29,6 +29,8 @@ port = 6222 username = "username" password = "password" + // Whether to use `username` as is or add a random suffix to it. + randomize-username = false } // An (optional) MUC configuration where we'll diff --git a/src/main/kotlin/org/jitsi/jibri/config/JibriConfig.kt b/src/main/kotlin/org/jitsi/jibri/config/JibriConfig.kt index fe1ed370..1d0c959f 100644 --- a/src/main/kotlin/org/jitsi/jibri/config/JibriConfig.kt +++ b/src/main/kotlin/org/jitsi/jibri/config/JibriConfig.kt @@ -33,7 +33,8 @@ data class XmppCredentials( val domain: String = "", val port: Int? = null, val username: String = "", - val password: String = "" + val password: String = "", + val randomizeUsername: Boolean = false ) { override fun toString(): String { return "XmppCredentials(domain=$domain, port=$port, username=$username, password=*****)" @@ -44,7 +45,8 @@ fun com.typesafe.config.Config.toXmppCredentials(): XmppCredentials = XmppCreden domain = getString("domain"), port = if (hasPath("port")) getInt("port") else null, username = getString("username"), - password = getString("password") + password = getString("password"), + randomizeUsername = getBoolean("randomize-username") ) data class XmppMuc( diff --git a/src/main/kotlin/org/jitsi/jibri/selenium/JibriSelenium.kt b/src/main/kotlin/org/jitsi/jibri/selenium/JibriSelenium.kt index 1f1d31f3..3de2cf1f 100644 --- a/src/main/kotlin/org/jitsi/jibri/selenium/JibriSelenium.kt +++ b/src/main/kotlin/org/jitsi/jibri/selenium/JibriSelenium.kt @@ -32,6 +32,7 @@ import org.jitsi.jibri.util.StatusPublisher import org.jitsi.jibri.util.TaskPools import org.jitsi.jibri.util.extensions.scheduleAtFixedRate import org.jitsi.jibri.util.getLoggerWithHandler +import org.jitsi.jibri.util.randomAlphaNum import org.jitsi.metaconfig.config import org.jitsi.metaconfig.from import org.jitsi.utils.logging2.Logger @@ -307,8 +308,12 @@ class JibriSelenium( "callStatsUserName" to callStatsUsername ) xmppCredentials?.let { - localStorageValues["xmpp_username_override"] = - "${xmppCredentials.username}@${xmppCredentials.domain}" + val username = if (xmppCredentials.randomizeUsername) { + "${xmppCredentials.username}-${randomAlphaNum(8)}" + } else { + xmppCredentials.username + } + localStorageValues["xmpp_username_override"] = "$username@${xmppCredentials.domain}" localStorageValues["xmpp_password_override"] = xmppCredentials.password } passcode?.let { diff --git a/src/main/kotlin/org/jitsi/jibri/util/RandomUtils.kt b/src/main/kotlin/org/jitsi/jibri/util/RandomUtils.kt new file mode 100644 index 00000000..0911bfde --- /dev/null +++ b/src/main/kotlin/org/jitsi/jibri/util/RandomUtils.kt @@ -0,0 +1,23 @@ +/* + * Copyright @ 2024 - present 8x8, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jitsi.jibri.util + +import kotlin.random.Random + +val alphaNum = ('a'..'z') + ('0'..'9') +fun randomAlphaNum(len: Int): String { + return List(len) { Random.nextInt(0, alphaNum.size) }.joinToString("") +}