public interface GatewayClient
Allows consumers to receive inbound events through dispatch()
and direct raw payloads through
receiver()
and allows a producer to submit events through send(Publisher)
and sender()
.
Additionally, supports low-level ByteBuf
based communication through receiver(Function)
and
sendBuffer(Publisher)
.
Modifier and Type | Method and Description |
---|---|
Mono<Void> |
close(boolean allowResume)
Terminates this client's current gateway connection.
|
Flux<Dispatch> |
dispatch()
|
Mono<Void> |
execute(String gatewayUrl)
Establish a reconnecting gateway connection to the given URL.
|
Mono<Void> |
execute(String gatewayUrl,
GatewayObserver additionalObserver)
Establish a reconnecting gateway connection to the given URL, allowing an ad-hoc observer to be notified.
|
long |
getResponseTime()
Gets the amount of time it last took Discord to respond to a heartbeat with an ack.
|
int |
getSequence()
Gets the current heartbeat sequence.
|
String |
getSessionId()
Retrieve the ID of the current gateway session.
|
boolean |
isConnected()
Returns whether this GatewayClient is currently connected to Discord Gateway therefore capable to send and
receive payloads.
|
Flux<GatewayPayload<?>> |
receiver()
Obtains the
Flux of raw payloads inbound from the gateway connection made by this client. |
<T> Flux<T> |
receiver(Function<ByteBuf,Publisher<? extends T>> mapper)
Obtains a
Flux of raw payloads inbound from the gateway connection made by this client, transformed by a
mapping function. |
default Mono<Void> |
send(Publisher<GatewayPayload<?>> publisher)
Sends a sequence of
payloads through this GatewayClient and returns a
Mono that signals completion when the payloads have been sent. |
Mono<Void> |
sendBuffer(Publisher<ByteBuf> publisher)
Sends a sequence of
ByteBuf payloads through this GatewayClient and returns a Mono
that signals completion when the given publisher completes. |
FluxSink<GatewayPayload<?>> |
sender()
Retrieves a new
FluxSink to safely produce outbound values using FluxSink.next(Object) . |
Mono<Void> execute(String gatewayUrl)
gatewayUrl
- the URL used to establish a websocket connectionMono
signaling completionMono<Void> execute(String gatewayUrl, GatewayObserver additionalObserver)
gatewayUrl
- the URL used to establish a websocket connectionadditionalObserver
- an additional observer to be notified of eventsMono
signaling completionMono<Void> close(boolean allowResume)
allowResume
- if resuming this session after closing is possible. if set to true
the main
execution Mono
will complete with a PartialDisconnectException
you can
use to perform additional behavior or reconnect.Mono
deferring completion until the disconnection has completed.Flux<Dispatch> dispatch()
Flux
of Dispatch
events inbound from the gateway connection made by this client.
Can be used like this, for example, to get all created message events:
gatewayClient.dispatch().ofType(MessageCreate.class) .subscribe(message -> { System.out.println("Got a message with content: " + message.getMessage().getContent()); });
Flux<GatewayPayload<?>> receiver()
Flux
of raw payloads inbound from the gateway connection made by this client.Flux
of GatewayPayload
values<T> Flux<T> receiver(Function<ByteBuf,Publisher<? extends T>> mapper)
Flux
of raw payloads inbound from the gateway connection made by this client, transformed by a
mapping function.FluxSink<GatewayPayload<?>> sender()
FluxSink
to safely produce outbound values using FluxSink.next(Object)
.FluxSink
default Mono<Void> send(Publisher<GatewayPayload<?>> publisher)
payloads
through this GatewayClient
and returns a
Mono
that signals completion when the payloads have been sent.publisher
- a sequence of outbound payloadsMono
completing when payloads have been sentMono<Void> sendBuffer(Publisher<ByteBuf> publisher)
ByteBuf
payloads through this GatewayClient
and returns a Mono
that signals completion when the given publisher completes.
Sequences produced this way are not expected to be validated against errors or invalid input by the underlying implementation.
publisher
- a sequence of outbound payloadsMono
signaling completion, if an error occurs while producing it is emitted through the MonoString getSessionId()
int getSequence()
boolean isConnected()
long getResponseTime()