-
-
Notifications
You must be signed in to change notification settings - Fork 142
Handshake middleware for server #224
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
Closed
Closed
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5df35d6
handshake middleware was added for server
8f46553
middleware fabric partly
e2afa63
middleware factory done
b63368d
fix
b6c66df
fix
f7ecd3f
update Middleware class
0edc7c7
ClientRejectedEvent update
ddbdbfe
upd
57aa6c5
fix config middleware
1c2a388
fix config middleware
1e3af3a
middleware fixes
4c3306b
middleware fix
ffe74e3
middleware interface to abstract
86a91f2
middleware update
254eb38
WebsocketAuthenticationProvider to WebsocketAuthenticationProviderInt…
7f4ce2e
WebsocketAuthenticationProvider fix
b2b64ed
WebsocketAuthenticationProvider fix
8d743dc
WebSocketServer constructor update
c24eabc
Handshake middleware example for OAuth
9b195a0
config fix - handshake_middleware is not necessary
36ddf3a
annotation fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| # HandshakeMiddleware | ||
|
|
||
| You can add any middleware as service to server with your business logic | ||
|
|
||
|
|
||
| **Bundle Configuration** | ||
|
|
||
| ```yaml | ||
| # Gos Web Socket Bundle | ||
| gos_web_socket: | ||
| server: | ||
| handshake_middleware: | ||
| - @some_service # have to extends Gos\Bundle\WebSocketBundle\Server\App\Stack\HandshakeMiddlewareAbstract | ||
| ``` |
This file contains hidden or 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,38 @@ | ||
| <?php | ||
|
|
||
| namespace Gos\Bundle\WebSocketBundle\Server\App\Registry; | ||
|
|
||
| use Gos\Bundle\WebSocketBundle\Server\App\Stack\HandshakeMiddlewareAbstract; | ||
|
|
||
| /** | ||
| * @author Tkachew <[email protected]> | ||
| */ | ||
| class HandshakeMiddlewareRegistry | ||
| { | ||
| /** | ||
| * @var HandshakeMiddlewareAbstract[] | ||
| */ | ||
| protected $middlewares; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->middlewares = []; | ||
| } | ||
|
|
||
| /** | ||
| * @param HandshakeMiddlewareAbstract $middleware | ||
| * @throws \Exception | ||
| */ | ||
| public function addMiddleware(HandshakeMiddlewareAbstract $middleware) | ||
| { | ||
| $this->middlewares[] = $middleware; | ||
| } | ||
|
|
||
| /** | ||
| * @return HandshakeMiddlewareAbstract[] | ||
| */ | ||
| public function getMiddlewares() | ||
| { | ||
| return $this->middlewares; | ||
| } | ||
| } | ||
This file contains hidden or 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,73 @@ | ||
| <?php | ||
|
|
||
| namespace Gos\Bundle\WebSocketBundle\Server\App\Stack\Factory; | ||
|
|
||
| use Gos\Bundle\WebSocketBundle\Event\ClientRejectedEvent; | ||
| use Gos\Bundle\WebSocketBundle\Event\Events; | ||
| use Gos\Bundle\WebSocketBundle\Server\App\Stack\HandshakeMiddlewareAbstract; | ||
| use Guzzle\Http\Message\RequestInterface; | ||
| use Ratchet\ConnectionInterface; | ||
| use Ratchet\Http\HttpServerInterface; | ||
| use Ratchet\MessageComponentInterface; | ||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
|
||
| /** | ||
| * @author Johann Saunier <[email protected]> | ||
| */ | ||
| class Middleware implements HttpServerInterface | ||
| { | ||
| /** | ||
| * @var \Ratchet\MessageComponentInterface | ||
| */ | ||
| protected $_component; | ||
|
|
||
| /** | ||
| * @var HandshakeMiddlewareAbstract | ||
| */ | ||
| protected $_middleware; | ||
|
|
||
| /** | ||
| * @param MessageComponentInterface $component | ||
| * @param HandshakeMiddlewareAbstract $middleware | ||
| */ | ||
| public function __construct( | ||
| MessageComponentInterface $component, | ||
| HandshakeMiddlewareAbstract $middleware | ||
| ) { | ||
| $this->_component = $component; | ||
| $this->_middleware = $middleware; | ||
| $this->_middleware->setComponent($component); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) | ||
| { | ||
| return $this->_middleware->onOpen($conn, $request); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function onMessage(ConnectionInterface $from, $msg) | ||
| { | ||
| return $this->_middleware->onMessage($from, $msg); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function onClose(ConnectionInterface $conn) | ||
| { | ||
| return $this->_middleware->onClose($conn); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function onError(ConnectionInterface $conn, \Exception $e) | ||
| { | ||
| return $this->_middleware->onError($conn, $e); | ||
| } | ||
| } |
This file contains hidden or 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,66 @@ | ||
| <?php | ||
|
|
||
| namespace Gos\Bundle\WebSocketBundle\Server\App\Stack; | ||
|
|
||
| use Guzzle\Http\Message\RequestInterface; | ||
| use Ratchet\Http\HttpServerInterface; | ||
| use Ratchet\ConnectionInterface; | ||
| use Ratchet\MessageComponentInterface; | ||
|
|
||
| /** | ||
| * @author Tkachew <[email protected]> | ||
| */ | ||
| abstract class HandshakeMiddlewareAbstract implements HttpServerInterface | ||
| { | ||
| /** | ||
| * @var MessageComponentInterface | ||
| */ | ||
| protected $_component; | ||
|
|
||
| /** | ||
| * @param MessageComponentInterface $component | ||
| */ | ||
| public function setComponent(MessageComponentInterface $component) | ||
| { | ||
| $this->_component = $component; | ||
| } | ||
|
|
||
| /** | ||
| * @param ConnectionInterface $conn | ||
| * @param RequestInterface|null $request | ||
| * @return mixed | ||
| */ | ||
| public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) | ||
| { | ||
| return $this->_component->onOpen($conn, $request); | ||
| } | ||
|
|
||
| /** | ||
| * @param ConnectionInterface $conn | ||
| * @return mixed | ||
| */ | ||
| public function onClose(ConnectionInterface $conn) | ||
| { | ||
| return $this->_component->onClose($conn); | ||
| } | ||
|
|
||
| /** | ||
| * @param ConnectionInterface $conn | ||
| * @param \Exception $e | ||
| * @return mixed | ||
| */ | ||
| public function onError(ConnectionInterface $conn, \Exception $e) | ||
| { | ||
| return $this->_component->onError($conn, $e); | ||
| } | ||
|
|
||
| /** | ||
| * @param ConnectionInterface $from | ||
| * @param string $msg | ||
| * @return mixed | ||
| */ | ||
| public function onMessage(ConnectionInterface $from, $msg) | ||
| { | ||
| return $this->_component->onMessage($from, $msg); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where?