From 2dc9a6d7333c4b829f2dc4ab5f8c342dfd240cd0 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 11 Oct 2017 21:18:15 -0400 Subject: [PATCH 1/3] Preparation for 0.3 Fix some API documentation Mark versions as 0.3 Use latest RFC6455 lib Update example with latest connector options --- README.md | 6 +++++- composer.json | 2 +- src/Connector.php | 6 ++++-- src/WebSocket.php | 2 +- src/functions.php | 2 +- tests/autobahn/runner.php | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b6fb196..acf2e20 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,11 @@ A more in-depth example using explicit interfaces: Requesting sub-protocols, and require __DIR__ . '/vendor/autoload.php'; $loop = React\EventLoop\Factory::create(); - $connector = new Ratchet\Client\Connector($loop); + $reactConnector = new React\Socket\Connector($loop, [ + 'dns' => '8.8.8.8', + 'timeout' => 10 + ]); + $connector = new Ratchet\Client\Connector($loop, $reactConnector); $connector('ws://127.0.0.1:9000', ['protocol1', 'subprotocol2'], ['Origin' => 'http://localhost']) ->then(function(Ratchet\Client\WebSocket $conn) { diff --git a/composer.json b/composer.json index a2b0c34..a7c98de 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": ">=5.4" , "react/socket": "^1.0 || ^0.8 || ^0.7" , "evenement/evenement": "^3.0 || ^2.0" - , "ratchet/rfc6455": "^0.2.2" + , "ratchet/rfc6455": "^0.2.3" } , "require-dev": { "phpunit/phpunit": "~4.8" diff --git a/src/Connector.php b/src/Connector.php index 7936705..65bd80b 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -6,6 +6,7 @@ use React\Socket\ConnectorInterface; use React\Promise\Deferred; use React\Promise\RejectedPromise; +use Psr\Http\Message\RequestInterface; use GuzzleHttp\Psr7 as gPsr; class Connector { @@ -104,6 +105,7 @@ public function __invoke($url, array $subProtocols = [], array $headers = []) { * @param string $url * @param array $subProtocols * @param array $headers + * @throws \InvalidArgumentException * @return \Psr\Http\Message\RequestInterface */ protected function generateRequest($url, array $subProtocols, array $headers) { @@ -121,9 +123,9 @@ protected function generateRequest($url, array $subProtocols, array $headers) { $uri = $uri->withPort('wss' === $scheme ? 443 : 80); } - $headers += ['User-Agent' => 'Ratchet-Pawl/0.2.3']; + $headers += ['User-Agent' => 'Ratchet-Pawl/0.3']; - $request = array_reduce(array_keys($headers), function($request, $header) use ($headers) { + $request = array_reduce(array_keys($headers), function(RequestInterface $request, $header) use ($headers) { return $request->withHeader($header, $headers[$header]); }, $this->_negotiator->generateRequest($uri)); diff --git a/src/WebSocket.php b/src/WebSocket.php index a09c4e8..fccc8a3 100644 --- a/src/WebSocket.php +++ b/src/WebSocket.php @@ -27,7 +27,7 @@ class WebSocket implements EventEmitterInterface { public $response; /** - * @var \React\Stream\Stream + * @var \React\Stream\DuplexStreamInterface */ protected $_stream; diff --git a/src/functions.php b/src/functions.php index 3a094fb..c7adb6c 100644 --- a/src/functions.php +++ b/src/functions.php @@ -8,7 +8,7 @@ * @param array $subProtocols * @param array $headers * @param LoopInterface|null $loop - * @return \React\Promise\PromiseInterface + * @return \React\Promise\PromiseInterface<\Ratchet\Client\WebSocket> */ function connect($url, array $subProtocols = [], $headers = [], LoopInterface $loop = null) { $loop = $loop ?: ReactFactory::create(); diff --git a/tests/autobahn/runner.php b/tests/autobahn/runner.php index bd06752..897a670 100644 --- a/tests/autobahn/runner.php +++ b/tests/autobahn/runner.php @@ -4,7 +4,7 @@ require __DIR__ . '/../../vendor/autoload.php'; - define('AGENT', 'Pawl/0.2.3'); + define('AGENT', 'Pawl/0.3'); $loop = React\EventLoop\Factory::create(); From d2c3e0622a1980f281bc7984a18766b2a1a65d04 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 11 Oct 2017 21:46:46 -0400 Subject: [PATCH 2/3] Further update API docs, remove unneeded code --- src/WebSocket.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/WebSocket.php b/src/WebSocket.php index fccc8a3..bf0ebc8 100644 --- a/src/WebSocket.php +++ b/src/WebSocket.php @@ -2,7 +2,7 @@ namespace Ratchet\Client; use Evenement\EventEmitterTrait; use Evenement\EventEmitterInterface; -use React\Stream\DuplexStreamInterface; +use React\Socket\ConnectionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Ratchet\RFC6455\Messaging\MessageBuffer; @@ -27,7 +27,7 @@ class WebSocket implements EventEmitterInterface { public $response; /** - * @var \React\Stream\DuplexStreamInterface + * @var \React\Socket\ConnectionInterface */ protected $_stream; @@ -38,7 +38,7 @@ class WebSocket implements EventEmitterInterface { /** * WebSocket constructor. - * @param \React\Stream\DuplexStreamInterface $stream + * @param \React\Socket\ConnectionInterface $stream * @param \Psr\Http\Message\ResponseInterface $response * @param \Psr\Http\Message\RequestInterface $request * @event message @@ -46,7 +46,7 @@ class WebSocket implements EventEmitterInterface { * @event close * @event error */ - public function __construct(DuplexStreamInterface $stream, ResponseInterface $response, RequestInterface $request) { + public function __construct(ConnectionInterface $stream, ResponseInterface $response, RequestInterface $request) { $this->_stream = $stream; $this->response = $response; $this->request = $request; @@ -103,13 +103,6 @@ function() use ($reusableUAException) { $stream->on('data', [$streamer, 'onData']); - $stream->on('end', function(DuplexStreamInterface $stream) { - if (is_resource($stream->stream)) { - stream_socket_shutdown($stream->stream, STREAM_SHUT_RDWR); - stream_set_blocking($stream->stream, false); - } - }); - $stream->on('close', function () { $close = $this->_close; $close(Frame::CLOSE_ABNORMAL, 'Underlying connection closed'); From 5b8934fefaee4e6ccc2e39f822d3dd6c7841ffa1 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 11 Oct 2017 21:52:14 -0400 Subject: [PATCH 3/3] Add TravisCI badge to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index acf2e20..caf83ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Pawl [![Autobahn Testsuite](https://img.shields.io/badge/Autobahn-passing-brightgreen.svg)](http://socketo.me/reports/pawl/index.html) +[![Build Status](https://travis-ci.org/ratchetphp/Pawl.svg?branch=master)](https://travis-ci.org/ratchetphp/Pawl) An asynchronous WebSocket client in PHP