Package ratpack.core.websocket
Class WebSockets
- java.lang.Object
-
- ratpack.core.websocket.WebSockets
-
public abstract class WebSockets extends Object
WebSockets support for Ratpack.An example that broadcasts strings to a websocket every second:
import org.reactivestreams.Publisher; import ratpack.test.embed.EmbeddedApp; import ratpack.core.websocket.WebSockets; import java.time.Duration; import static ratpack.exec.stream.Streams.periodically; chain.get("whatever", context -> { Publisher<String> stream = periodically(context, Duration.ofSeconds(1), i -> i < 5 ? i.toString() : null ); WebSockets.websocketBroadcast(context, stream); });
- See Also:
- Writing WebSocket client applications
-
-
Constructor Summary
Constructors Constructor Description WebSockets()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
websocket(Context context, WebSocketHandler<?> handler)
static <T> WebSocketConnector<T>
websocket(Context context, Function<WebSocket,T> openAction)
static void
websocketBroadcast(Context context, Publisher<String> broadcaster)
Sets up a websocket that sends the published Strings to a client.static void
websocketByteBufBroadcast(Context context, Publisher<io.netty.buffer.ByteBuf> broadcaster)
Sets up a websocket that sends the published byte buffers to a client.
-
-
-
Method Detail
-
websocket
public static <T> WebSocketConnector<T> websocket(Context context, Function<WebSocket,T> openAction)
-
websocket
public static void websocket(Context context, WebSocketHandler<?> handler)
-
websocketBroadcast
public static void websocketBroadcast(Context context, Publisher<String> broadcaster)
Sets up a websocket that sends the published Strings to a client.This takes the place of a
Streams.bindExec(Publisher)
call.- Parameters:
context
- the request handling contextbroadcaster
- aPublisher
of Strings to send to the websocket client
-
websocketByteBufBroadcast
public static void websocketByteBufBroadcast(Context context, Publisher<io.netty.buffer.ByteBuf> broadcaster)
Sets up a websocket that sends the published byte buffers to a client.This takes the place of a
Streams.bindExec(Publisher)
call.- Parameters:
context
- the request handling contextbroadcaster
- aPublisher
ofByteBuf
s to send to the websocket client
-
-