From 8bbc516f5e595496f327de41f2666e859d4126b2 Mon Sep 17 00:00:00 2001 From: Illia Kovalov Date: Mon, 9 Oct 2017 17:50:50 +0200 Subject: [PATCH] Update WsServer.php --- src/Ratchet/WebSocket/WsServer.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 951e9dd..551c737 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -61,22 +61,12 @@ class WsServer implements HttpServerInterface { */ private $msgCb; - /** - * @var bool - */ - private $keepAliveEnabled; - - /** - * @var int - */ - private $keepAliveTimeout = 30; - /** * @param \Ratchet\WebSocket\MessageComponentInterface|\Ratchet\MessageComponentInterface $component Your application to run with WebSockets * @param int $keepAliveTimeout * @note If you want to enable sub-protocols have your component implement WsServerInterface as well */ - public function __construct(ComponentInterface $component, $keepAliveTimeout = 30) { + public function __construct(ComponentInterface $component) { if ($component instanceof MessageComponentInterface) { $this->msgCb = function(ConnectionInterface $conn, MessageInterface $msg) { $this->delegate->onMessage($conn, $msg); @@ -99,7 +89,6 @@ class WsServer implements HttpServerInterface { $this->closeFrameChecker = new CloseFrameChecker; $this->handshakeNegotiator = new ServerNegotiator(new RequestVerifier); $this->handshakeNegotiator->setStrictSubProtocolCheck(true); - $this->keepAliveEnabled = false; if ($component instanceof WsServerInterface) { $this->handshakeNegotiator->setSupportedSubProtocols($component->getSubProtocols()); @@ -208,10 +197,7 @@ class WsServer implements HttpServerInterface { $this->handshakeNegotiator->setStrictSubProtocolCheck($enable); } - public function enableKeepAlive(LoopInterface $loop) { - if ($this->keepAliveEnabled) { - return; - } + public function enableKeepAlive(LoopInterface $loop, $interval = 30) { $this->keepAliveEnabled = true; $lastPing = new Frame(uniqid(), true, Frame::OP_PING); $pingedConnections = new \SplObjectStorage; @@ -223,7 +209,7 @@ class WsServer implements HttpServerInterface { } }; - $loop->addPeriodicTimer((int)$this->keepAliveTimeout, function() use ($pingedConnections, &$lastPing, $splClearer) { + $loop->addPeriodicTimer((int)$interval, function() use ($pingedConnections, &$lastPing, $splClearer) { foreach ($pingedConnections as $wsConn) { $wsConn->close(); }