class WSConnection implements EventEmitterInterface (View source)

Handles the WS connection.

Traits

EventEmitterTrait

Properties

WSManager $wsmanager
int $shardID
protected WebSocket $ws
protected WSCompressionInterface $compressContext
array $ratelimits The WS ratelimits.
TimerInterface $heartbeat
array $wsHeartbeat The WS heartbeat.
protected bool $authenticated The WS authentication state.
protected array $queue The WS queue.
protected bool $running The WS queue processing status.
protected bool $expectedClose If the connection gets closed, did we expect it?
protected bool $previous Whether we should use the previous sequence for RESUME (for after compress context failure).
bool $ready
protected int $lastPacketTime The timestamp of when we received the last event.
protected mixed|null $previousSequence The previous sequence.
protected mixed $sequence The sequence.
int[] $pings
protected array $wsCloseCodes WS close codes, sorted by resumable session and ends everything.
int $status
protected string|null $wsSessionID The Discord Session ID.
WSEncodingInterface $encoding

Methods

__construct(WSManager $wsmanager, int $shardID, string $compression)

DO NOT initialize this class yourself.

bool
__isset(string $name)

No description

mixed
__get(string $name)

No description

void
destroy()

Disconnects.

ExtendedPromiseInterface
connect(bool $reconnect = false)

Connects to the gateway url. Resolves with $this.

void
disconnect(int $code = 1000, string $reason = '')

Closes the WS connection.

void
reconnect(bool $resumable = true)

Closes the WS connection.

ExtendedPromiseInterface
renewConnection(bool $forceNewGateway = true)

Closes the WS connection.

ExtendedPromiseInterface
send(array $packet)

No description

void
processQueue()

Processes the WS queue.

void
setAuthenticated(bool $state)

Set authenticated.

string|null
getSessionID()

Get the session ID.

void
setSessionID(string|null $id)

Set the session ID.

void
setSequence($sequence)

Sets the sequence.

void
sendIdentify()

Sends an IDENTIFY or RESUME payload, depending on ws session ID.

void
heartbeat()

Sends a heartbeat.

void
heartFailure()

Handles heart failures.

void
_pong($end)

Handles heartbeat ack.

void
_send(array $packet)

Direct ws send method. DO NOT USE.

void
initWS(WebSocket $conn, bool $ready, bool $reconnect, Deferred $deferred)

Initializes the websocet.

initWSSelfReady(bool $ready, bool $reconnect, Deferred $deferred)

Returns the handler for self.ready event.

initWSSelfError(bool $ready, Deferred $deferred)

Returns the handler for self.error event.

initWSMessage(bool $ready, Deferred $deferred)

Returns the handler for message event.

initWSError(bool $ready, Deferred $deferred)

Returns the handler for error event.

initWSClose(Deferred $deferred)

Returns the handler for close event.

Details

__construct(WSManager $wsmanager, int $shardID, string $compression)

DO NOT initialize this class yourself.

Parameters

WSManager $wsmanager
int $shardID
string $compression

bool __isset(string $name)

Parameters

string $name

Return Value

bool

Exceptions

Exception

mixed __get(string $name)

Parameters

string $name

Return Value

mixed

Exceptions

RuntimeException

void destroy()

Disconnects.

Return Value

void

ExtendedPromiseInterface connect(bool $reconnect = false)

Connects to the gateway url. Resolves with $this.

Parameters

bool $reconnect

Return Value

ExtendedPromiseInterface

Exceptions

RuntimeException

void disconnect(int $code = 1000, string $reason = '')

Closes the WS connection.

Parameters

int $code
string $reason

Return Value

void

void reconnect(bool $resumable = true)

Closes the WS connection.

Parameters

bool $resumable

Return Value

void

protected ExtendedPromiseInterface renewConnection(bool $forceNewGateway = true)

Closes the WS connection.

Parameters

bool $forceNewGateway

Return Value

ExtendedPromiseInterface

ExtendedPromiseInterface send(array $packet)

Parameters

array $packet

Return Value

ExtendedPromiseInterface

Exceptions

RuntimeException

void processQueue()

Processes the WS queue.

Return Value

void

void setAuthenticated(bool $state)

Set authenticated.

Parameters

bool $state

Return Value

void

string|null getSessionID()

Get the session ID.

Return Value

string|null

void setSessionID(string|null $id)

Set the session ID.

Parameters

string|null $id

Return Value

void

void setSequence($sequence)

Sets the sequence.

Parameters

$sequence

Return Value

void

void sendIdentify()

Sends an IDENTIFY or RESUME payload, depending on ws session ID.

Return Value

void

void heartbeat()

Sends a heartbeat.

Return Value

void

void heartFailure()

Handles heart failures.

Return Value

void

void _pong($end)

Handles heartbeat ack.

Parameters

$end

Return Value

void

void _send(array $packet)

Direct ws send method. DO NOT USE.

Parameters

array $packet

Return Value

void

protected void initWS(WebSocket $conn, bool $ready, bool $reconnect, Deferred $deferred)

Initializes the websocet.

Parameters

WebSocket $conn
bool $ready
bool $reconnect
Deferred $deferred

Return Value

void

protected Closure initWSSelfReady(bool $ready, bool $reconnect, Deferred $deferred)

Returns the handler for self.ready event.

Parameters

bool $ready
bool $reconnect
Deferred $deferred

Return Value

Closure

protected Closure initWSSelfError(bool $ready, Deferred $deferred)

Returns the handler for self.error event.

Parameters

bool $ready
Deferred $deferred

Return Value

Closure

protected Closure initWSMessage(bool $ready, Deferred $deferred)

Returns the handler for message event.

Parameters

bool $ready
Deferred $deferred

Return Value

Closure

protected Closure initWSError(bool $ready, Deferred $deferred)

Returns the handler for error event.

Parameters

bool $ready
Deferred $deferred

Return Value

Closure

protected Closure initWSClose(Deferred $deferred)

Returns the handler for close event.

Parameters

Deferred $deferred

Return Value

Closure