\App\IqrfNetModule\ModelsWebSocketClient

WebSocket client

Summary

Methods
Properties
Constants
__construct()
sendSync()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
createConnection()
stopSync()
receiveSync()
checkMessage()
parseResponse()
$loop
$serverUrl
N/A

Properties

$loop

$loop : \React\EventLoop\LoopInterface

Type

\React\EventLoop\LoopInterface — Event loop

$serverUrl

$serverUrl : string

Type

normal — URL to IQRF Gateway Daemon's WebSocket server

Methods

__construct()

__construct(string  $url) : mixed

Constructor

Parameters

string $url

URL to IQRF Gateway Daemon's WebSocket server

Returns

mixed

sendSync()

sendSync(\App\IqrfNetModule\Requests\ApiRequest  $request, bool  $checkStatus = true, int  $timeout = 13) : array

Sends IQRF JSON API request

Parameters

\App\IqrfNetModule\Requests\ApiRequest $request

IQRF JSON API request

bool $checkStatus

Check response status

int $timeout

WebSocket client timeout

Throws

\App\IqrfNetModule\Exceptions\DpaErrorException
\App\IqrfNetModule\Exceptions\EmptyResponseException
\Nette\Utils\JsonException
\App\IqrfNetModule\Exceptions\UserErrorException

Returns

array —

IQRF JSON API response

createConnection()

createConnection(int  $timeout) : \React\Promise\PromiseInterface

Creates a connection to WebSocket server

Parameters

int $timeout

WebSocket client timeout

Returns

\React\Promise\PromiseInterface —

React promise

stopSync()

stopSync(bool  $wait) : void

Stops event loop

Parameters

bool $wait

Wait to finish

receiveSync()

receiveSync(\Ratchet\Client\WebSocket  $connection, \Ratchet\RFC6455\Messaging\MessageInterface  $message, \Ratchet\RFC6455\Messaging\MessageInterface|null  $resolved, bool  $wait, int  $attempts, \App\IqrfNetModule\Requests\ApiRequest  $request) : void

Receives a message from WebSocket server

Parameters

\Ratchet\Client\WebSocket $connection

WebSocket client connection

\Ratchet\RFC6455\Messaging\MessageInterface $message

Received message

\Ratchet\RFC6455\Messaging\MessageInterface|null $resolved

Stored receive message

bool $wait

Wait to finish

int $attempts

Attempts to receive

\App\IqrfNetModule\Requests\ApiRequest $request

IQRF JSON API request

Throws

\Nette\Utils\JsonException

checkMessage()

checkMessage(\App\IqrfNetModule\Requests\ApiRequest  $request, \Ratchet\RFC6455\Messaging\MessageInterface  $response) : bool

Checks if JSON DPA request and response have got the same message ID

Parameters

\App\IqrfNetModule\Requests\ApiRequest $request

JSON DPA request

\Ratchet\RFC6455\Messaging\MessageInterface $response

JSON DPA request

Throws

\Nette\Utils\JsonException

Returns

bool —

Have JSON DPA request and response got the same message ID

parseResponse()

parseResponse(\App\IqrfNetModule\Requests\ApiRequest  $request, \Ratchet\RFC6455\Messaging\MessageInterface|null  $response, bool  $checkStatus) : array

Parses IQRF JSON API request and response

Parameters

\App\IqrfNetModule\Requests\ApiRequest $request

JSON DPA request

\Ratchet\RFC6455\Messaging\MessageInterface|null $response

IQRF JSON API response

bool $checkStatus

Check response status

Throws

\App\IqrfNetModule\Exceptions\EmptyResponseException
\App\IqrfNetModule\Exceptions\DpaErrorException
\App\IqrfNetModule\Exceptions\UserErrorException

Returns

array —

IQRF JSON API response in an array