Skip to content

Commit

Permalink
Improved disclose_publisher compatibility with autobahnjs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwdan authored and mbonneau committed Nov 2, 2015
1 parent 2b787d9 commit a8e9cfa
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 45 deletions.
24 changes: 17 additions & 7 deletions src/Thruway/Message/EventMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class EventMessage extends Message
*/
private $publicationId;

/**
* @var
*/
private $topic;

/**
* Constructor
*
Expand All @@ -38,14 +43,16 @@ class EventMessage extends Message
* @param \stdClass $details
* @param mixed $arguments
* @param mixed $argumentsKw
* @param null $topic
*/
public function __construct($subscriptionId, $publicationId, $details, $arguments = null, $argumentsKw = null)
public function __construct($subscriptionId, $publicationId, $details, $arguments = null, $argumentsKw = null, $topic = null)
{
$this->setArguments($arguments);
$this->setArgumentsKw($argumentsKw);
$this->setDetails($details);
$this->setPublicationId($publicationId);
$this->setSubscriptionId($subscriptionId);
$this->topic = $topic;
}

/**
Expand Down Expand Up @@ -81,11 +88,12 @@ public function getAdditionalMsgFields()
public static function createFromPublishMessage(PublishMessage $msg, $subscriptionId)
{
return new static(
$subscriptionId,
$msg->getPublicationId(),
new \stdClass(),
$msg->getArguments(),
$msg->getArgumentsKw()
$subscriptionId,
$msg->getPublicationId(),
new \stdClass(),
$msg->getArguments(),
$msg->getArgumentsKw(),
$msg->getTopicName()
);
}

Expand Down Expand Up @@ -136,7 +144,8 @@ public function disclosePublisher(Session $session)
{

$details = $this->getDetails();
$details->caller = $session->getSessionId();
$details->publisher = $session->getSessionId();
$details->topic = $this->topic;
$details->authid = $session->getAuthenticationDetails()->getAuthId();
$details->authrole = $session->getAuthenticationDetails()->getAuthRole();
$details->authroles = $session->getAuthenticationDetails()->getAuthRoles();
Expand All @@ -150,6 +159,7 @@ public function disclosePublisher(Session $session)
public function isRestoringState()
{
$restoringState = isset($this->getDetails()->_thruway_restoring_state) ? $this->getDetails()->_thruway_restoring_state : false;

return $restoringState;
}

Expand Down
80 changes: 42 additions & 38 deletions tests/WAMP/DisclosePublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class DisclosePublisherTest extends PHPUnit_Framework_TestCase
protected $_testAuthId;
protected $_testAuthMethod;
protected $_testAuthRole;
protected $_testTopic;


public function setUp()
Expand All @@ -23,17 +24,18 @@ public function setUp()
$this->_testAuthId = null;
$this->_testAuthMethod = null;
$this->_testAuthRole = null;
$this->_testTopic = null;

$challenge = function ($session, $method) {
return "letMeIn";
};

$options = [
"realm" => 'testSimpleAuthRealm',
"url" => 'ws://127.0.0.1:8090',
"max_retries" => 0,
"authmethods" => ["simplysimple"],
"onChallenge" => $challenge
"realm" => 'testSimpleAuthRealm',
"url" => 'ws://127.0.0.1:8090',
"max_retries" => 0,
"authmethods" => ["simplysimple"],
"onChallenge" => $challenge
];

$this->_conn = new \Thruway\Connection($options);
Expand All @@ -45,41 +47,42 @@ public function testSubscribe()

$this->_conn->on('open', function (\Thruway\ClientSession $session) {

/**
* Subscribe to event
*/
$session->subscribe('com.example.publish',
function ($args, $kwargs = null, $details, $publicationId = null) {

$this->_testArgs = $args;
$this->_testPublisherId = $details->publisher;
$this->_testTopic = $details->topic;
$this->_testAuthId = $details->authid;
$this->_testAuthMethod = $details->authmethod;
$this->_testAuthRole = $details->authroles;

},
['disclose_publisher' => true]
)->then(function () use ($session) {
/**
* Subscribe to event
* Tell the server to publish
*/
$session->subscribe('com.example.publish',
function ($args, $kwargs = null, $details, $publicationId = null) {

$this->_testArgs = $args;
$this->_testPublisherId = $details->caller;
$this->_testAuthId = $details->authid;
$this->_testAuthMethod = $details->authmethod;
$this->_testAuthRole = $details->authroles;

},
['disclose_publisher' => true]
)->then(function () use ($session) {
/**
* Tell the server to publish
*/
$session->call('com.example.publish', ['test publish'])->then(
function ($res) {
$this->_testResult = $res;

},
function ($error) {
$this->_conn->close();
$this->_error = $error;
})->then(function () use ($session) {
$session->close();
});
},
function () use ($session) {
$session->close();
throw new Exception("subscribe failed.");
});
}
$session->call('com.example.publish', ['test publish'])->then(
function ($res) {
$this->_testResult = $res;

},
function ($error) {
$this->_conn->close();
$this->_error = $error;
})->then(function () use ($session) {
$session->close();
});
},
function () use ($session) {
$session->close();
throw new Exception("subscribe failed.");
});
}
);


Expand All @@ -90,5 +93,6 @@ function () use ($session) {
$this->assertNotEmpty($this->_testPublisherId);
$this->assertEquals("anonymous", $this->_testAuthId);
$this->assertEquals("internalClient", $this->_testAuthMethod);
$this->assertEquals('com.example.publish', $this->_testTopic);
}
}

0 comments on commit a8e9cfa

Please sign in to comment.