Skip to content

Commit

Permalink
Send Leave when explicitly calling presence(connected=false) with EE (#…
Browse files Browse the repository at this point in the history
…188)

* Send Leave when explicitly calling presence(connected=false) with EE

* PubNub SDK v8.0.0 release.

---------

Co-authored-by: marcin.cebo <[email protected]>
Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
3 people authored Feb 22, 2024
1 parent 83f5d51 commit 3e964d6
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 28 deletions.
15 changes: 11 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: kotlin
version: 7.8.1
version: 8.0.0
schema: 1
scm: github.com/pubnub/kotlin
files:
- build/libs/pubnub-kotlin-7.8.1-all.jar
- build/libs/pubnub-kotlin-8.0.0-all.jar
sdks:
-
type: library
Expand All @@ -23,8 +23,8 @@ sdks:
-
distribution-type: library
distribution-repository: maven
package-name: pubnub-kotlin-7.8.1
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/7.8.1/pubnub-kotlin-7.8.1.jar
package-name: pubnub-kotlin-8.0.0
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/8.0.0/pubnub-kotlin-8.0.0.jar
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -114,6 +114,13 @@ sdks:
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
is-required: Required
changelog:
- date: 2024-02-22
version: v8.0.0
changes:
- type: feature
text: "A new version of subscription and presence handling is enabled by default (`enableEventEngine` flag is set to `true`). Please consult the documentation for new PNStatus values that are emitted for subscriptions, as code changes might be required to support this change."
- type: feature
text: "Added support for scoped event listeners using new entity objects: Channels, ChannelGroups, ChannelMetadata and UserMetadata."
- date: 2024-02-06
version: v7.8.1
changes:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v8.0.0
February 22 2024

#### Added
- A new version of subscription and presence handling is enabled by default (`enableEventEngine` flag is set to `true`). Please consult the documentation for new PNStatus values that are emitted for subscriptions, as code changes might be required to support this change.
- Added support for scoped event listeners using new entity objects: Channels, ChannelGroups, ChannelMetadata and UserMetadata.

## v7.8.1
February 06 2024

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-kotlin</artifactId>
<version>7.8.1</version>
<version>8.0.0</version>
</dependency>
```

* for Gradle, add the following dependency in your `gradle.build`:
```groovy
implementation 'com.pubnub:pubnub-kotlin:7.8.1'
implementation 'com.pubnub:pubnub-kotlin:8.0.0'
```

2. Configure your keys:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=true
GROUP=com.pubnub
POM_ARTIFACT_ID=pubnub-kotlin
VERSION_NAME=7.8.1
VERSION_NAME=8.0.0
POM_PACKAGING=jar

POM_NAME=PubNub Kotlin SDK
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/pubnub/api/PubNub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PubNub internal constructor(

companion object {
private const val TIMESTAMP_DIVIDER = 1000
private const val SDK_VERSION = "7.8.1"
private const val SDK_VERSION = "8.0.0"
private const val MAX_SEQUENCE = 65535

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/com/pubnub/api/callbacks/SubscribeCallback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ abstract class SubscribeCallback : Listener, StatusListener, EventListener {

/**
* Receive status events like
* [PNStatusCategory.PNAcknowledgmentCategory],
* [PNStatusCategory.PNConnectedCategory],
* [PNStatusCategory.PNReconnectedCategory]
* [PNStatusCategory.PNDisconnectedCategory],
* [PNStatusCategory.PNSubscriptionChanged]
* [PNStatusCategory.PNConnectionError],
* [PNStatusCategory.PNUnexpectedDisconnectCategory],
* [PNStatusCategory.PNAcknowledgmentCategory]
*
* and other events related to the subscribe loop and channel mix.
*
Expand Down
22 changes: 7 additions & 15 deletions src/main/kotlin/com/pubnub/api/presence/Presence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ internal interface Presence {
channels: Set<String> = emptySet(),
channelGroups: Set<String> = emptySet(),
connected: Boolean = false
)
) {
if (connected) {
joined(channels, channelGroups)
} else {
left(channels, channelGroups)
}
}

fun reconnect()

Expand Down Expand Up @@ -128,8 +134,6 @@ internal class PresenceNoOp(private val suppressLeaveEvents: Boolean = false, pr
channelGroups.clear()
}

override fun presence(channels: Set<String>, channelGroups: Set<String>, connected: Boolean) = noAction()

override fun reconnect() = noAction()

override fun disconnect() = noAction()
Expand Down Expand Up @@ -163,18 +167,6 @@ internal class EnabledPresence(
presenceEventEngineManager.addEventToQueue(PresenceEvent.LeftAll)
}

override fun presence(
channels: Set<String>,
channelGroups: Set<String>,
connected: Boolean
) {
if (connected) {
joined(channels, channelGroups)
} else {
left(channels, channelGroups)
}
}

override fun reconnect() {
presenceEventEngineManager.addEventToQueue(PresenceEvent.Reconnect)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/pubnub/api/legacy/PubNubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PubNubTest : BaseTest() {
fun getVersionAndTimeStamp() {
val version = pubnub.version
val timeStamp = pubnub.timestamp()
assertEquals("7.8.1", version)
assertEquals("8.0.0", version)
assertTrue(timeStamp > 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Assume.assumeFalse
import org.junit.Ignore
import org.junit.Test
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -2651,8 +2650,9 @@ class SubscriptionManagerTest : BaseTest() {
}

@Test
@Ignore("Presence EE doesn't support this right now") // TODO add missing functionality?
fun testAllHeartbeatsLeaveViaPresence() {
// in case of EE the leave event is sent, but EE spec doesn't send status for it, so there's no way to check
assumeFalse("Test skipped because enableEventEngine is true", pubnub.configuration.enableEventEngine)
val statusReceived = AtomicBoolean()
initPubNub(
PubNub(
Expand Down
22 changes: 22 additions & 0 deletions src/test/kotlin/com/pubnub/api/presence/PresenceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.mockk.verify
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertInstanceOf
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
Expand Down Expand Up @@ -137,6 +138,27 @@ internal class PresenceTest {
verify { leaveProviderMock.getLeaveRemoteAction(any(), any()) }
}

@Test
fun `Leave events created when suppressLeaveEvents is false and heartbeat interval is 0 and presence(false) called`() {
// given
val leaveProviderMock: LeaveProvider = mockk()
every { leaveProviderMock.getLeaveRemoteAction(any(), any()) } returns successfulRemoteAction(true)

val presence = Presence.create(
listenerManager = listenerManager,
heartbeatInterval = 0.seconds,
suppressLeaveEvents = false,
leaveProvider = leaveProviderMock,
)

// when
presence.presence(channels = setOf("abc"), connected = false)

// then
assertInstanceOf(PresenceNoOp::class.java, presence)
verify { leaveProviderMock.getLeaveRemoteAction(any(), any()) }
}

private fun Presence.Companion.create(
listenerManager: ListenerManager,
heartbeatInterval: Duration = 3.seconds,
Expand Down

0 comments on commit 3e964d6

Please sign in to comment.