Skip to content

Commit

Permalink
Merge branch '0.3-prep'
Browse files Browse the repository at this point in the history
  • Loading branch information
cboden committed Oct 12, 2017
2 parents 7a4c92c + 5b8934f commit b86d04e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -59,7 +60,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) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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));

Expand Down
15 changes: 4 additions & 11 deletions src/WebSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +27,7 @@ class WebSocket implements EventEmitterInterface {
public $response;

/**
* @var \React\Stream\Stream
* @var \React\Socket\ConnectionInterface
*/
protected $_stream;

Expand All @@ -38,15 +38,15 @@ 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
* @event pong
* @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;
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/autobahn/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit b86d04e

Please sign in to comment.