Skip to content

Commit

Permalink
fix: swoft-cloud/swoft/issues/1222 compatible ws setting open_websock…
Browse files Browse the repository at this point in the history
…et_close_frame
  • Loading branch information
inhere committed Apr 13, 2020
1 parent 3db933e commit e6428a5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/websocket-server/src/Swoole/MessageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Swoole\Websocket\Server;
use Throwable;
use function server;
use const WEBSOCKET_OPCODE_CLOSE;

/**
* Class MessageListener
Expand All @@ -55,14 +56,22 @@ class MessageListener implements MessageInterface
public function onMessage(Server $server, Frame $frame): void
{
$fd = $frame->fd;
$sid = (string)$fd;

// Fix: if setting: 'open_websocket_close_frame' => true
if ($frame->opcode === WEBSOCKET_OPCODE_CLOSE) {
CLog::info('Close ws#%d connection by close opcode message, reason: %s', $fd, $frame->reason);
// Swoft::getBean(CloseListener::class)->onClose($server, $fd, 0);
// NOTICE: swoole will auto call close event.
return;
}

server()->log("Message: conn#{$fd} received message data", [], 'debug');

$request = Request::new($frame);
$response = Response::new($fd);

/** @var WsMessageContext $ctx */
$sid = (string)$fd;
$ctx = WsMessageContext::new($request, $response);

// Storage context
Expand Down

0 comments on commit e6428a5

Please sign in to comment.