-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename modules to match
ktor
plugins and migrate them to new ktor API
- Loading branch information
Showing
21 changed files
with
277 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.ktor.client | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.plugins.* | ||
import io.ktor.client.plugins.api.* | ||
import io.ktor.client.plugins.websocket.* | ||
import io.ktor.client.request.* | ||
import io.ktor.util.* | ||
import io.rsocket.kotlin.* | ||
import io.rsocket.kotlin.core.* | ||
import io.rsocket.kotlin.transport.* | ||
import io.rsocket.kotlin.transport.ktor.websocket.internal.* | ||
import kotlinx.coroutines.* | ||
import kotlin.coroutines.* | ||
|
||
private val RSocketSupportConfigKey = AttributeKey<RSocketSupportConfig.Internal>("RSocketSupportConfig") | ||
|
||
public val RSocketSupport: ClientPlugin<RSocketSupportConfig> = createClientPlugin("RSocketSupport", ::RSocketSupportConfig) { | ||
client.pluginOrNull(WebSockets) ?: error("RSocket require WebSockets to work. You must install WebSockets plugin first.") | ||
client.attributes.put(RSocketSupportConfigKey, pluginConfig.toInternal()) | ||
} | ||
|
||
public class RSocketSupportConfig internal constructor() { | ||
private var connector = RSocketConnector() | ||
|
||
public fun connector(connector: RSocketConnector) { | ||
this.connector = connector | ||
} | ||
|
||
public fun connector(block: RSocketConnectorBuilder.() -> Unit) { | ||
this.connector = RSocketConnector(block) | ||
} | ||
|
||
internal fun toInternal(): Internal = Internal(connector) | ||
internal class Internal(val connector: RSocketConnector) | ||
} | ||
|
||
internal suspend fun HttpClient.connectRSocket(request: HttpRequestBuilder.() -> Unit): RSocket { | ||
val config = attributes.getOrNull(RSocketSupportConfigKey) | ||
?: error("Plugin `RSocketSupport` is not installed. Consider using `install(RSocketSupport)` in client config first.") | ||
|
||
return config.connector.connect(RSocketSupportTarget(this, request)) | ||
} | ||
|
||
private class RSocketSupportTarget( | ||
private val client: HttpClient, | ||
private val request: HttpRequestBuilder.() -> Unit, | ||
) : RSocketClientTarget { | ||
override val coroutineContext: CoroutineContext get() = client.coroutineContext | ||
|
||
@RSocketTransportApi | ||
override fun connectClient(handler: RSocketConnectionHandler): Job = launch { | ||
client.webSocket(request) { | ||
handler.handleKtorWebSocketConnection(this) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ktor-plugins/ktor-server-rsocket/api/ktor-server-rsocket.api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public final class io/rsocket/kotlin/ktor/server/RSocketSupportConfig { | ||
public final fun server (Lio/rsocket/kotlin/core/RSocketServer;)V | ||
public final fun server (Lkotlin/jvm/functions/Function1;)V | ||
} | ||
|
||
public final class io/rsocket/kotlin/ktor/server/RSocketSupportKt { | ||
public static final fun getRSocketSupport ()Lio/ktor/server/application/ApplicationPlugin; | ||
} | ||
|
||
public final class io/rsocket/kotlin/ktor/server/RoutingKt { | ||
public static final fun rSocket (Lio/ktor/server/routing/Route;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;)V | ||
public static final fun rSocket (Lio/ktor/server/routing/Route;Ljava/lang/String;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;)V | ||
public static synthetic fun rSocket$default (Lio/ktor/server/routing/Route;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;ILjava/lang/Object;)V | ||
public static synthetic fun rSocket$default (Lio/ktor/server/routing/Route;Ljava/lang/String;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;ILjava/lang/Object;)V | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.ktor.server | ||
|
||
import io.ktor.server.application.* | ||
import io.ktor.server.routing.* | ||
import io.ktor.server.websocket.* | ||
import io.ktor.util.* | ||
import io.rsocket.kotlin.* | ||
import io.rsocket.kotlin.core.* | ||
import io.rsocket.kotlin.transport.* | ||
import io.rsocket.kotlin.transport.ktor.websocket.internal.* | ||
|
||
private val RSocketSupportConfigKey = AttributeKey<RSocketSupportConfig.Internal>("RSocketSupportConfig") | ||
|
||
public val RSocketSupport: ApplicationPlugin<RSocketSupportConfig> = createApplicationPlugin("RSocketSupport", ::RSocketSupportConfig) { | ||
application.pluginOrNull(WebSockets) ?: error("RSocket require WebSockets to work. You must install WebSockets plugin first.") | ||
application.attributes.put(RSocketSupportConfigKey, pluginConfig.toInternal()) | ||
} | ||
|
||
public class RSocketSupportConfig internal constructor() { | ||
private var server: RSocketServer = RSocketServer() | ||
|
||
public fun server(server: RSocketServer) { | ||
this.server = server | ||
} | ||
|
||
public fun server(block: RSocketServerBuilder.() -> Unit) { | ||
server = RSocketServer(block) | ||
} | ||
|
||
|
||
internal fun toInternal(): Internal = Internal(server) | ||
internal class Internal(val server: RSocketServer) | ||
} | ||
|
||
|
||
@OptIn(RSocketTransportApi::class) | ||
internal fun Route.rSocketHandler(acceptor: ConnectionAcceptor): suspend DefaultWebSocketServerSession.() -> Unit { | ||
val config = application.attributes.getOrNull(RSocketSupportConfigKey) | ||
?: error("Plugin RSocketSupport is not installed. Consider using `install(RSocketSupport)` in server config first.") | ||
|
||
val handler = config.server.createHandler(acceptor) | ||
return { | ||
handler.handleKtorWebSocketConnection(this) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...lugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.ktor.server | ||
|
||
import io.ktor.server.routing.* | ||
import io.ktor.server.websocket.* | ||
import io.rsocket.kotlin.* | ||
|
||
public fun Route.rSocket(protocol: String? = null, acceptor: ConnectionAcceptor) { | ||
webSocket(protocol, rSocketHandler(acceptor)) | ||
} | ||
|
||
public fun Route.rSocket(path: String, protocol: String? = null, acceptor: ConnectionAcceptor) { | ||
webSocket(path, protocol, rSocketHandler(acceptor)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
ktor-plugins/rsocket-ktor-client/src/commonMain/kotlin/dummy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.deprecated | ||
|
||
private val dummy = 0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import rsocketbuild.* | ||
|
||
plugins { | ||
id("rsocketbuild.multiplatform-library") | ||
} | ||
|
||
description = "OLD ARTIFACT - migrate to ktor-server-rsocket" | ||
|
||
kotlin { | ||
jvmTarget() | ||
nixTargets() | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
implementation(projects.ktorServerRsocket) | ||
} | ||
} | ||
} |
Oops, something went wrong.