diff --git a/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.api b/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.api index 9cb449dd6b..e654f6f2ae 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.api +++ b/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.api @@ -12,7 +12,9 @@ public final class io/ktor/server/sse/SSEKt { } public final class io/ktor/server/sse/SSEServerContent : io/ktor/http/content/OutgoingContent$WriteChannelContent { + public fun (Lio/ktor/server/application/ApplicationCall;Lkotlin/jvm/functions/Function2;)V public fun (Lio/ktor/server/application/ApplicationCall;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V + public synthetic fun (Lio/ktor/server/application/ApplicationCall;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getCall ()Lio/ktor/server/application/ApplicationCall; public fun getContentType ()Lio/ktor/http/ContentType; public final fun getHandle ()Lkotlin/jvm/functions/Function2; @@ -41,3 +43,23 @@ public final class io/ktor/server/sse/SSESessionWithSerialization$DefaultImpls { public static fun send (Lio/ktor/server/sse/SSESessionWithSerialization;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } +public abstract interface class io/ktor/server/sse/ServerSSESession : kotlinx/coroutines/CoroutineScope { + public abstract fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun getCall ()Lio/ktor/server/application/ApplicationCall; + public abstract fun send (Lio/ktor/sse/ServerSentEvent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun send (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class io/ktor/server/sse/ServerSSESession$DefaultImpls { + public static fun send (Lio/ktor/server/sse/ServerSSESession;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun send$default (Lio/ktor/server/sse/ServerSSESession;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class io/ktor/server/sse/ServerSSESessionWithSerialization : io/ktor/server/sse/ServerSSESession { + public abstract fun getSerializer ()Lkotlin/jvm/functions/Function2; +} + +public final class io/ktor/server/sse/ServerSSESessionWithSerialization$DefaultImpls { + public static fun send (Lio/ktor/server/sse/ServerSSESessionWithSerialization;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + diff --git a/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.klib.api b/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.klib.api index 28237be108..88e8ef431e 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.klib.api +++ b/ktor-server/ktor-server-plugins/ktor-server-sse/api/ktor-server-sse.klib.api @@ -6,29 +6,30 @@ // - Show declarations: true // Library unique name: -abstract interface io.ktor.server.sse/SSESession : kotlinx.coroutines/CoroutineScope { // io.ktor.server.sse/SSESession|null[0] - abstract val call // io.ktor.server.sse/SSESession.call|{}call[0] - abstract fun (): io.ktor.server.application/ApplicationCall // io.ktor.server.sse/SSESession.call.|(){}[0] +abstract interface io.ktor.server.sse/ServerSSESession : kotlinx.coroutines/CoroutineScope { // io.ktor.server.sse/ServerSSESession|null[0] + abstract val call // io.ktor.server.sse/ServerSSESession.call|{}call[0] + abstract fun (): io.ktor.server.application/ApplicationCall // io.ktor.server.sse/ServerSSESession.call.|(){}[0] - abstract suspend fun close() // io.ktor.server.sse/SSESession.close|close(){}[0] - abstract suspend fun send(io.ktor.sse/ServerSentEvent) // io.ktor.server.sse/SSESession.send|send(io.ktor.sse.ServerSentEvent){}[0] - open suspend fun send(kotlin/String? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/Long? = ..., kotlin/String? = ...) // io.ktor.server.sse/SSESession.send|send(kotlin.String?;kotlin.String?;kotlin.String?;kotlin.Long?;kotlin.String?){}[0] + abstract suspend fun close() // io.ktor.server.sse/ServerSSESession.close|close(){}[0] + abstract suspend fun send(io.ktor.sse/ServerSentEvent) // io.ktor.server.sse/ServerSSESession.send|send(io.ktor.sse.ServerSentEvent){}[0] + open suspend fun send(kotlin/String? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/Long? = ..., kotlin/String? = ...) // io.ktor.server.sse/ServerSSESession.send|send(kotlin.String?;kotlin.String?;kotlin.String?;kotlin.Long?;kotlin.String?){}[0] } -abstract interface io.ktor.server.sse/SSESessionWithSerialization : io.ktor.server.sse/SSESession { // io.ktor.server.sse/SSESessionWithSerialization|null[0] - abstract val serializer // io.ktor.server.sse/SSESessionWithSerialization.serializer|{}serializer[0] - abstract fun (): kotlin/Function2 // io.ktor.server.sse/SSESessionWithSerialization.serializer.|(){}[0] +abstract interface io.ktor.server.sse/ServerSSESessionWithSerialization : io.ktor.server.sse/ServerSSESession { // io.ktor.server.sse/ServerSSESessionWithSerialization|null[0] + abstract val serializer // io.ktor.server.sse/ServerSSESessionWithSerialization.serializer|{}serializer[0] + abstract fun (): kotlin/Function2 // io.ktor.server.sse/ServerSSESessionWithSerialization.serializer.|(){}[0] } -final class <#A: io.ktor.server.sse/SSESession> io.ktor.server.sse/SSEServerContent : io.ktor.http.content/OutgoingContent.WriteChannelContent { // io.ktor.server.sse/SSEServerContent|null[0] - constructor (io.ktor.server.application/ApplicationCall, kotlin/Function2?, kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit>) // io.ktor.server.sse/SSEServerContent.|(io.ktor.server.application.ApplicationCall;kotlin.Function2?;kotlin.coroutines.SuspendFunction1<1:0,kotlin.Unit>){}[0] +final class io.ktor.server.sse/SSEServerContent : io.ktor.http.content/OutgoingContent.WriteChannelContent { // io.ktor.server.sse/SSEServerContent|null[0] + constructor (io.ktor.server.application/ApplicationCall, kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/SSEServerContent.|(io.ktor.server.application.ApplicationCall;kotlin.coroutines.SuspendFunction1){}[0] + constructor (io.ktor.server.application/ApplicationCall, kotlin.coroutines/SuspendFunction1, kotlin/Function2? = ...) // io.ktor.server.sse/SSEServerContent.|(io.ktor.server.application.ApplicationCall;kotlin.coroutines.SuspendFunction1;kotlin.Function2?){}[0] final val call // io.ktor.server.sse/SSEServerContent.call|{}call[0] final fun (): io.ktor.server.application/ApplicationCall // io.ktor.server.sse/SSEServerContent.call.|(){}[0] final val contentType // io.ktor.server.sse/SSEServerContent.contentType|{}contentType[0] final fun (): io.ktor.http/ContentType // io.ktor.server.sse/SSEServerContent.contentType.|(){}[0] final val handle // io.ktor.server.sse/SSEServerContent.handle|{}handle[0] - final fun (): kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit> // io.ktor.server.sse/SSEServerContent.handle.|(){}[0] + final fun (): kotlin.coroutines/SuspendFunction1 // io.ktor.server.sse/SSEServerContent.handle.|(){}[0] final val serialize // io.ktor.server.sse/SSEServerContent.serialize|{}serialize[0] final fun (): kotlin/Function2? // io.ktor.server.sse/SSEServerContent.serialize.|(){}[0] @@ -39,10 +40,10 @@ final class <#A: io.ktor.server.sse/SSESession> io.ktor.server.sse/SSEServerCont final val io.ktor.server.sse/SSE // io.ktor.server.sse/SSE|{}SSE[0] final fun (): io.ktor.server.application/ApplicationPlugin // io.ktor.server.sse/SSE.|(){}[0] -final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.coroutines.SuspendFunction1){}[0] -final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/Function2 = ..., kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.Function2;kotlin.coroutines.SuspendFunction1){}[0] -final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.String;kotlin.coroutines.SuspendFunction1){}[0] -final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, kotlin/Function2 = ..., kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.String;kotlin.Function2;kotlin.coroutines.SuspendFunction1){}[0] -final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/send(#A) // io.ktor.server.sse/send|send@io.ktor.server.sse.SSESessionWithSerialization(0:0){0§}[0] -final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/send(#A? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/Long? = ..., kotlin/String? = ...) // io.ktor.server.sse/send|send@io.ktor.server.sse.SSESessionWithSerialization(0:0?;kotlin.String?;kotlin.String?;kotlin.Long?;kotlin.String?){0§}[0] -final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/send(io.ktor.sse/TypedServerSentEvent<#A>) // io.ktor.server.sse/send|send@io.ktor.server.sse.SSESessionWithSerialization(io.ktor.sse.TypedServerSentEvent<0:0>){0§}[0] +final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.coroutines.SuspendFunction1){}[0] +final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/Function2 = ..., kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.Function2;kotlin.coroutines.SuspendFunction1){}[0] +final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.String;kotlin.coroutines.SuspendFunction1){}[0] +final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, kotlin/Function2 = ..., kotlin.coroutines/SuspendFunction1) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.String;kotlin.Function2;kotlin.coroutines.SuspendFunction1){}[0] +final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/ServerSSESessionWithSerialization).io.ktor.server.sse/send(#A) // io.ktor.server.sse/send|send@io.ktor.server.sse.ServerSSESessionWithSerialization(0:0){0§}[0] +final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/ServerSSESessionWithSerialization).io.ktor.server.sse/send(#A? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/Long? = ..., kotlin/String? = ...) // io.ktor.server.sse/send|send@io.ktor.server.sse.ServerSSESessionWithSerialization(0:0?;kotlin.String?;kotlin.String?;kotlin.Long?;kotlin.String?){0§}[0] +final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/ServerSSESessionWithSerialization).io.ktor.server.sse/send(io.ktor.sse/TypedServerSentEvent<#A>) // io.ktor.server.sse/send|send@io.ktor.server.sse.ServerSSESessionWithSerialization(io.ktor.sse.TypedServerSentEvent<0:0>){0§}[0] diff --git a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/DefaultServerSSESession.kt b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/DefaultServerSSESession.kt index 44975a8850..a0eeeb97ce 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/DefaultServerSSESession.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/DefaultServerSSESession.kt @@ -14,7 +14,7 @@ internal class DefaultServerSSESession( private val output: ByteWriteChannel, override val call: ApplicationCall, override val coroutineContext: CoroutineContext -) : SSESession { +) : ServerSSESession { private val mutex = Mutex() override suspend fun send(event: ServerSentEvent) { diff --git a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/Routing.kt b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/Routing.kt index be652cea11..b2b344bfc6 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/Routing.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/Routing.kt @@ -15,7 +15,7 @@ import io.ktor.util.reflect.* * * @param path A URL path at which to handle Server-Sent Events (SSE) requests. * @param handler A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE - * endpoint. Inside the handler, you can use the functions provided by [SSESessionWithSerialization] + * endpoint. Inside the handler, you can use the functions provided by [ServerSSESessionWithSerialization] * to send events to the connected clients. * * Example of usage: @@ -33,9 +33,9 @@ import io.ktor.util.reflect.* * To learn more, see [the SSE](https://en.wikipedia.org/wiki/Server-sent_events) * and [the SSE specification](https://html.spec.whatwg.org/multipage/server-sent-events.html). * - * @see SSESession + * @see ServerSSESession */ -public fun Route.sse(path: String, handler: suspend SSESession.() -> Unit) { +public fun Route.sse(path: String, handler: suspend ServerSSESession.() -> Unit) { route(path, HttpMethod.Get) { sse(handler) } @@ -46,7 +46,7 @@ public fun Route.sse(path: String, handler: suspend SSESession.() -> Unit) { * Requires [SSE] plugin to be installed. * * @param handler A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE - * endpoint. Inside the handler, you can use the functions provided by [SSESessionWithSerialization] + * endpoint. Inside the handler, you can use the functions provided by [ServerSSESessionWithSerialization] * to send events to the connected clients. * * Example of usage: @@ -64,9 +64,9 @@ public fun Route.sse(path: String, handler: suspend SSESession.() -> Unit) { * To learn more, see [the SSE](https://en.wikipedia.org/wiki/Server-sent_events) * and [the SSE specification](https://html.spec.whatwg.org/multipage/server-sent-events.html). * - * @see SSESession + * @see ServerSSESession */ -public fun Route.sse(handler: suspend SSESession.() -> Unit): Unit = processSSE(null, handler) +public fun Route.sse(handler: suspend ServerSSESession.() -> Unit): Unit = processSSEWithoutSerialization(null, handler) /** * Adds a route to handle Server-Sent Events (SSE) at the specified [path] using the provided [handler]. @@ -75,7 +75,7 @@ public fun Route.sse(handler: suspend SSESession.() -> Unit): Unit = processSSE( * @param path A URL path at which to handle Server-Sent Events (SSE) requests. * @param serialize A function to serialize data objects into the `data` field of a `ServerSentEvent`. * @param handler A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE - * endpoint. Inside the handler, you can use the functions provided by [SSESessionWithSerialization] + * endpoint. Inside the handler, you can use the functions provided by [ServerSSESessionWithSerialization] * to send events to the connected clients. * * Example of usage: @@ -95,12 +95,12 @@ public fun Route.sse(handler: suspend SSESession.() -> Unit): Unit = processSSE( * To learn more, see [the SSE](https://en.wikipedia.org/wiki/Server-sent_events) * and [the SSE specification](https://html.spec.whatwg.org/multipage/server-sent-events.html). * - * @see SSESessionWithSerialization + * @see ServerSSESessionWithSerialization */ public fun Route.sse( path: String, serialize: (TypeInfo, Any) -> String = { _, it -> it.toString() }, - handler: suspend SSESessionWithSerialization.() -> Unit + handler: suspend ServerSSESessionWithSerialization.() -> Unit ) { route(path, HttpMethod.Get) { sse(serialize, handler) @@ -113,7 +113,7 @@ public fun Route.sse( * * @param serialize A function to serialize data objects into the `data` field of a `ServerSentEvent`. * @param handler A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE - * endpoint. Inside the handler, you can use the functions provided by [SSESessionWithSerialization] + * endpoint. Inside the handler, you can use the functions provided by [ServerSSESessionWithSerialization] * to send events to the connected clients. * * Example of usage: @@ -133,16 +133,35 @@ public fun Route.sse( * To learn more, see [the SSE](https://en.wikipedia.org/wiki/Server-sent_events) * and [the SSE specification](https://html.spec.whatwg.org/multipage/server-sent-events.html). * - * @see SSESessionWithSerialization + * @see ServerSSESessionWithSerialization */ public fun Route.sse( serialize: (TypeInfo, Any) -> String = { _, it -> it.toString() }, - handler: suspend SSESessionWithSerialization.() -> Unit -): Unit = processSSE(serialize, handler) + handler: suspend ServerSSESessionWithSerialization.() -> Unit +): Unit = processSSEWithSerialization(serialize, handler) + +private fun Route.processSSEWithoutSerialization( + serialize: ((TypeInfo, Any) -> String)?, + handler: suspend ServerSSESession.() -> Unit +) = processSSE(serialize, handler) + +private fun Route.processSSEWithSerialization( + serialize: ((TypeInfo, Any) -> String)?, + handler: suspend ServerSSESessionWithSerialization.() -> Unit +) { + val sessionHandler: suspend ServerSSESession.() -> Unit = { + if (this is ServerSSESessionWithSerialization) { + handler() + } else { + throw IllegalStateException("ServerSSESessionWithSerialization is required.") + } + } + processSSE(serialize, sessionHandler) +} private fun Route.processSSE( serialize: ((TypeInfo, Any) -> String)?, - handler: suspend SSESessionWithSerialization.() -> Unit + handler: suspend ServerSSESession.() -> Unit ) { plugin(SSE) @@ -151,6 +170,6 @@ private fun Route.processSSE( call.response.header(HttpHeaders.CacheControl, "no-store") call.response.header(HttpHeaders.Connection, "keep-alive") call.response.header("X-Accel-Buffering", "no") - call.respond(SSEServerContent(call, serialize, handler)) + call.respond(SSEServerContent(call, handler, serialize)) } } diff --git a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/SSEServerContent.kt b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/SSEServerContent.kt index 36b51f28b9..0d260e95ce 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/SSEServerContent.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/SSEServerContent.kt @@ -24,24 +24,30 @@ import kotlinx.coroutines.* * @param call that is starting SSE session. * @param handle function that is started once SSE session created. */ -public class SSEServerContent( +public class SSEServerContent( public val call: ApplicationCall, - public val serialize: ((TypeInfo, Any) -> String)?, - public val handle: suspend T.() -> Unit + public val handle: suspend ServerSSESession.() -> Unit, + public val serialize: ((TypeInfo, Any) -> String)? = null ) : OutgoingContent.WriteChannelContent() { + public constructor( + call: ApplicationCall, + handle: suspend ServerSSESession.() -> Unit, + ) : this(call, handle, null) + override val contentType: ContentType = ContentType.Text.EventStream override suspend fun writeTo(channel: ByteWriteChannel) { LOGGER.trace("Starting sse session for ${call.request.uri}") - var session: T? = null + var session: ServerSSESession? = null try { coroutineScope { - session = DefaultServerSSESession(channel, call, coroutineContext) as T + session = DefaultServerSSESession(channel, call, coroutineContext) if (serialize != null) { - session = object : SSESessionWithSerialization, SSESession by session as DefaultServerSSESession { + session = object : ServerSSESessionWithSerialization, + ServerSSESession by session as DefaultServerSSESession { override val serializer: (TypeInfo, Any) -> String = serialize - } as T + } } session?.handle() } diff --git a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/SSESession.kt b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/ServerSSESession.kt similarity index 82% rename from ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/SSESession.kt rename to ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/ServerSSESession.kt index d48fc3d81b..4662798963 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/SSESession.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-sse/common/src/io/ktor/server/sse/ServerSSESession.kt @@ -12,7 +12,7 @@ import kotlinx.coroutines.* /** * Represents a server-side Server-Sent Events (SSE) session. - * An [SSESession] allows the server to send [ServerSentEvent] to the client over a single HTTP connection. + * An [ServerSSESession] allows the server to send [ServerSentEvent] to the client over a single HTTP connection. * * Example of usage: * ```kotlin @@ -31,7 +31,7 @@ import kotlinx.coroutines.* * * @see SSE */ -public interface SSESession : CoroutineScope { +public interface ServerSSESession : CoroutineScope { /** * The received [call] that originated this session. */ @@ -62,7 +62,7 @@ public interface SSESession : CoroutineScope { } /** - * Closes the [SSESession], terminating the connection with the client. + * Closes the [ServerSSESession], terminating the connection with the client. * Once this method is called, the SSE session is closed and no further events can be sent. * You don't need to call this method as it is called automatically when all the send operations are completed. * @@ -75,7 +75,7 @@ public interface SSESession : CoroutineScope { /** * Represents a server-side Server-Sent Events (SSE) session with serialization support. - * An [SSESessionWithSerialization] allows the server to send [ServerSentEvent] to the client over a single HTTP connection. + * An [ServerSSESessionWithSerialization] allows the server to send [ServerSentEvent] to the client over a single HTTP connection. * * Example of usage: * ```kotlin @@ -96,14 +96,14 @@ public interface SSESession : CoroutineScope { * * @see SSE */ -public interface SSESessionWithSerialization : SSESession { +public interface ServerSSESessionWithSerialization : ServerSSESession { /** * Serializer for transforming data object into field `data` of `ServerSentEvent`. */ public val serializer: (TypeInfo, Any) -> String } -public suspend inline fun SSESessionWithSerialization.send(event: TypedServerSentEvent) { +public suspend inline fun ServerSSESessionWithSerialization.send(event: TypedServerSentEvent) { send( ServerSentEvent( event.data?.let { @@ -117,7 +117,7 @@ public suspend inline fun SSESessionWithSerialization.send(eve ) } -public suspend inline fun SSESessionWithSerialization.send( +public suspend inline fun ServerSSESessionWithSerialization.send( data: T? = null, event: String? = null, id: String? = null, @@ -127,6 +127,6 @@ public suspend inline fun SSESessionWithSerialization.send( send(TypedServerSentEvent(data, event, id, retry, comments)) } -public suspend inline fun SSESessionWithSerialization.send(data: T) { +public suspend inline fun ServerSSESessionWithSerialization.send(data: T) { send(ServerSentEvent(serializer(typeInfo(), data))) }