Skip to content

Commit

Permalink
fix some error for ws server
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 8, 2020
1 parent 3cae6ea commit 4aaed75
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/framework/src/Concern/AbstractSessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function set(string $sessionId, SessionInterface $session): bool
}

/**
* Get connection session object by sessionId.
*
* - If not found on current worker, will try find from storage driver.
*
* @param string $sessionId The session Id. eg: swoole.fd, http session id
*
* @return SessionInterface|null
Expand Down
1 change: 1 addition & 0 deletions src/websocket-server/src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static function manager(): ConnectionManager
*/
public static function current(): self
{
/** @see ConnectionManager::current() */
return Swoft::getBean(WsServerBean::MANAGER)->current();
}

Expand Down
3 changes: 2 additions & 1 deletion src/websocket-server/src/Swoole/HandshakeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function onHandshake(Request $request, Response $response): bool
$psr7Req = Psr7Request::new($request);
$psr7Res = Psr7Response::new($response);
$wsServer = Swoft::getBean(WsServerBean::SERVER);
/** @var Swoft\WebSocket\Server\ConnectionManager $manager */
$manager = Swoft::getBean(WsServerBean::MANAGER);

// Initialize connection session and context
Expand Down Expand Up @@ -188,7 +189,7 @@ public function onOpen(Psr7Request $request, int $fd): void
Swoft::trigger(WsServerEvent::OPEN_AFTER, $fd, $server, $request);
} catch (Throwable $e) {
Swoft::trigger(WsServerEvent::OPEN_ERROR, $e, $request);
\vdump($e);

/** @var WsErrorDispatcher $errDispatcher */
$errDispatcher = BeanFactory::getSingleton(WsErrorDispatcher::class);
$errDispatcher->openError($e, $request);
Expand Down
5 changes: 3 additions & 2 deletions src/websocket-server/src/Swoole/MessageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ public function onMessage(Server $server, Frame $frame): void
Session::bindCo($sid);

try {
// Trigger message before event
// Trigger message before event.
// NOTICE: on the event, maybe session has been lost. TODO
Swoft::trigger(WsServerEvent::MESSAGE_RECEIVE, $fd, $server, $frame);

/** @var Connection $conn */
// $conn = Session::current();
// NOTICE: don't use Session::current(). must use Connection::current(), it can be restore connection from storage.
$conn = Connection::current();
$info = $conn->getModuleInfo();

Expand Down

0 comments on commit 4aaed75

Please sign in to comment.