1 | 2 | simandl | <?php |
2 | | | |
3 | | | /** |
4 | | | * @author Jakub PetrĹžĂlka <petrzilka@czweb.net> |
5 | | | */ |
6 | | | require_once('init.php'); |
7 | | | |
8 | | | use Phem\Core\Collection; |
9 | | | use Phem\Environment\Application; |
10 | | | use Phem\Libraries\MessageBus\MessageBus; |
11 | | | use Ratchet\Http\HttpServer; |
12 | | | use Ratchet\Server\IoServer; |
13 | | | use Ratchet\WebSocket\WsServer; |
14 | | | use React\EventLoop\Factory; |
15 | | | use React\Socket\Server; |
16 | | | |
17 | | | $loop = Factory::create(); |
18 | | | |
19 | | | $msgBus = new MessageBus(); |
20 | | | |
21 | | | // Listen for the application notifications |
22 | | | $pullerClassName = ROOT_NAMESPACE."\\Libraries\\MessageBus\\" |
23 | | | . WEBSOCKET_PULLER_MODE."Puller"; |
24 | | | if (class_exists($pullerClassName)) |
25 | | | { |
26 | | | $puller = new $pullerClassName($loop,$msgBus); |
27 | | | $puller->listen(WEBSOCKET_PULLER_BIND_ADDR,WEBSOCKET_PULLER_PORT); |
28 | | | } |
29 | | | else if (strtolower(WEBSOCKET_PULLER_MODE) != "disabled") |
30 | | | { |
31 | | | throw new Exception("Unsupported mode given by WEBSOCKET_PULLER_MODE"); |
32 | | | } |
33 | | | |
34 | | | // Listen for the websocket connections |
35 | | | $webSock = new Server($loop); |
36 | | | $webSock->listen(WEBSOCKET_PORT, WEBSOCKET_BIND_ADDR); |
37 | | | $server = new IoServer(new HttpServer(new WsServer($msgBus)), $webSock); |
38 | | | |
39 | | | // Clear previous application scope user cache |
40 | | | Application::setUsers(new Collection()); |
41 | | | |
42 | | | $loop->run(); |