Connection

Satori RTM Connection.

Access the RTM Service on the connection level to connect to the RTM Service, send and receive PDUs Uses WebSocket client to connect to RTM.

Does not handle any possible exceptions from the WS client.

package

Default

Methods

Creates \Rtm\Connection instance.

__construct(string $endpoint, array $options = array()) 
Throws
\RtmClient\WebSocket\Exceptions\BadSchemeException

when endpoint schema is not starting from https://, http://, ws://, wss://

\RtmClient\WebSocket\Exceptions\ConnectionException

when connection is broken, unable to connect or send/read from the connection

Arguments

$endpoint

string

$options

array

Connection instance options

$options = [
  'logger' => (\Psr\Log\LoggerInterface Custom logger
]

Closes connection.

close(integer $status = 1000, string $reason = 'Connection closed') : true

Arguments

$status

integer

Close status code

$reason

string

Any message that will be send in close frame. All unprocessed callbacks will get this reason.

Response

true

if websocket connection has been closed

Closes awating callbacks.

closeCallbacks(string $reason) : void

Sends "disconnected" error to all callbacks that await for the response from Satori RTM.

Arguments

$reason

string

Disconnect reason

Starts connection to the endpoint.

connect() : true
Throws
\RtmClient\WebSocket\Exceptions\ConnectionException

when connection is broken, unable to connect or send/read from the connection

Response

true

Checks if the connection is persistent and was reused.

isReusedPersistentConnection() : boolean

Response

boolean

true if the connection is persistent and was reused. false otherwise

Generates next ID for PDU.

nextId() : integer

Response

integer

Next id

Reads data from the connection and converts to PDU.

read(integer $mode, integer $timeout_sec, integer $timeout_microsec) : array
Throws
\Exception

possible exceptions from user callbacks

\RtmClient\WebSocket\Exceptions\ConnectionException

when connection is broken, unable to read from the connection

\RtmClient\ApplicationException

if failed to parse incoming json string

\RtmClient\ApplicationException

if missing "action" or "body" field in received PDU

Arguments

$mode

integer

\Rtm\WebSocket\Client::SYNC_READ or \Rtm\WebSocket\Client::ASYNC_READ

$timeout_sec

integer

The seconds part of the timeout to be set

$timeout_microsec

integer

The microseconds part of the timeout to be set

Response

array

Combined \Rtm\WebSocket\ReturnCode and Rtm\Pdu\Pdu

Forms and sends PDU using websocket connection.

send(string $action, array $body, callable $callback = null) : \RtmClient\always
Throws
\RtmClient\WebSocket\Exceptions\ConnectionException

when connection is broken, unable to connect or send/read from the connection

Arguments

$action

string

PDU action

$body

array

PDU body

$callback

callable

callback to be called when getting back request confirmation from RTM

Response

\RtmClient\always

true

Sends PING to server: https://tools.ietf.org/html/rfc6455#section-5.5.2

sendPing(string $text = 'ping') : true

Arguments

$text

string

Text to be send as ping payload

Response

true

if sent

Waits for all ack responses from Satori RTM.

waitAllReplies(integer $timeout_sec, integer $timeout_microsec) : void
Throws
\RtmClient\WebSocket\Exceptions\ConnectionException

when connection is broken, unable to connect or send/read from the connection

\RtmClient\ApplicationException

if failed to parse incoming json string

\RtmClient\ApplicationException

if missing "action" or "body" field in received PDU

Arguments

$timeout_sec

integer

The seconds part of the maximal awaiting time to be set

$timeout_microsec

integer

The microseconds part of the maximal awaiting time to be set

Properties

Connection endpoint

endpoint : string
var

Type(s)

string

Internal ID. Used to mark PDU requests

last_id : integer
var

Type(s)

integer

WS client instance

ws : \Rtm\WebSocket\Client
var

Type(s)

\Rtm\WebSocket\Client

List of callbacks. Callback will be executed when getting PDU with ID matched to the callback

callbacks : array
var

Type(s)

array