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<discord4j.discordjson.json.gateway.Dispatch> |
dispatch()
Obtains the
Flux of Dispatch events inbound from the gateway connection made by this client. |
Mono<Void> |
execute(String gatewayUrl)
Establish a reconnecting gateway connection to the given URL.
|
Duration |
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.
|
int |
getShardCount()
Return number of shards this client operates under.
|
Mono<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<? extends 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) . |
Flux<GatewayConnection.State> |
stateEvents()
Return a sequence of the
GatewayConnection.State transitions this client receives. |
Mono<Void> execute(String gatewayUrl)
gatewayUrl
- the URL used to establish a websocket connectionMono
signaling completion of the session. If a non-recoverable error terminates the session,
it is emitted as an error through this Mono.Mono<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. If this client closed due
to an error it is emitted through the Mono.Flux<discord4j.discordjson.json.gateway.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
of Dispatch
valuesFlux<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<? extends 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 Monoint getShardCount()
String getSessionId()
int getSequence()
Flux<GatewayConnection.State> stateEvents()
GatewayConnection.State
transitions this client receives.Flux
of state elementsMono<Boolean> isConnected()
Mono
that upon subscription, returns true if the gateway connection is currently
established, false otherwise.Duration getResponseTime()