![JAR search and dependency download from the Maven repository](/logo.png)
com.pubnub.internal.endpoints.presence.HeartbeatEndpoint.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-kotlin-impl Show documentation
Show all versions of pubnub-kotlin-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.endpoints.presence
import com.pubnub.api.PubNubError
import com.pubnub.api.PubNubException
import com.pubnub.api.enums.PNOperationType
import com.pubnub.api.retry.RetryableEndpointGroup
import com.pubnub.internal.EndpointCore
import com.pubnub.internal.PubNubImpl
import com.pubnub.internal.PubNubUtil
import retrofit2.Call
import retrofit2.Response
class HeartbeatEndpoint internal constructor(
pubnub: PubNubImpl,
val channels: List = listOf(),
val channelGroups: List = listOf(),
val state: Any? = null,
) : EndpointCore(pubnub) {
override fun getAffectedChannels() = channels
override fun getAffectedChannelGroups() = channelGroups
override fun validateParams() {
super.validateParams()
if (channels.isEmpty() && channelGroups.isEmpty()) {
throw PubNubException(PubNubError.CHANNEL_AND_GROUP_MISSING)
}
}
override fun doWork(queryParams: HashMap): Call {
addQueryParams(queryParams)
val channelsCsv =
if (channels.isNotEmpty()) {
channels.joinToString(",")
} else {
","
}
return retrofitManager.presenceService.heartbeat(
configuration.subscribeKey,
channelsCsv,
queryParams,
)
}
private fun addQueryParams(queryParams: HashMap) {
queryParams["heartbeat"] = pubnub.configuration.presenceTimeout.toString()
if (channelGroups.isNotEmpty()) {
queryParams["channel-group"] = channelGroups.joinToString(",")
}
state?.let {
queryParams["state"] = pubnub.mapper.toJson(it)
}
PubNubUtil.maybeAddEeQueryParam(queryParams)
}
override fun createResponse(input: Response): Boolean {
return true
}
override fun operationType() = PNOperationType.PNHeartbeatOperation
override fun getEndpointGroupName(): RetryableEndpointGroup = RetryableEndpointGroup.PRESENCE
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy