Releases: amphp/websocket-client
2.0.1
2.0.0
Stable release compatible with AMPHP v3 and fibers! 🎉
As with other libraries compatible with AMPHP v3, most cases of parameters or returns of Promise<ResolutionType>
have been replaced with ResolutionType
.
This release is compatible with amphp/http-client@^5
and amphp/websocket@^2
. See the release notes of these libraries for further change notes.
Similar to v1
, a Websocket connection is created using Amp\Websocket\Client\connect()
or using an instance of WebsocketConnector
, calling WebsocketConnector::connect()
. The returned WebsocketConnection
then is used to send and receive WebSocket messages.
- Renamed most classes and interfaces to add
Websocket
as a prefix to avoid name collisions with similarly named classes in other packages which are frequently used together. For example,Connection
is nowWebsocketConnection
. - Advanced handshake and connection parameters may be specified using a
Rfc6455ConnectionFactory
instance provided when constructing aRfc6455Connector
. - A global
WebsocketConnector
instance may be accessed and set viaAmp\Websocket\Client\websocketConnector()
.
2.0.0 Beta 4
- Compatibility with
amphp/websocket@v2
andamphp/http-client@v5
2.0.0 Beta 3
- Compatibility with
amphp/http@v2
- Added query-related methods to
WebsocketHandshake
2.0.0 Beta 2
- Updated for compatibility with
amphp/socket@v2
andamphp/[email protected]
- Altered
Rfc6455ConnectionFactory
constructor to use an instance ofWebsocketParserFactory
, moving some configuration options toRfc6455ParserFactory
2.0.0 Beta 1
Initial release compatible with AMPHP v3.
As with other libraries compatible with AMPHP v3, most cases of parameters or returns of Promise<ResolutionType>
have been replaced with ResolutionType
.
- Added
Websocket
as a prefix to several classes:Connection
renamed toWebsocketConnection
ConnectionFactory
renamed toWebsocketConnectionFactory
Connector
renamed toWebsocketConnector
ConnectionException
renamed toWebsocketConnectException
Handshake
renamed toWebsocketHandshake
- Renamed
connector
function towebsocketConnector
1.0.1
1.0.0
Changes since RC2
- Removed header methods from
Connection
. Now theResponse
object is available withConnection::getResponse()
, which provides access to the response headers and other response data. - Removed the
connector()
function, so there is no longer a globalConnector
object. - Fixed
Handshake::withHeaders()
to remove all prior set headers as expected. - Added
ConnectContext
parameter toconnect()
function. ConnectionException
now extendsHttpException
fromamphp/http-client
.
Upgrading from v0.2.x to v1.0
This library has been refactored to use the new amphp/websocket
library containing components that can be shared between server and clients.
The simplest way to use this library is with the connect()
function to initiate a WebSocket connection.
$connection = yield Amp\Websocket\Client\connect('ws://localhost:1337/broadcast');
yield $connection->send('Hello!');
/** @var Amp\Websocket\Message $message */
while ($message = yield $connection->receive()) {
$payload = yield $message->buffer();
// $payload now contains the entire message content
yield $connection->send('Received message with length ' . strlen($payload));
}
Custom request headers and connections options can be set using the Handshake
class and passing this object to connect()
instead of a string URI. Connection behavior can be further customized by using an instance of Connector
to establish a connection instead of the connect()
function.
WebSocket clients are now represented by Connection
, which extends the Client
object from amphp/websocket
. This object contains several methods for getting information about the client, fetching the headers returned in the server response, and sending/receiving messages.
1.0.0 RC2
- This library now uses
HttpClient
fromamphp/http-client
to send connection requests. As such,Rfc6455Connector
requires an instance ofHttpClient
when constructed. The client may have various interceptors attached to modify behavior when connecting. - Updated to
league/uri@^6
, subsequently PHP 7.2+ is now required.
1.0.0 RC1
This library has been refactored to use the new amphp/websocket
library containing components that can be shared between server and clients.
Note: This is a pre-release, there might be breaking changes in the final stable version.
The simplest way to use this library is with the connect()
function to initiate a WebSocket connection.
$connection = yield Amp\Websocket\Client\connect('ws://localhost:1337/broadcast');
yield $connection->send('Hello!');
/** @var Amp\Websocket\Message $message */
while ($message = yield $connection->receive()) {
$payload = yield $message->buffer();
// $payload now contains the entire message content
yield $connection->send('Received message with length ' . strlen($payload));
}
Custom request headers and connections options can be set using the Handshake
class and passing this object to connect()
instead of a string URI. Connection behavior can be customized using the Connector
interface or by extending the existing Rfc6455Connector
class.
WebSocket clients are now represented by Connection
, which extends the Client
object from amphp/websocket
. This object contains several methods for getting information about the client, fetching the headers returned in the server response, and sending/receiving messages.