| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
namespace Ratchet\Wamp;
|
|
|
3 |
use Ratchet\MessageComponentInterface;
|
|
|
4 |
use Ratchet\WebSocket\WsServerInterface;
|
|
|
5 |
use Ratchet\ConnectionInterface;
|
|
|
6 |
|
|
|
7 |
/**
|
|
|
8 |
* Enable support for the official WAMP sub-protocol in your application
|
|
|
9 |
* WAMP allows for Pub/Sub and RPC
|
|
|
10 |
* @link http://wamp.ws The WAMP specification
|
|
|
11 |
* @link https://github.com/oberstet/autobahn-js Souce for client side library
|
|
|
12 |
* @link http://autobahn.s3.amazonaws.com/js/autobahn.min.js Minified client side library
|
|
|
13 |
*/
|
|
|
14 |
class WampServer implements MessageComponentInterface, WsServerInterface {
|
|
|
15 |
/**
|
|
|
16 |
* @var ServerProtocol
|
|
|
17 |
*/
|
|
|
18 |
protected $wampProtocol;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* This class just makes it 1 step easier to use Topic objects in WAMP
|
|
|
22 |
* If you're looking at the source code, look in the __construct of this
|
|
|
23 |
* class and use that to make your application instead of using this
|
|
|
24 |
*/
|
|
|
25 |
public function __construct(WampServerInterface $app) {
|
|
|
26 |
$this->wampProtocol = new ServerProtocol(new TopicManager($app));
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* {@inheritdoc}
|
|
|
31 |
*/
|
|
|
32 |
public function onOpen(ConnectionInterface $conn) {
|
|
|
33 |
$this->wampProtocol->onOpen($conn);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* {@inheritdoc}
|
|
|
38 |
*/
|
|
|
39 |
public function onMessage(ConnectionInterface $conn, $msg) {
|
|
|
40 |
try {
|
|
|
41 |
$this->wampProtocol->onMessage($conn, $msg);
|
|
|
42 |
} catch (Exception $we) {
|
|
|
43 |
$conn->close(1007);
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* {@inheritdoc}
|
|
|
49 |
*/
|
|
|
50 |
public function onClose(ConnectionInterface $conn) {
|
|
|
51 |
$this->wampProtocol->onClose($conn);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* {@inheritdoc}
|
|
|
56 |
*/
|
|
|
57 |
public function onError(ConnectionInterface $conn, \Exception $e) {
|
|
|
58 |
$this->wampProtocol->onError($conn, $e);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* {@inheritdoc}
|
|
|
63 |
*/
|
|
|
64 |
public function getSubProtocols() {
|
|
|
65 |
return $this->wampProtocol->getSubProtocols();
|
|
|
66 |
}
|
|
|
67 |
}
|