WAMP Codes

Changed the WAMP codes back into constants.
Added the new Welcome constant (not yet implemented)
This commit is contained in:
Chris Boden 2012-01-20 17:48:35 -05:00
parent 4372f9a8c3
commit aceb2c9006
5 changed files with 24 additions and 9 deletions

View File

@ -23,8 +23,19 @@ use Ratchet\Application\WAMP\Command\Action\Prefix;
* | EVENT | 8 | Server-to-Client |
* +--------------+----+------------------+
* @link http://www.tavendo.de/autobahn/protocol.html
* @link https://raw.github.com/oberstet/Autobahn/master/lib/javascript/autobahn.js
*/
class App implements WebSocketAppInterface {
const MSG_WELCOME = 0;
const MSG_PREFIX = 1;
const MSG_CALL = 2;
const MSG_CALL_RESULT = 3;
const MSG_CALL_ERROR = 4;
const MSG_SUBSCRIBE = 5;
const MSG_UNSUBSCRIBE = 6;
const MSG_PUBLISH = 7;
const MSG_EVENT = 8;
protected $_app;
/**
@ -81,11 +92,11 @@ class App implements WebSocketAppInterface {
}
switch ($json[0]) {
case 1:
case static::MSG_PREFIX:
$ret = $this->addPrefix($from, $json[1], $json[2]);
break;
case 2:
case static::MSG_CALL:
array_shift($json);
$callID = array_shift($json);
$procURI = array_shift($json);
@ -97,15 +108,15 @@ class App implements WebSocketAppInterface {
$ret = $this->_app->onCall($from, $callID, $procURI, $json);
break;
case 5:
case static::MSG_SUBSCRIBE:
$ret = $this->_app->onSubscribe($from, $this->getUri($from, $json[1]));
break;
case 6:
case static::MSG_UNSUBSCRIBE:
$ret = $this->_app->onUnSubscribe($from, $this->getUri($from, $json[1]));
break;
case 7:
case static::MSG_PUBLISH:
$ret = $this->_app->onPublish($from, $this->getUri($from, $json[1]), $json[2]);
break;

View File

@ -1,6 +1,7 @@
<?php
namespace Ratchet\Application\WAMP\Command\Action;
use Ratchet\Resource\Command\Action\SendMessage;
use Ratchet\Application\WAMP\App as WAMP;
class CallError extends SendMessage {
protected $_id;
@ -14,7 +15,7 @@ class CallError extends SendMessage {
$this->_uri = $uri;
$this->_desc = $desc;
return $this->setMessage(json_encode(array(4, $callId, $uri, $desc)));
return $this->setMessage(json_encode(array(WAMP::MSG_CALL_ERROR, $callId, $uri, $desc)));
}
public function getId() {

View File

@ -1,6 +1,7 @@
<?php
namespace Ratchet\Application\WAMP\Command\Action;
use Ratchet\Resource\Command\Action\SendMessage;
use Ratchet\Application\WAMP\App as WAMP;
/**
*/
@ -13,7 +14,7 @@ class CallResult extends SendMessage {
$this->_id = $callId;
$this->_data = $data;
return $this->setMessage(json_encode(array(3, $callId, $data)));
return $this->setMessage(json_encode(array(WAMP::MSG_CALL_RESULT, $callId, $data)));
}
public function getId() {

View File

@ -1,6 +1,7 @@
<?php
namespace Ratchet\Application\WAMP\Command\Action;
use Ratchet\Resource\Command\Action\SendMessage;
use Ratchet\Application\WAMP\App as WAMP;
/**
* This is an event in the context of a topicURI
@ -13,6 +14,6 @@ class Event extends SendMessage {
* @return Event
*/
public function setEvent($uri, $msg) {
return $this->setMessage(json_encode(array(8, $uri, (string)$msg)));
return $this->setMessage(json_encode(array(WAMP::MSG_EVENT, $uri, (string)$msg)));
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace Ratchet\Application\WAMP\Command\Action;
use Ratchet\Resource\Command\Action\SendMessage;
use Ratchet\Application\WAMP\App as WAMP;
/**
* Send a curie to uri mapping to the client
@ -20,7 +21,7 @@ class Prefix extends SendMessage {
$this->_curie = $curie;
$this->_uri = $uri;
return $this->setMessage(json_encode(array(1, $curie, $uri)));
return $this->setMessage(json_encode(array(WAMP::MSG_PREFIX, $curie, $uri)));
}
/**