99use Gos \Bundle \WebSocketBundle \Pusher \ServerPushHandlerRegistry ;
1010use Gos \Bundle \WebSocketBundle \Server \App \Registry \OriginRegistry ;
1111use Gos \Bundle \WebSocketBundle \Server \App \Registry \PeriodicRegistry ;
12+ use Gos \Bundle \WebSocketBundle \Server \App \Stack \OriginCheck ;
13+ use Gos \Bundle \WebSocketBundle \Server \App \Stack \WampConnectionPeriodicTimer ;
1214use Gos \Bundle \WebSocketBundle \Server \App \WampApplication ;
13- use Gos \Component \RatchetStack \Builder ;
15+ use Gos \Bundle \WebSocketBundle \Server \WampServer ;
16+ use Gos \Bundle \WebSocketBundle \Topic \TopicManager ;
1417use ProxyManager \Proxy \ProxyInterface ;
1518use Psr \Log \LoggerInterface ;
1619use Psr \Log \NullLogger ;
17- use Ratchet \Wamp \TopicManager ;
18- use React \EventLoop \Factory ;
20+ use Ratchet \Http \HttpServer ;
21+ use Ratchet \Server \IoServer ;
22+ use Ratchet \Session \SessionProvider ;
23+ use Ratchet \WebSocket \WsServer ;
1924use React \EventLoop \LoopInterface ;
2025use React \Socket \Server ;
2126use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
@@ -67,18 +72,21 @@ class WebSocketServer implements ServerInterface
6772 /** @var ServerPushHandlerRegistry */
6873 protected $ serverPusherHandlerRegistry ;
6974
70- /** @var TopicManager */
75+ /**
76+ * @var TopicManager
77+ */
7178 protected $ topicManager ;
7279
7380 /**
74- * @param LoopInterface $loop
75- * @param EventDispatcherInterface $eventDispatcher
76- * @param PeriodicRegistry $periodicRegistry
77- * @param WampApplication $wampApplication
78- * @param OriginRegistry $originRegistry
79- * @param bool $originCheck
80- * @param TopicManager $topicManager
81- * @param LoggerInterface|null $logger
81+ * @param LoopInterface $loop
82+ * @param EventDispatcherInterface $eventDispatcher
83+ * @param PeriodicRegistry $periodicRegistry
84+ * @param WampApplication $wampApplication
85+ * @param OriginRegistry $originRegistry
86+ * @param bool $originCheck
87+ * @param TopicManager $topicManager
88+ * @param ServerPushHandlerRegistry $serverPushHandlerRegistry
89+ * @param LoggerInterface|null $logger
8290 */
8391 public function __construct (
8492 LoopInterface $ loop ,
@@ -120,13 +128,8 @@ public function launch($host, $port, $profile)
120128 {
121129 $ this ->logger ->info ('Starting web socket ' );
122130
123- //In order to avoid circular reference
124- $ this ->topicManager ->setWampApplication ($ this ->wampApplication );
125131
126- $ stack = new Builder ();
127-
128- $ server = new Server ($ this ->loop );
129- $ server ->listen ($ port , $ host );
132+ $ server = new Server ("$ host: $ port " , $ this ->loop );
130133
131134 if (true === $ profile ) {
132135 $ memoryUsagePeriodicTimer = new PeriodicMemoryUsage ($ this ->logger );
@@ -146,21 +149,29 @@ public function launch($host, $port, $profile)
146149
147150 $ allowedOrigins = array_merge (array ('localhost ' , '127.0.0.1 ' ), $ this ->originRegistry ->getOrigins ());
148151
149- $ stack
150- ->push ('Ratchet\Server\IoServer ' , $ server , $ this ->loop )
151- ->push ('Ratchet\Http\HttpServer ' );
152-
153- if ($ this ->originCheck ) {
154- $ stack ->push ('Gos\Bundle\WebSocketBundle\Server\App\Stack\OriginCheck ' , $ allowedOrigins , $ this ->eventDispatcher );
155- }
156-
157- $ stack
158- ->push ('Ratchet\WebSocket\WsServer ' )
159- ->push ('Gos\Bundle\WebSocketBundle\Server\App\Stack\WampConnectionPeriodicTimer ' , $ this ->loop )
160- ->push ('Ratchet\Session\SessionProvider ' , $ this ->sessionHandler )
161- ->push ('Ratchet\Wamp\WampServer ' , $ this ->topicManager );
162-
163- $ app = $ stack ->resolve ($ this ->wampApplication );
152+ $ wsServer = new WsServer (
153+ new WampConnectionPeriodicTimer (
154+ new WampServer ($ this ->wampApplication , $ this ->topicManager ),
155+ $ this ->loop
156+ )
157+ );
158+ $ wsServer ->setStrictSubProtocolCheck (false );
159+
160+ $ app = new IoServer (
161+ new HttpServer (
162+ new OriginCheck (
163+ new SessionProvider (
164+ $ wsServer ,
165+ $ this ->sessionHandler
166+ ),
167+ $ this ->originCheck ,
168+ $ allowedOrigins ,
169+ $ this ->eventDispatcher
170+ )
171+ ),
172+ $ server ,
173+ $ this ->loop
174+ );
164175
165176 //Push Transport Layer
166177 foreach ($ this ->serverPusherHandlerRegistry ->getPushers () as $ handler ) {
0 commit comments