WAMP Prefixes

WAMP Client to server prefixes and transparent interpretation to application working
This commit is contained in:
Chris Boden 2012-01-17 21:05:32 -05:00
parent b2e4578e19
commit eb82a7ab04

View File

@ -31,13 +31,13 @@ class App implements WebSocketAppInterface {
/** /**
* @todo WAMP spec does not say what to do when there is an error with PREFIX... * @todo WAMP spec does not say what to do when there is an error with PREFIX...
*/ */
public function addPrefix(Connection $conn, $uri, $curie) { public function addPrefix(Connection $conn, $curie, $uri) {
// validate uri // validate uri
// validate curie // validate curie
// make sure the curie is shorter than the uri // make sure the curie is shorter than the uri
$conn->prefixes[$uri] = $curie; $conn->WAMP->prefixes[$curie] = $uri;
} }
public function onOpen(Connection $conn) { public function onOpen(Connection $conn) {
@ -60,7 +60,7 @@ class App implements WebSocketAppInterface {
switch ($json[0]) { switch ($json[0]) {
case 1: case 1:
return $this->addPrefix($conn, $json[2], $json[1]); return $this->addPrefix($from, $json[1], $json[2]);
break; break;
case 2: case 2:
@ -70,15 +70,15 @@ class App implements WebSocketAppInterface {
break; break;
case 5: case 5:
return $this->_app->onSubscribe($from, $json[1]); return $this->_app->onSubscribe($from, $this->getUri($from, $json[1]));
break; break;
case 6: case 6:
return $this->_app->onUnSubscribe($from, $json[1]); return $this->_app->onUnSubscribe($from, $this->getUri($from, $json[1]));
break; break;
case 7: case 7:
return $this->_app->onPublish($from, $json[1], $json[2]); return $this->_app->onPublish($from, $this->getUri($from, $json[1]), $json[2]);
break; break;
default: default:
@ -86,6 +86,16 @@ class App implements WebSocketAppInterface {
} }
} }
/**
* Get the full request URI from the connection object if a prefix has been established for it
* @param Ratchet\Resource\Connection
* @param ...
* @return string
*/
protected function getUri(Connection $conn, $uri) {
$ret = (isset($conn->WAMP->prefixes[$uri]) ? $conn->WAMP->prefixes[$uri] : $uri);
}
public function __construct(ServerInterface $app) { public function __construct(ServerInterface $app) {
$this->_app = $app; $this->_app = $app;
} }