Skip to content

Commit

Permalink
Merge pull request #10 from clue-labs/heartbeat
Browse files Browse the repository at this point in the history
Support sending heart beat requests and fix invalid heart beat timezone
  • Loading branch information
clue committed May 12, 2015
2 parents a1f9c7c + ad9673a commit 1c13976
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,22 @@ public function sendInitRequest($class, $name)
)));
}

public function sendHeartBeatRequest(\DateTime $dt)
{
// TODO: legacy protocol uses a QTime, datastream protocol QDateTime
$this->send($this->protocol->writeVariantList(array(
Protocol::REQUEST_HEARTBEAT,
$dt
), array(1 => Types::TYPE_QTIME)));
}

public function sendHeartBeatReply(\DateTime $dt)
{
// legacy protocol actually uses a QTime instead of QDateTime, but accepts both
// TODO: legacy protocol uses a QTime, datastream protocol QDateTime
$this->send($this->protocol->writeVariantList(array(
Protocol::REQUEST_HEARTBEATREPLY,
$dt
)));
), array(1 => Types::TYPE_QTIME)));
}

public function sendBufferInput($bufferInfo, $input)
Expand Down
28 changes: 28 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Clue\React\Block\Blocker;
use Clue\React\Quassel\Client;
use React\Promise\Deferred;
use Clue\React\Quassel\Io\Protocol;

class FunctionalTest extends TestCase
{
Expand Down Expand Up @@ -124,6 +125,33 @@ public function testSendClientLogin(Client $client, $message)
return self::$blocker->awaitOne($deferred->promise());
}

/**
* @depends testCreateClient
*
* @param Client $client
*/
public function testSendHeartBeat(Client $client)
{
$time = new \DateTime();

$deferred = new Deferred();

$callback = function ($message) use ($deferred, &$callback, $client) {
if (isset($message[0]) && $message[0] === Protocol::REQUEST_HEARTBEATREPLY) {
$client->removeListener('message', $callback);
$deferred->resolve($message[1]);
}
};

$client->on('message', $callback);

$client->sendHeartBeatRequest($time);

$received = self::$blocker->awaitOne($deferred->promise());

$this->assertEquals($time, $received);
}

/**
* @depends testCreateClient
*/
Expand Down

0 comments on commit 1c13976

Please sign in to comment.