Merge pull request #403 from ratchetphp/0.4-wip/request-container
0.4 wip/request container
This commit is contained in:
commit
fb6eee1908
20
src/Ratchet/WebSocket/ConnContext.php
Normal file
20
src/Ratchet/WebSocket/ConnContext.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Ratchet\WebSocket;
|
||||||
|
use Ratchet\RFC6455\Messaging\MessageBuffer;
|
||||||
|
|
||||||
|
class ConnContext {
|
||||||
|
/**
|
||||||
|
* @var \Ratchet\WebSocket\WsConnection
|
||||||
|
*/
|
||||||
|
public $connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Ratchet\RFC6455\Messaging\MessageBuffer;
|
||||||
|
*/
|
||||||
|
public $buffer;
|
||||||
|
|
||||||
|
public function __construct(WsConnection $conn, MessageBuffer $buffer) {
|
||||||
|
$this->connection = $conn;
|
||||||
|
$this->buffer = $buffer;
|
||||||
|
}
|
||||||
|
}
|
@ -87,11 +87,10 @@ class WsServer implements HttpServerInterface {
|
|||||||
throw new \UnexpectedValueException('$request can not be null');
|
throw new \UnexpectedValueException('$request can not be null');
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn->httpRequest = $request; // This will replace ->WebSocket->request
|
$conn->httpRequest = $request;
|
||||||
|
|
||||||
$conn->WebSocket = new \StdClass;
|
$conn->WebSocket = new \StdClass;
|
||||||
$conn->WebSocket->closing = false;
|
$conn->WebSocket->closing = false;
|
||||||
$conn->WebSocket->request = $request; // deprecated
|
|
||||||
|
|
||||||
$response = $this->handshakeNegotiator->handshake($request)->withHeader('X-Powered-By', \Ratchet\VERSION);
|
$response = $this->handshakeNegotiator->handshake($request)->withHeader('X-Powered-By', \Ratchet\VERSION);
|
||||||
|
|
||||||
@ -115,7 +114,7 @@ class WsServer implements HttpServerInterface {
|
|||||||
$this->ueFlowFactory
|
$this->ueFlowFactory
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->connections->attach($conn, [$wsConn, $streamer]);
|
$this->connections->attach($conn, new ConnContext($wsConn, $streamer));
|
||||||
|
|
||||||
return $this->delegate->onOpen($wsConn);
|
return $this->delegate->onOpen($wsConn);
|
||||||
}
|
}
|
||||||
@ -128,8 +127,7 @@ class WsServer implements HttpServerInterface {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = $this->connections[$from];
|
$this->connections[$from]->buffer->onData($msg);
|
||||||
$context[1]->onData($msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,7 +138,7 @@ class WsServer implements HttpServerInterface {
|
|||||||
$context = $this->connections[$conn];
|
$context = $this->connections[$conn];
|
||||||
$this->connections->detach($conn);
|
$this->connections->detach($conn);
|
||||||
|
|
||||||
$this->delegate->onClose($context[0]);
|
$this->delegate->onClose($context->connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,8 +147,7 @@ class WsServer implements HttpServerInterface {
|
|||||||
*/
|
*/
|
||||||
public function onError(ConnectionInterface $conn, \Exception $e) {
|
public function onError(ConnectionInterface $conn, \Exception $e) {
|
||||||
if ($this->connections->contains($conn)) {
|
if ($this->connections->contains($conn)) {
|
||||||
$context = $this->connections[$conn];
|
$this->delegate->onError($this->connections[$from]->connection, $e);
|
||||||
$this->delegate->onError($context[0], $e);
|
|
||||||
} else {
|
} else {
|
||||||
$conn->close();
|
$conn->close();
|
||||||
}
|
}
|
||||||
@ -195,8 +192,7 @@ class WsServer implements HttpServerInterface {
|
|||||||
$lastPing = new Frame(uniqid(), true, Frame::OP_PING);
|
$lastPing = new Frame(uniqid(), true, Frame::OP_PING);
|
||||||
|
|
||||||
foreach ($this->connections as $key => $conn) {
|
foreach ($this->connections as $key => $conn) {
|
||||||
$context = $this->connections[$conn];
|
$wsConn = $this->connections[$from]->connection;
|
||||||
$wsConn = $context[0];
|
|
||||||
|
|
||||||
$wsConn->send($lastPing);
|
$wsConn->send($lastPing);
|
||||||
$pingedConnections->attach($wsConn);
|
$pingedConnections->attach($wsConn);
|
||||||
|
Loading…
Reference in New Issue
Block a user