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

jvmMain.com.pubnub.kmp.factories.jvm.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!

The newest version!
package com.pubnub.kmp

import com.pubnub.api.PubNub
import com.pubnub.api.models.consumer.PNStatus
import com.pubnub.api.models.consumer.pubsub.PNMessageResult
import com.pubnub.api.models.consumer.pubsub.PNPresenceEventResult
import com.pubnub.api.models.consumer.pubsub.PNSignalResult
import com.pubnub.api.models.consumer.pubsub.files.PNFileEventResult
import com.pubnub.api.models.consumer.pubsub.message_actions.PNMessageActionResult
import com.pubnub.api.models.consumer.pubsub.objects.PNObjectEventResult
import com.pubnub.api.v2.PNConfiguration
import com.pubnub.api.v2.callbacks.EventListener
import com.pubnub.api.v2.callbacks.StatusListener

actual fun createPubNub(config: PNConfiguration): PubNub {
    return PubNub.create(config)
}

actual fun createEventListener(
    pubnub: PubNub,
    onMessage: (PubNub, PNMessageResult) -> Unit,
    onPresence: (PubNub, PNPresenceEventResult) -> Unit,
    onSignal: (PubNub, PNSignalResult) -> Unit,
    onMessageAction: (PubNub, PNMessageActionResult) -> Unit,
    onObjects: (PubNub, PNObjectEventResult) -> Unit,
    onFile: (PubNub, PNFileEventResult) -> Unit
): EventListener {
    return object : EventListener {
        override fun message(pubnub: PubNub, result: PNMessageResult) {
            onMessage(pubnub, result)
        }

        override fun presence(pubnub: PubNub, result: PNPresenceEventResult) {
            onPresence(pubnub, result)
        }

        override fun signal(pubnub: PubNub, result: PNSignalResult) {
            onSignal(pubnub, result)
        }

        override fun messageAction(pubnub: PubNub, result: PNMessageActionResult) {
            onMessageAction(pubnub, result)
        }

        override fun objects(pubnub: PubNub, result: PNObjectEventResult) {
            onObjects(pubnub, result)
        }

        override fun file(pubnub: PubNub, result: PNFileEventResult) {
            onFile(pubnub, result)
        }
    }
}

actual fun createStatusListener(
    pubnub: PubNub,
    onStatus: (PubNub, PNStatus) -> Unit
): StatusListener {
    return object : StatusListener {
        override fun status(pubnub: PubNub, status: PNStatus) {
            onStatus(pubnub, status)
        }
    }
}

actual fun createCustomObject(map: Map): CustomObject {
    return map
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy