com.lightningkite.lightningserver.websocket.dsl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server-core Show documentation
Show all versions of server-core Show documentation
A set of tools to fill in/replace what Ktor is lacking in.
The newest version!
package com.lightningkite.lightningserver.websocket
import com.lightningkite.lightningserver.core.LightningServerDsl
import com.lightningkite.lightningserver.core.ServerPath
@LightningServerDsl
fun ServerPath.websocket(
connect: suspend (WebSockets.ConnectEvent) -> Unit = { },
message: suspend (WebSockets.MessageEvent) -> Unit = { },
disconnect: suspend (WebSockets.DisconnectEvent) -> Unit = {}
): ServerPath {
WebSockets.handlers[this] = object : WebSockets.Handler {
override suspend fun connect(event: WebSockets.ConnectEvent) = connect(event)
override suspend fun message(event: WebSockets.MessageEvent) = message(event)
override suspend fun disconnect(event: WebSockets.DisconnectEvent) = disconnect(event)
}
return this
}
@LightningServerDsl
fun ServerPath.websocket(
handler: WebSockets.Handler
): ServerPath {
WebSockets.handlers[this] = handler
return this
}