Interface GatewayClient

    • Method Detail

      • execute

        Mono<Void> execute​(String gatewayUrl)
        Establish a reconnecting gateway connection to the given URL.
        Parameters:
        gatewayUrl - the URL used to establish a websocket connection
        Returns:
        a Mono signaling completion of the session. If a non-recoverable error terminates the session, it is emitted as an error through this Mono.
      • close

        Mono<CloseStatus> close​(boolean allowResume)
        Terminates this client's current gateway connection.
        Parameters:
        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.
        Returns:
        a Mono deferring completion until the disconnection has completed. If this client closed due to an error it is emitted through the Mono. If available, a CloseStatus will be present.
      • dispatch

        Flux<discord4j.discordjson.json.gateway.Dispatch> dispatch()
        Obtains the 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());
         });
         
        Returns:
        a Flux of Dispatch values
      • receiver

        <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.
        Type Parameters:
        T - the type of the resulting inbound Flux
        Parameters:
        mapper - a mapping function turning raw ByteBuf objects into a given type
        Returns:
        a Flux of raw payloads transformed by a mapping function
      • send

        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.
        Parameters:
        publisher - a sequence of outbound payloads
        Returns:
        a Mono completing when payloads have been sent
      • sendBuffer

        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.

        Sequences produced this way are not expected to be validated against errors or invalid input by the underlying implementation.

        Parameters:
        publisher - a sequence of outbound payloads
        Returns:
        a Mono signaling completion, if an error occurs while producing it is emitted through the Mono
      • getShardCount

        int getShardCount()
        Return number of shards this client operates under.
        Returns:
        a positive integer representing the number of shards
      • getSessionId

        String getSessionId()
        Retrieve the ID of the current gateway session.
        Returns:
        the ID of the current gateway session. Used for resuming and voice.
      • getSequence

        int getSequence()
        Gets the current heartbeat sequence.
        Returns:
        an integer representing the current gateway sequence
      • isConnected

        Mono<Boolean> isConnected()
        Returns whether this GatewayClient is currently connected to Discord Gateway therefore capable to send and receive payloads.
        Returns:
        a Mono that upon subscription, returns true if the gateway connection is currently established, false otherwise.
      • getResponseTime

        Duration getResponseTime()
        Gets the amount of time it last took Discord to respond to a heartbeat with an ack.
        Returns:
        the duration which Discord took to respond to the last heartbeat with an ack.