
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
com.pubnub:pubnub-gson
Advanced tools
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!
This is the official PubNub Kotlin SDK repository.
PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.
You will need the publish and subscribe keys to authenticate your app. Get your keys from the Admin Portal.
Integrate the Kotlin SDK into your project:
for Maven, add the following dependency in your pom.xml
:
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-kotlin</artifactId>
<version>10.5.0</version>
</dependency>
for Gradle, add the following dependency in your gradle.build
:
implementation ("com.pubnub:pubnub-kotlin:10.0.0")
Configure your keys and create PubNub instance:
val config = PNConfiguration.builder(UserId("myUserId"), "mySubKey") {
publishKey = "myPubKey"
}
val pubnub = PubNub.create(config.build())
// Create a subscription to a specific channel
val subscription = pubnub.channel("my_channel").subscription(SubscriptionOptions.receivePresenceEvents())
// Add a listener to the subscription for handling various event types
subscription.addListener(object : EventListener {
override fun message(pubnub: PubNub, message: PNMessageResult) {
// Log or process message
println("Message: ${message.message}")
}
override fun signal(pubnub: PubNub, signal: PNSignalResult) {
// Handle signals
println("Signal: ${signal.message}")
}
override fun messageAction(pubnub: PubNub, messageAction: PNMessageActionResult) {
// Handle message reactions
println("Message Reaction: ${messageAction.data}")
}
override fun file(pubnub: PubNub, file: PNFileEventResult) {
// Handle file events
println("File: ${file.file.name}")
}
override fun objects(pubnub: PubNub, obj: PNObjectEventResult) {
// Handle metadata updates
println("App Context: ${obj.event}")
}
override fun presence(pubnub: PubNub, presence: PNPresenceEventResult) {
// Handle presence updates
// requires a subscription with presence
println("Presence: ${presence.uuid} - ${presence.event}")
}
})
// Adding the status listener to the PubNub client
pubnub.addListener(object : StatusListener() {
override fun status(pubnub: PubNub, status: PNStatus) {
// This block is executed asynchronously for each status update
println("Connection Status: ${status.category}")
}
})
// for subscription set
val subscriptionSet = pubnub.subscriptionSetOf(
// Specify channels with default options
channels = setOf("my_channel", "other_channel"),
)
subscriptionSet.addListener(object : EventListener {
override fun message(pubnub: PubNub, message: PNMessageResult) {
// Log or process message
println("Message: ${message.message}")
}
})
pubnub.addListener(object : SubscribeCallback() {
override fun status(pubnub: PubNub, status: PNStatus) {
println("Status category: ${status.category}")
// PNConnectedCategory, PNReconnectedCategory, PNDisconnectedCategory
println("Status operation: ${status.operation}")
// PNSubscribeOperation, PNHeartbeatOperation
println("Status error: ${status.error}")
// true or false
}
override fun presence(pubnub: PubNub, pnPresenceEventResult: PNPresenceEventResult) {
println("Presence event: ${pnPresenceEventResult.event}")
println("Presence channel: ${pnPresenceEventResult.channel}")
println("Presence uuid: ${pnPresenceEventResult.uuid}")
println("Presence timetoken: ${pnPresenceEventResult.timetoken}")
println("Presence occupancy: ${pnPresenceEventResult.occupancy}")
}
override fun message(pubnub: PubNub, pnMessageResult: PNMessageResult) {
println("Message payload: ${pnMessageResult.message}")
println("Message channel: ${pnMessageResult.channel}")
println("Message publisher: ${pnMessageResult.publisher}")
println("Message timetoken: ${pnMessageResult.timetoken}")
}
override fun signal(pubnub: PubNub, pnSignalResult: PNSignalResult) {
println("Signal payload: ${pnSignalResult.message}")
println("Signal channel: ${pnSignalResult.channel}")
println("Signal publisher: ${pnSignalResult.publisher}")
println("Signal timetoken: ${pnSignalResult.timetoken}")
}
override fun messageAction(pubnub: PubNub, pnMessageActionResult: PNMessageActionResult) {
with(pnMessageActionResult.messageAction) {
println("Message action type: $type")
println("Message action value: $value")
println("Message action uuid: $uuid")
println("Message action actionTimetoken: $actionTimetoken")
println("Message action messageTimetoken: $messageTimetoken")
}
println("Message action subscriptions: ${pnMessageActionResult.subscription}")
println("Message action channel: ${pnMessageActionResult.channel}")
println("Message action timetoken: ${pnMessageActionResult.timetoken}")
}
})
subscription.subscribe()
pubnub.subscribe(channels = listOf("my_channel"), withPresence = true)
val channel = pubnub.channel("my_channel")
channel.publish(message = "hello").async { result ->
result.onSuccess { response ->
println("Message timetoken: ${response.timetoken}")
}.onFailure { exception ->
println("ERROR: Failed to publish message")
println("Error details: ${exception.message}")
}
}
pubnub.publish(channel = "my_channel", message = "hello")
.async { result ->
// the result is always of a nullable type
// it's null if there were errors (status.error)
// otherwise it's usable
// handle publish result
result.onSuccess { res ->
println("Message timetoken: ${res!!.timetoken}")
}.onFailure { exception ->
// handle error
exception.printStackTrace()
}
}
pubnub.subscribe(channels = listOf("my_channel"))
If you need help or have a general question, contact support@pubnub.com.
FAQs
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!
We found that com.pubnub:pubnub-gson demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.