Skip to content

Commit 2bba509

Browse files
authored
Merge pull request #1100 from akotulu/master
Improved onWebSocketClose with response message.
2 parents 72cafa1 + d80eb0d commit 2bba509

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Connection/TcpConnection.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,26 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
133133
public $onConnect = null;
134134

135135
/**
136-
* Emitted before websocket handshake (Only works when protocol is ws).
136+
* Emitted before websocket handshake (Only called when protocol is ws).
137137
*
138138
* @var ?callable
139139
*/
140140
public $onWebSocketConnect = null;
141141

142142
/**
143-
* Emitted after websocket handshake (Only works when protocol is ws).
143+
* Emitted after websocket handshake (Only called when protocol is ws).
144144
*
145145
* @var ?callable
146146
*/
147147
public $onWebSocketConnected = null;
148148

149+
/**
150+
* Emitted when websocket connection is closed (Only called when protocol is ws).
151+
*
152+
* @var ?callable
153+
*/
154+
public $onWebSocketClose = null;
155+
149156
/**
150157
* Emitted when data is received.
151158
*

src/Protocols/Ws.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function input(string $buffer, AsyncTcpConnection $connection): in
116116
// Try to emit onWebSocketClose callback.
117117
if (isset($connection->onWebSocketClose)) {
118118
try {
119-
($connection->onWebSocketClose)($connection);
119+
($connection->onWebSocketClose)($connection, self::decode($buffer, $connection));
120120
} catch (Throwable $e) {
121121
Worker::stopAll(250, $e);
122122
}

0 commit comments

Comments
 (0)