
com.pubnub.internal.presence.eventengine.effect.PresenceEffectFactory.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.presence.eventengine.effect
import com.pubnub.api.enums.PNHeartbeatNotificationOptions
import com.pubnub.internal.eventengine.Effect
import com.pubnub.internal.eventengine.EffectFactory
import com.pubnub.internal.eventengine.Sink
import com.pubnub.internal.presence.eventengine.data.PresenceData
import com.pubnub.internal.presence.eventengine.effect.effectprovider.HeartbeatProvider
import com.pubnub.internal.presence.eventengine.effect.effectprovider.LeaveProvider
import com.pubnub.internal.presence.eventengine.event.PresenceEvent
import com.pubnub.internal.subscribe.eventengine.effect.StatusConsumer
import java.util.concurrent.ScheduledExecutorService
import kotlin.time.Duration
internal class PresenceEffectFactory(
private val heartbeatProvider: HeartbeatProvider,
private val leaveProvider: LeaveProvider,
private val presenceEventSink: Sink,
private val executorService: ScheduledExecutorService,
private val heartbeatInterval: Duration,
private val suppressLeaveEvents: Boolean,
private val heartbeatNotificationOptions: PNHeartbeatNotificationOptions,
private val statusConsumer: StatusConsumer,
private val presenceData: PresenceData,
private val sendStateWithHeartbeat: Boolean,
) : EffectFactory {
override fun create(effectInvocation: PresenceEffectInvocation): Effect? {
return when (effectInvocation) {
is PresenceEffectInvocation.Heartbeat -> {
val heartbeatRemoteAction =
heartbeatProvider.getHeartbeatRemoteAction(
effectInvocation.channels,
effectInvocation.channelGroups,
if (sendStateWithHeartbeat) {
presenceData.channelStates.filter { it.key in effectInvocation.channels }
} else {
null
},
)
HeartbeatEffect(heartbeatRemoteAction, presenceEventSink, heartbeatNotificationOptions, statusConsumer)
}
is PresenceEffectInvocation.Leave -> {
if (!suppressLeaveEvents) {
val leaveRemoteAction =
leaveProvider.getLeaveRemoteAction(
effectInvocation.channels,
effectInvocation.channelGroups,
)
LeaveEffect(leaveRemoteAction)
} else {
null
}
}
is PresenceEffectInvocation.Wait -> {
WaitEffect(heartbeatInterval, presenceEventSink, executorService)
}
PresenceEffectInvocation.CancelWait,
-> null
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy