Skip to content

Commit 112e644

Browse files
committed
Changed some logging in the example
1 parent a972292 commit 112e644

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

examples/tcp_proxy_example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public function __construct(\React\EventLoop\LoopInterface $loop, $logger)
3232

3333
public function onDisconnect(WebSocketConnectionInterface $user)
3434
{
35-
$this->logger->notice(sprintf("User %s has been removed from proxy", $user->getId()));
3635
foreach ($this->getStreamsByUser($user) as $stream) {
3736
$stream->close();
3837
}
@@ -82,6 +81,7 @@ protected function requestConnect(WebSocketConnectionInterface $user, $message)
8281
)));
8382

8483
$stream->on("data", function ($data) use ($stream, $id, $user, $logger){
84+
$logger->notice("Forwarding ".strlen($data). " bytes from stream $id to {$user->getId()}");
8585
$message = array(
8686
'connection' => $id,
8787
'event' => 'data',

src/Devristo/Phpws/Server/UriHandler/ClientRouter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public function __construct(WebSocketServer $server, LoggerInterface $logger){
3232
$handler = $that->matchConnection($client);
3333

3434
if($handler){
35-
$logger->notice("We have added client {$client->getId()} to ".get_class($handler));
35+
$logger->notice("Added client {$client->getId()} to ".get_class($handler));
3636
$membership->attach($client, $handler);
37+
$handler->emit("connect", array("client" => $client));
3738
$handler->addConnection($client);
3839
}else
3940
$logger->err("Cannot route {$client->getId()} with request uri {$client->getUriRequested()}");
@@ -44,7 +45,7 @@ public function __construct(WebSocketServer $server, LoggerInterface $logger){
4445
$handler = $membership[$client];
4546
$membership->detach($client);
4647

47-
$logger->notice("We have removed client {$client->getId()} from".get_class($handler));
48+
$logger->notice("Removed client {$client->getId()} from".get_class($handler));
4849

4950
$handler->removeConnection($client);
5051
$handler->emit("disconnect", array("client" => $client));

src/Devristo/Phpws/Server/UriHandler/WebSocketUriHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function __construct($logger)
3838

3939
$this->on("message", array($this, 'onMessage'));
4040
$this->on("disconnect", array($this, 'onDisconnect'));
41+
$this->on("connect", array($this, 'onConnect'));
4142
}
4243

4344
public function addConnection(WebSocketConnectionInterface $user)
@@ -48,7 +49,6 @@ public function addConnection(WebSocketConnectionInterface $user)
4849
public function removeConnection(WebSocketConnectionInterface $user)
4950
{
5051
$this->users->detach($user);
51-
$this->onDisconnect($user);
5252
}
5353

5454
public function setServer(WebSocketServer $server)
@@ -66,6 +66,10 @@ public function onDisconnect(WebSocketConnectionInterface $user)
6666

6767
}
6868

69+
public function onConnect(WebSocketConnectionInterface $user){
70+
71+
}
72+
6973
public function onMessage(WebSocketConnectionInterface $user, WebSocketMessageInterface $msg)
7074
{
7175

0 commit comments

Comments
 (0)