-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
207 additions
and
169 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[Documentation](Index.md) > Client | ||
[Documentation](Index.md) / Client | ||
|
||
# Websocket: Client | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[Documentation](Index.md) > Examples | ||
[Documentation](Index.md) / Examples | ||
|
||
# Websocket: Examples | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[Documentation](Index.md) > Listener | ||
[Documentation](Index.md) / Listener | ||
|
||
# Websocket: Listener | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[Documentation](Index.md) > Message | ||
[Documentation](Index.md) / Message | ||
|
||
# Websocket: Message | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[Documentation](Index.md) / [Middleware](Middleware.md) / Callback | ||
|
||
# Websocket: Callback middleware | ||
|
||
This middleware will apply callback functions on certain actions. | ||
This middlewares is included in library and can be added to provide additional functionality. | ||
|
||
```php | ||
$client_or_server | ||
->addMiddleware(new WebSocket\Middleware\Callback( | ||
incoming: function (WebSocket\Middleware\ProcessStack $stack, WebSocket\Connection $connection): WebSocket\Message\Message { | ||
$message = $stack->handleIncoming(); // Get incoming message from next middleware | ||
$message->setContent("Changed message"); | ||
return $message; | ||
}, | ||
outgoing: function (WebSocket\Middleware\ProcessStack $stack, WebSocket\Connection $connection, WebSocket\Message\Message $message): WebSocket\Message\Message { | ||
$message->setContent('Changed message'); | ||
$message = $stack->handleOutgoing($message); // Forward outgoing message to next middleware | ||
return $message; | ||
}, | ||
httpIncoming: function (WebSocket\Middleware\ProcessHttpStack $stack, WebSocket\Connection $connection): WebSocket\Http\Message { | ||
$message = $stack->handleHttpIncoming(); // Get incoming message from next middleware | ||
return $message; | ||
}, | ||
httpOutgoing: function (WebSocket\Middleware\ProcessHttpStack $stack, WebSocket\Connection $connection, WebSocket\Http\Message $message): WebSocket\Http\Message { | ||
$message = $stack->handleHttpOutgoing($message); // Forward outgoing message to next middleware | ||
return $message; | ||
}, | ||
tick: function (WebSocket\Middleware\ProcessTickStack $stack, WebSocket\Connection $connection): void { | ||
$stack->handleTick(); // Forward tick to next middleware | ||
} | ||
)); | ||
``` | ||
|
||
* The `incoming` and `outgoing` callbacks **MUST** return a [Message](Message.md) instance | ||
* The `httpIncoming` and `httpOutgoing` callbacks **MUST** return a HTTP request/response instance respectively | ||
* The `tick` callback returns nothing | ||
|
||
The `handleIncoming`, `handleOutgoing`, `handleHttpIncoming`, `handleHttpOutgoing` and `handleTick` methods will pass initiative further down the middleware stack. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Documentation](Index.md) / [Middleware](Middleware.md) / CloseHandler | ||
|
||
# Websocket: CloseHandler middleware | ||
|
||
Thid middleware provide standard operability according to WebSocket protocol, | ||
and should be added unless you write your own implementation of close handling. | ||
|
||
* When a Close message is received, CloseHandler will respond with a Close confirmation message | ||
* When a Close confirmation message is received, CloseHandler will close the connection | ||
* When a Close message is sent, CloseHandler will block further messages from being sent | ||
|
||
```php | ||
$client_or_server->addMiddleware(new WebSocket\Middleware\CloseHandler()); | ||
``` |
Oops, something went wrong.