Subscription

Represents a potential subscription to the PubNub real-time network.

Create objects of this class through the com.pubnub.api.v2.entities.Subscribable.subscription method of the respective entities, such as com.pubnub.api.v2.entities.Channel, com.pubnub.api.v2.entities.ChannelGroup, com.pubnub.api.v2.entities.ChannelMetadata and com.pubnub.api.v2.entities.UserMetadata.

Created subscriptions are initially inactive, which means you must call subscribe to start receiving events.

This class implements the AutoCloseable interface to help you release resources by calling unsubscribe and removing all listeners on close. Remember to always call close when you no longer need this Subscription.

Properties

Link copied to clipboard
open var onFile: (PNFileEventResult) -> Unit?

A nullable property to set a function or lambda for responding to file events. This function is invoked whenever a new file event is received, providing a convenient way to process or react to file events.

Link copied to clipboard

A nullable property that can be set to a function (or lambda expression) to handle incoming message events. This function is invoked whenever a new message is received, providing a convenient way to process or react to messages.

Link copied to clipboard

A nullable property that allows setting a function or lambda to react to message action events. This function is invoked whenever a new message action is received, providing a convenient way to process or react to message actions.

Link copied to clipboard

A nullable property for assigning a function or lambda to handle object events. This function is triggered with each new object event, providing a mechanism to manage object-related updates.

Link copied to clipboard

A nullable property designed to set a function or lambda expression for handling incoming presence events. This function is called whenever a new presence event occurs, offering an efficient method for tracking presence updates.

Link copied to clipboard
open var onSignal: (PNSignalResult) -> Unit?

A nullable property for assigning a function or lambda expression to handle incoming signal events. This function is called whenever a new signal is received, providing a convenient way to process or react to signals.

Functions

Link copied to clipboard
abstract fun addListener(listener: EventListener)

Add a listener.

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract operator fun plus(subscription: Subscription): SubscriptionSet

Create a SubscriptionSet containing this Subscription and the added subscription.

Link copied to clipboard
abstract fun removeAllListeners()

Removes all listeners.

Link copied to clipboard
abstract fun removeListener(listener: Listener)

Remove a listener.

Link copied to clipboard
abstract fun subscribe(cursor: SubscriptionCursor)
Link copied to clipboard
abstract fun unsubscribe()