Package discord4j.voice
Class VoiceWebsocketHandler
- java.lang.Object
-
- discord4j.voice.VoiceWebsocketHandler
-
public class VoiceWebsocketHandler extends Object
Represents a WebSocket handler specialized for Discord voice gateway operations.Capable of handling closing events that normally occur in its lifecycle.
This handler uses a
FluxSink
ofByteBuf
to push inbound payloads and aFlux
ofByteBuf
to pull outbound payloads.The handler also provides methods to control the lifecycle, which perform operations on the current session. It is required to use them to properly release important resources and complete the session.
-
-
Constructor Summary
Constructors Constructor Description VoiceWebsocketHandler(Sinks.Many<ByteBuf> inbound, Flux<ByteBuf> outbound, ContextView context)
Create a new handler with the given data pipelines.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Initiates a close sequence that will terminate this session and instruct consumers downstream that a reconnect should take place afterwards.void
close(DisconnectBehavior behavior)
Initiates a close sequence that will terminate this session and then execute a givenDisconnectBehavior
.void
error(Throwable error)
Initiates a close sequence with the given error.Mono<Tuple2<DisconnectBehavior,CloseStatus>>
handle(WebsocketInbound in, WebsocketOutbound out)
Handle an upgraded websocket connection, given by bothWebsocketInbound
andWebsocketOutbound
to manage a session until the remote closes or one of the local methodsclose()
orerror(Throwable)
methods are called.
-
-
-
Constructor Detail
-
VoiceWebsocketHandler
public VoiceWebsocketHandler(Sinks.Many<ByteBuf> inbound, Flux<ByteBuf> outbound, ContextView context)
Create a new handler with the given data pipelines.- Parameters:
inbound
- theSinks.Many
ofByteBuf
to process inbound payloadsoutbound
- theFlux
ofByteBuf
to process outbound payloadscontext
- the ReactorContextView
that owns this handler, to enrich logging
-
-
Method Detail
-
handle
public Mono<Tuple2<DisconnectBehavior,CloseStatus>> handle(WebsocketInbound in, WebsocketOutbound out)
Handle an upgraded websocket connection, given by bothWebsocketInbound
andWebsocketOutbound
to manage a session until the remote closes or one of the local methodsclose()
orerror(Throwable)
methods are called. When that happens, a close procedure will take place and ultimately emit a pair ofDisconnectBehavior
and remoteCloseStatus
, if present or "-1" if none is present.- Parameters:
in
- the websocket inboundout
- the websocket outbound- Returns:
- a
Mono
that upon subscription, manages a websocket session until it closes where aTuple2
is emitted representing both theDisconnectBehavior
that initiated the close procedure, and the inboundCloseStatus
.
-
close
public void close()
Initiates a close sequence that will terminate this session and instruct consumers downstream that a reconnect should take place afterwards.
-
close
public void close(DisconnectBehavior behavior)
Initiates a close sequence that will terminate this session and then execute a givenDisconnectBehavior
.- Parameters:
behavior
- theDisconnectBehavior
to follow after the close sequence starts
-
error
public void error(Throwable error)
Initiates a close sequence with the given error. The session will be terminated abruptly and then instruct consumers downstream that a reconnect should take place afterwards.- Parameters:
error
- the cause for this session termination
-
-