Fixed message parsing bug

This commit is contained in:
2024-03-01 21:48:28 +01:00
parent c4f3e8ae50
commit b2494c3163
3 changed files with 25 additions and 5 deletions

View File

@ -74,7 +74,8 @@ class CommandBusClient implements CommandBusInterface
$this->connection = $connection;
$this->emit(self::EVENT_CONNECTED);
$connection->on('error', function ($error) {
$this->emit(self::EVENT_DISCONNECTED, [ $error ]);
$this->emit(self::EVENT_ERROR, [ $error ]);
$this->emit(self::EVENT_DISCONNECTED);
if ($this->autoReconnect) {
Loop::addTimer(1, $this->reconnect(...));
}
@ -89,8 +90,10 @@ class CommandBusClient implements CommandBusInterface
});
$connection->on('data', function ($data) use ($connection) {
try {
$message = Message::fromString($data);
$this->onServerMessage($message);
$messages = Message::fromStringMulti($data);
foreach ($messages as $message) {
$this->onServerMessage($message);
}
} catch (MessageException $e) {
$connection->end('{"msg":"error","data":{"error":"Bad message format"}}');
}