
com.pubnub.internal.managers.BasePathManager.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-core-impl Show documentation
Show all versions of pubnub-core-impl Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!
package com.pubnub.internal.managers
import com.pubnub.api.v2.BasePNConfiguration
import com.pubnub.api.v2.BasePNConfiguration.Companion.isValid
internal class BasePathManager(private val config: BasePNConfiguration) {
/**
* for cache busting, the current subdomain number used.
*/
private var currentSubdomain = 1
/**
* if using cache busting, this is the max number of subdomains that are supported.
*/
private val MAX_SUBDOMAIN = 20
/**
* default subdomain used if cache busting is disabled.
*/
private val DEFAULT_SUBDOMAIN = "ps"
/**
* default base path if a custom one is not provided.
*/
private val DEFAULT_BASE_PATH = "pndsn.com"
fun basePath(): String {
val basePathBuilder =
StringBuilder("http")
.append(
if (config.secure) {
"s"
} else {
""
},
)
.append("://")
when {
config.origin.isValid() -> {
basePathBuilder.append(config.origin)
}
config.cacheBusting -> {
basePathBuilder
.append("ps")
.append(currentSubdomain)
.append(".")
.append(DEFAULT_BASE_PATH)
incrementSubdomain()
}
else -> {
basePathBuilder
.append(DEFAULT_SUBDOMAIN)
.append(".")
.append(DEFAULT_BASE_PATH)
}
}
return basePathBuilder.toString()
}
private fun incrementSubdomain() {
if (currentSubdomain == MAX_SUBDOMAIN) {
currentSubdomain = 1
} else {
currentSubdomain++
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy