Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/EventSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
*/
class EventSource extends EventEmitter
{
/**
* @var string (read-only) last event ID received
*/
public $lastEventId = '';

// ready state
const CONNECTING = 0;
const OPEN = 1;
Expand All @@ -67,18 +62,46 @@ class EventSource extends EventEmitter
* @see self::CONNECTING
* @see self::OPEN
* @see self::CLOSED
* @psalm-readonly-allow-private-mutation
*/
public $readyState = self::CLOSED;

/**
* @var string (read-only) URL
* @readonly
*/
public $url;

/**
* @var string last event ID received
*/
private $lastEventId = '';

/**
* @var LoopInterface
* @readonly
*/
private $loop;

/**
* @var Browser
* @readonly
*/
private $browser;

/**
* @var ?\React\Promise\PromiseInterface
*/
private $request;

/**
* @var ?\React\EventLoop\TimerInterface
*/
private $timer;

/**
* @var float
*/
private $reconnectTime = 3.0;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/MessageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,26 @@ public static function parse($data)

/**
* @var string
* @readonly
*/
public $data = '';

/**
* @var ?string
* @readonly
*/
public $lastEventId = null;

/**
* @var string
* @readonly
*/
public $type = 'message';

/**
* @internal
* @var ?int
* @readonly
*/
public $retry;
}
6 changes: 5 additions & 1 deletion tests/EventSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,11 @@ public function testEmitMessageOnceWhenCallingCloseFromMessageHandlerFromEventSt

$this->assertInstanceOf('Clue\React\EventSource\MessageEvent', $message);
$this->assertEquals('1', $message->lastEventId);
$this->assertEquals('1', $es->lastEventId);

$ref = new \ReflectionProperty($es, 'lastEventId');
$ref->setAccessible(true);

$this->assertEquals('1', $ref->getValue($es));
}

public function testReconnectAfterStreamClosesUsesLastEventIdFromParsedEventStreamForNextRequest()
Expand Down