Skip to content

Commit d925030

Browse files
committed
Add subprotocol support
1 parent bc06731 commit d925030

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/WebSocketMiddleware.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ final class WebSocketMiddleware
1313
{
1414
private $paths;
1515
private $connectionHandler = null;
16+
private $subProtocols;
1617

17-
public function __construct(array $paths = [], callable $connectionHandler = null)
18+
public function __construct(array $paths = [], callable $connectionHandler = null, array $subProtocols = [])
1819
{
1920
$this->paths = $paths;
2021
$this->connectionHandler = $connectionHandler ?: function () {};
22+
$this->subProtocols = $subProtocols;
2123
}
2224

2325
public function __invoke(ServerRequestInterface $request, callable $next)
@@ -30,6 +32,8 @@ public function __invoke(ServerRequestInterface $request, callable $next)
3032
}
3133

3234
$negotiator = new ServerNegotiator(new RequestVerifier());
35+
$negotiator->setSupportedSubProtocols($this->subProtocols);
36+
$negotiator->setStrictSubProtocolCheck(true);
3337

3438
$response = $negotiator->handshake($request);
3539

0 commit comments

Comments
 (0)