Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":{
Expand Down
12 changes: 11 additions & 1 deletion src/WebSocketMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}