diff --git a/composer.json b/composer.json index 17b68c8..46d59ef 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ } ], "require": { - "ratchet/rfc6455": "^0.3", + "guzzlehttp/psr7": "^1.7 || ^2.0", + "ratchet/rfc6455": "^0.3 || ^0.4", "react/http": "^1.0" }, "require-dev":{ diff --git a/src/WebSocketMiddleware.php b/src/WebSocketMiddleware.php index 1880b88..e925f7e 100644 --- a/src/WebSocketMiddleware.php +++ b/src/WebSocketMiddleware.php @@ -2,6 +2,7 @@ namespace Voryx\WebSocketMiddleware; +use GuzzleHttp\Psr7\HttpFactory; use Psr\Http\Message\ServerRequestInterface; use Ratchet\RFC6455\Handshake\PermessageDeflateOptions; use Ratchet\RFC6455\Handshake\RequestVerifier; @@ -38,7 +39,11 @@ public function __invoke(ServerRequestInterface $request, callable $next = null) } } - $negotiator = new ServerNegotiator(new RequestVerifier(), $this->webSocketOptions->isPermessageDeflateEnabled()); + if (self::isRFC6455v03()) { + $negotiator = new ServerNegotiator(new RequestVerifier(), $this->webSocketOptions->isPermessageDeflateEnabled()); + } else { + $negotiator = new ServerNegotiator(new RequestVerifier(), new HttpFactory(), $this->webSocketOptions->isPermessageDeflateEnabled()); + } $negotiator->setSupportedSubProtocols($this->subProtocols); $negotiator->setStrictSubProtocolCheck(true); @@ -88,4 +93,9 @@ public function __invoke(ServerRequestInterface $request, callable $next = null) return $response; } + + private static function isRFC6455v03() { + $reflection = new \ReflectionClass('Ratchet\RFC6455\Handshake\ServerNegotiator'); + return $reflection->getMethod('__construct')->getNumberOfRequiredParameters() === 1; + } }