All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pubnub.api.subscribe.eventengine.effect.effectprovider.ReceiveMessagesProviderImpl.kt Maven / Gradle / Ivy

Go to download

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!

There is a newer version: 10.2.0
Show newest version
package com.pubnub.api.subscribe.eventengine.effect.effectprovider

import com.pubnub.api.PubNub
import com.pubnub.api.endpoints.pubsub.Subscribe
import com.pubnub.api.endpoints.remoteaction.RemoteAction
import com.pubnub.api.endpoints.remoteaction.map
import com.pubnub.api.models.consumer.pubsub.PNEvent
import com.pubnub.api.subscribe.eventengine.effect.ReceiveMessagesResult
import com.pubnub.api.subscribe.eventengine.event.SubscriptionCursor
import com.pubnub.api.workers.SubscribeMessageProcessor

internal class ReceiveMessagesProviderImpl(val pubNub: PubNub, val messageProcessor: SubscribeMessageProcessor) : ReceiveMessagesProvider {

    override fun getReceiveMessagesRemoteAction(
        channels: Set,
        channelGroups: Set,
        subscriptionCursor: SubscriptionCursor
    ): RemoteAction {
        val subscribe = Subscribe(pubNub)
        subscribe.channels = channels.toList()
        subscribe.channelGroups = channelGroups.toList()
        subscribe.timetoken = subscriptionCursor.timetoken
        subscribe.region = subscriptionCursor.region
        return subscribe.map {
            val sdkMessages: List = it.messages.mapNotNull {
                messageProcessor.processIncomingPayload(it)
            }
            ReceiveMessagesResult(
                sdkMessages, SubscriptionCursor(it.metadata.timetoken, it.metadata.region)
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy