Skip to content

Make Browser second constructor argument, de-emphasize default loop #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2021
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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ Its constructor simply requires the URL to the remote Server-Sent Events (SSE) e
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php');
```

This class takes an optional `LoopInterface|null $loop` parameter that can be used to
pass the event loop instance to use for this object. You can use a `null` value
here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
This value SHOULD NOT be given unless you're sure you want to explicitly use a
given event loop instance.

If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
proxy servers etc.), you can explicitly pass a custom instance of the
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
Expand All @@ -74,9 +68,15 @@ $connector = new React\Socket\Connector([
]);
$browser = new React\Http\Browser($connector);

$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', null, $browser);
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $browser);
```

This class takes an optional `LoopInterface|null $loop` parameter that can be used to
pass the event loop instance to use for this object. You can use a `null` value
here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
This value SHOULD NOT be given unless you're sure you want to explicitly use a
given event loop instance.

## Install

The recommended way to install this library is [through Composer](https://getcomposer.org).
Expand Down
44 changes: 42 additions & 2 deletions src/EventSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,52 @@ class EventSource extends EventEmitter
private $reconnectTime = 3.0;

/**
* The `EventSource` class is responsible for communication with the remote Server-Sent Events (SSE) endpoint.
*
* The `EventSource` object works very similar to the one found in common
* web browsers. Unless otherwise noted, it follows the same semantics as defined
* under https://html.spec.whatwg.org/multipage/server-sent-events.html
*
* Its constructor simply requires the URL to the remote Server-Sent Events (SSE) endpoint:
*
* ```php
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php');
* ```
*
* If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
* proxy servers etc.), you can explicitly pass a custom instance of the
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
* to the [`Browser`](https://github.com/reactphp/http#browser) instance
* and pass it as an additional argument to the `EventSource` like this:
*
* ```php
* $connector = new React\Socket\Connector([
* 'dns' => '127.0.0.1',
* 'tcp' => [
* 'bindto' => '192.168.10.1:0'
* ],
* 'tls' => [
* 'verify_peer' => false,
* 'verify_peer_name' => false
* ]
* ]);
* $browser = new React\Http\Browser($connector);
*
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $browser);
* ```
*
* This class takes an optional `LoopInterface|null $loop` parameter that can be used to
* pass the event loop instance to use for this object. You can use a `null` value
* here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
* This value SHOULD NOT be given unless you're sure you want to explicitly use a
* given event loop instance.
*
* @param string $url
* @param ?LoopInterface $loop
* @param ?Browser $browser
* @param ?LoopInterface $loop
* @throws \InvalidArgumentException for invalid URL
*/
public function __construct($url, LoopInterface $loop = null, Browser $browser = null)
public function __construct($url, Browser $browser = null, LoopInterface $loop = null)
{
$parts = parse_url($url);
if (!isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], array('http', 'https'))) {
Expand Down
Loading