All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.lightningserver.websocket.dsl.kt Maven / Gradle / Ivy

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
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy