Skip to content

Commit

Permalink
feat: Add an option to randomize the username used to login to join t…
Browse files Browse the repository at this point in the history
…he conference.
  • Loading branch information
bgrozev committed Feb 15, 2024
1 parent 0529453 commit 164eda4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/example_xmpp_envs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/jitsi/jibri/config/JibriConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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=*****)"
Expand All @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/org/jitsi/jibri/selenium/JibriSelenium.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions src/main/kotlin/org/jitsi/jibri/util/RandomUtils.kt
Original file line number Diff line number Diff line change
@@ -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("")
}

0 comments on commit 164eda4

Please sign in to comment.