WAMP Event Action

Added the Event action in WAMP (like SendMessage)
Confirmed subscribe, unsubscribe, publish, event working in WAMP
This commit is contained in:
Chris Boden 2012-01-16 22:54:28 -05:00
parent ad302a00d1
commit 9b14684cbe
2 changed files with 22 additions and 9 deletions

View File

@ -6,6 +6,7 @@ use Ratchet\Resource\Connection;
/**
* WebSocket Application Messaging Protocol
*
* +--------------+----+------------------+
* | Message Type | ID | DIRECTION |
* |--------------+----+------------------+
@ -63,29 +64,24 @@ class App implements WebSocketAppInterface {
break;
case 2:
$ret = $this->_app->onCall($from, $json[1], $json[2]);
return $this->_app->onCall($from, $json[1], $json[2]);
break;
case 5:
$ret = $this->_app->onSubscribe($from, $json[1]);
return $this->_app->onSubscribe($from, $json[1]);
break;
case 6:
$ret = $this->_app->onUnSubscribe($from, $json[1]);
return $this->_app->onUnSubscribe($from, $json[1]);
break;
case 7:
$ret = $this->_app->onPublish($from, $json[1], $json[2]);
return $this->_app->onPublish($from, $json[1], $json[2]);
break;
default:
throw new Exception('Invalid message type');
}
// create method to loop through $ret
// json_encode messages, return $ret back to WebSocket
return $ret;
}
public function __construct(ServerInterface $app) {

View File

@ -0,0 +1,17 @@
<?php
namespace Ratchet\Application\WAMP\Command\Action;
use Ratchet\Resource\Command\Action\SendMessage;
/**
* This is an event in the context of a topicURI
* This event (message) is to be sent to all subscribers of $uri
*/
class Event extends SendMessage {
/**
* @param ...
* @param string
*/
public function setEvent($uri, $msg) {
$this->setMessage(json_encode(array(8, $uri, (string)$msg)));
}
}