Skip to content

Commit

Permalink
Merge pull request #77 from kuzzleio/1.3.1-proposal
Browse files Browse the repository at this point in the history
Release 1.3.1
  • Loading branch information
Shiranuit authored May 17, 2022
2 parents d7f66c4 + 1ba29be commit 8227e58
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {

val artifactName = "sdk-jvm"
val artifactGroup = "io.kuzzle"
val artifactVersion = "1.3.0"
val artifactVersion = "1.3.1"

val pomUrl = "https://github.com/kuzzleio/sdk-jvm"
val pomScmUrl = "https://github.com/kuzzleio/sdk-jvm"
Expand All @@ -35,7 +35,7 @@ val pomDeveloperId = "kuzzleio"
val pomDeveloperName = "kuzzle"

group = "io.kuzzle.sdk"
version = "1.3.0"
version = "1.3.1"
val ktorVersion = "1.6.8"

repositories {
Expand Down
6 changes: 3 additions & 3 deletions doc/1/getting-started/java/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ To build the project, add the following lines:
<dependency>
<groupId>io.kuzzle</groupId>
<artifactId>sdk-jvm</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
<type>pom</type>
</dependency>
```
Expand All @@ -70,14 +70,14 @@ To build the project, add the following lines:

```groovy
dependencies {
compile 'io.kuzzle:sdk-jvm:1.3.0'
compile 'io.kuzzle:sdk-jvm:1.3.1'
}
```

### Ivy

```html
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.3.0'>
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.3.1'>
<artifact name='sdk-jvm' ext='pom' ></artifact>
</dependency>
```
Expand Down
6 changes: 3 additions & 3 deletions doc/1/getting-started/kotlin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ To build the project, add the following lines:
<dependency>
<groupId>io.kuzzle</groupId>
<artifactId>sdk-jvm</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
<type>pom</type>
</dependency>
```
Expand All @@ -82,14 +82,14 @@ To build the project, add the following lines:

```groovy
dependencies {
compile 'io.kuzzle:sdk-jvm:1.3.0'
compile 'io.kuzzle:sdk-jvm:1.3.1'
}
```

### Ivy

```html
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.3.0'>
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.3.1'>
<artifact name='sdk-jvm' ext='pom' ></artifact>
</dependency>
```
Expand Down
28 changes: 14 additions & 14 deletions src/main/kotlin/io/kuzzle/sdk/Kuzzle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ open class Kuzzle {
if (event.requestId != null && queries[event.requestId!!] != null) {
queries[event.requestId!!]?.completeExceptionally(event.exception)
queries.remove(event.requestId!!)
} else {
protocol.trigger(UnhandledExceptionEvent(event.exception))
}
}

Expand All @@ -73,7 +75,7 @@ open class Kuzzle {
queries[event.requestId]?.completeExceptionally(InvalidJSON(event.message ?: "null"))
queries.remove(event.requestId)
} else {
protocol.trigger(UnhandledResponseEvent(message))
protocol.trigger(UnhandledExceptionEvent(InvalidJSON(event.message ?: "null")))
}
return
}
Expand All @@ -90,28 +92,26 @@ open class Kuzzle {

val requestId = event.requestId ?: response.room ?: response.requestId

if (queries.size == 0 || requestId == null || queries[requestId] == null) {
protocol.trigger(UnhandledResponseEvent(message))
return
if (response.error?.id == "security.token.expired") {
protocol.trigger(TokenExpiredEvent())
}

if (response.error == null) {
queries[requestId]?.complete(response)
queries.remove(requestId)
if (queries.isEmpty() || requestId == null || queries[requestId] == null) {
if (response.error != null) {
protocol.trigger(UnhandledExceptionEvent(ApiErrorException(response)))
return
}
protocol.trigger(RoomMessageEvent(response))
return
}

if (response.error?.id == null ||
response.error?.id != "security.token.expired"
) {
if (response.error != null) {
queries[requestId]?.completeExceptionally(ApiErrorException(response))
queries.remove(requestId)
return
} else {
queries[requestId]?.complete(response)
}

queries[requestId]?.completeExceptionally(ApiErrorException(response))
queries.remove(requestId)
protocol.trigger(TokenExpiredEvent())
}

private fun onNetworkStateChange(event: NetworkStateChangeEvent) {
Expand Down
33 changes: 12 additions & 21 deletions src/main/kotlin/io/kuzzle/sdk/controllers/RealtimeController.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.kuzzle.sdk.controllers

import io.kuzzle.sdk.Kuzzle
import io.kuzzle.sdk.coreClasses.json.JsonSerializer
import io.kuzzle.sdk.coreClasses.maps.KuzzleMap
import io.kuzzle.sdk.coreClasses.responses.Response
import io.kuzzle.sdk.events.NetworkStateChangeEvent
import io.kuzzle.sdk.events.TokenExpiredEvent
import io.kuzzle.sdk.events.RoomMessageEvent
import io.kuzzle.sdk.events.UnhandledResponseEvent
import io.kuzzle.sdk.handlers.NotificationHandler
import io.kuzzle.sdk.protocol.ProtocolState
Expand All @@ -25,28 +24,20 @@ class RealtimeController(kuzzle: Kuzzle) : BaseController(kuzzle) {
)

init {
kuzzle.protocol.addListener<UnhandledResponseEvent> {
val response = Response().apply {
fromMap(JsonSerializer.deserialize(it.message) as Map<String?, Any?>)
}

if (response.error != null && response.error!!.id.equals("security.token.expired")) {
kuzzle.protocol.trigger(TokenExpiredEvent())
} else {
var sdkInstanceId = ""
if (response.Volatile != null) {
sdkInstanceId = response.Volatile!!["sdkInstanceId"].toString()
}
kuzzle.protocol.addListener<RoomMessageEvent> { event ->
val response: Response = event.response
var sdkInstanceId = response.Volatile?.get("sdkInstanceId")?.toString()

val subs: ArrayList<Subscription>? = currentSubscriptions[response.room]
if (subs != null) {
val instanceId = sdkInstanceId
subs.forEach {
if (instanceId == kuzzle.instanceId && it.subscribeToSelf || instanceId != kuzzle.instanceId) {
it.handler(response)
}
val subscriptions: ArrayList<Subscription>? = currentSubscriptions[response.room]
if (subscriptions != null) {
val instanceId = sdkInstanceId
subscriptions.forEach {
if (instanceId == kuzzle.instanceId && it.subscribeToSelf || instanceId != kuzzle.instanceId) {
it.handler(response)
}
}
} else {
kuzzle.protocol.trigger(UnhandledResponseEvent(response))
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/io/kuzzle/sdk/events/RoomMessageEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.kuzzle.sdk.events

import io.kuzzle.sdk.coreClasses.responses.Response

data class RoomMessageEvent(val response: Response)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.kuzzle.sdk.events

data class UnhandledExceptionEvent(val exception: Exception)
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package io.kuzzle.sdk.events

data class UnhandledResponseEvent(var message: String?)
import io.kuzzle.sdk.coreClasses.responses.Response

data class UnhandledResponseEvent(var message: Response?)

0 comments on commit 8227e58

Please sign in to comment.