Exemplo n.º 1
3
<?php

require_once __DIR__ . '/../lib/autoloader.php';
use Pubnub\Pubnub;
$publish_key = isset($argv[1]) ? $argv[1] : 'demo';
$subscribe_key = isset($argv[2]) ? $argv[2] : 'demo';
$secret_key = isset($argv[3]) ? $argv[3] : false;
$cipher_key = isset($argv[4]) ? $argv[4] : false;
$ssl_on = false;
## Create Pubnub Object
$pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on, 'IUNDERSTAND.pubnub.com');
## Define Messaging Channel
$channel = "php_exit";
## Subscribe Example
echo "\nWaiting for Publish message... Hit CTRL+C to finish.\n";
$pubnub->subscribe(array('channel' => $channel, 'callback' => function ($message) {
    print_r($message);
    echo "\r\n";
    return false;
}));
Exemplo n.º 2
1
 /**
  * @group gzip
  */
 public function testEnableGzipCompression()
 {
     $pubnub = new Pubnub(array_merge(static::$keys, array('gzip' => true)));
     $response = $pubnub->publish(static::$channel, static::$message);
     $this->assertEquals(1, $response[0]);
     $this->assertEquals('Sent', $response[1]);
     $this->assertGreaterThan(1400688897 * 10000000, $response[2]);
 }
Exemplo n.º 3
0
 /**
  * Remove generated namespaces and groups
  */
 public static function cleanup()
 {
     $pn = new Pubnub(static::$keys);
     $result = $pn->channelGroupListGroups();
     $groups = $result["payload"]["groups"];
     foreach ($groups as $groupName) {
         // WARNING: Check $groups for temporary generated groups if some tests fails.
         if (strpos($groupName, 'ptest') !== false) {
             $result = $pn->channelGroupRemoveGroup($groupName);
             if ($result['message'] === "OK") {
                 //                    print_r("Successfully removed group " . $groupName . "\n");
             }
         }
     }
     $result = $pn->channelGroupListNamespaces();
     $namespaces = $result["payload"]["namespaces"];
     foreach ($namespaces as $namespace) {
         if (strpos($namespace, 'ptest') !== false) {
             $result = $pn->channelGroupRemoveNamespace($namespace);
             if ($result['message'] === "OK") {
                 //                    print_r("Successfully removed namespace " . $namespace . "\n");
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function broadcast(array $channels, $event, array $payload = array())
 {
     $payload = ['event' => $event, 'data' => $payload];
     foreach ($channels as $channel) {
         $this->pubnub->publish($channel, $payload);
     }
 }
Exemplo n.º 5
0
 /**
  * @group ssl
  */
 public function testDisableSSLPeerVerification()
 {
     $pubnub = new Pubnub(array('subscribe_key' => 'demo', 'publish_key' => 'demo', 'origin' => 'pubsub.pubnub.com', 'ssl' => true, 'verify_peer' => false));
     $response = $pubnub->publish(static::$channel, static::$message);
     $this->assertEquals(1, $response[0]);
     $this->assertEquals('Sent', $response[1]);
     $this->assertGreaterThan(1400688897 * 10000000, $response[2]);
 }
Exemplo n.º 6
0
 /**
  * @group ssl
  */
 public function testDisableSSLPeerVerification()
 {
     $pubnub = new Pubnub(array_merge(static::$keys, array('ssl' => true, 'verify_peer' => false)));
     $response = $pubnub->publish(static::$channel, static::$message);
     $this->assertEquals(1, $response[0]);
     $this->assertEquals('Sent', $response[1]);
     $this->assertGreaterThan(1400688897 * 10000000, $response[2]);
 }
Exemplo n.º 7
0
 public function __invoke(ClosureDaemon $daemon)
 {
     $this->daemon = $daemon;
     $camera = $this->gopro;
     $darkroom = $this->darkroom;
     error_log('subscribed to channel: ' . $this->channel);
     $this->pubnub->subscribe($this->channel, [$this, 'process']);
     return $this->daemon->run;
 }
Exemplo n.º 8
0
 /**
  * @group subscribe
  * @group subscribe-errors
  */
 public function testSubscribeWithInvalidCredentials()
 {
     $test = $this;
     $pubnub = new Pubnub("invalid", "credentials");
     $pubnub->subscribe("error_test", function ($response) use($test) {
         $test->assertTrue($response['error']);
         $test->assertEquals("Invalid Subscribe Key", $response['message']);
         return false;
     });
 }
Exemplo n.º 9
0
 protected function subscribeAtPubnub()
 {
     if (!$this->alive()) {
         throw new Exception('Subscription is not alive');
     }
     $this->_pubnub = $this->_pubnubFactory->pubnub(array('publish_key' => 'convince-pubnub-its-okay', 'subscribe_key' => $this->_subscription['deliveryMode']['subscriberKey']));
     $this->_pubnub->subscribe($this->_subscription['deliveryMode']['address'], array($this, 'notify'));
     return $this;
 }
Exemplo n.º 10
0
 protected function subscribeAtPubnub()
 {
     if (!$this->alive()) {
         throw new Exception('Subscription is not alive');
     }
     $this->_pubnub = $this->_pubnubFactory->pubnub(array('publish_key' => 'convince-pubnub-its-okay', 'subscribe_key' => $this->_subscription['deliveryMode']['subscriberKey']));
     $this->_pubnub->setSubscribeTimeout(self::SUBSCRIBE_TIMEOUT);
     $this->_pubnub->subscribe($this->_subscription['deliveryMode']['address'], array($this, 'notify'), 0, false, array($this, 'pubnubTimeoutHandler'));
     return $this;
 }
Exemplo n.º 11
0
 protected function subscribeAtPubnub()
 {
     if (!$this->isSubscribed()) {
         return $this;
     }
     $this->pubnub = $this->pubnubFactory->getPubnub(array('publish_key' => 'convince-pubnub-its-okay', 'subscribe_key' => $this->subscription['deliveryMode']['subscriberKey']));
     //print 'PUBNUB object created' . PHP_EOL;
     $this->pubnub->subscribe($this->subscription['deliveryMode']['address'], array($this, 'notify'));
     //print 'PUBNUB subscription created' . PHP_EOL;
     return $this;
 }
Exemplo n.º 12
0
<?php

require_once 'autoloader.php';
use Pubnub\Pubnub;
// Create Pubnub Object
$pubnub = new Pubnub('pub-c-a9afac0f-597a-4d95-a975-83b16220f02b', 'sub-c-2023456c-d1a2-11e5-bcee-0619f8945a4f', false, false, false, 'IUNDERSTAND.pubnub.com');
// Define Messaging Channel
$channel = $_REQUEST['auth_code'];
echo "\nWaiting for Publish message... Hit CTRL+C to finish.\n";
$pubnub->subscribe($channel, function ($message) {
    print_r($message);
    echo "\r\n";
    flush();
    ob_flush();
    return true;
});
Exemplo n.º 13
0
<?php

require 'vendor/autoload.php';
use Pubnub\Pubnub;
$pubnub = new Pubnub("pub-c-c22bf29d-2eba-48c2-84f5-1946ed66539e", "sub-c-2556ee06-7916-11e5-9720-0619f8945a4f", "client0001");
$pubnub->subscribe('hello_world', function ($envelope) {
    $msg = $envelope['message'];
    print_r($envelope);
    if (strcmp($msg, "exit") == 0) {
        print_r('<<< So long, and thanks for all the messages! >>>');
        return false;
    } else {
        print_r('>>> May I have some more message, please? <<<');
        return true;
    }
});
Exemplo n.º 14
0
## USAGE:
## ---------------------------------------------------------------------------
#
# php ./pubnubPlaintextTests.php
# php ./pubnubPlaintextTests.php [PUB-KEY] [SUB-KEY] [SECRET-KEY] [CIPHER-KEY] [USE SSL]
#
## Capture Publish and Subscribe Keys from Command Line
$publish_key = isset($argv[1]) ? $argv[1] : 'demo';
$subscribe_key = isset($argv[2]) ? $argv[2] : 'demo';
$secret_key = isset($argv[3]) ? $argv[3] : false;
$cipher_key = isset($argv[4]) ? $argv[4] : false;
$ssl_on = false;
## ---------------------------------------------------------------------------
## Create Pubnub Object
## ---------------------------------------------------------------------------
$pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on, 'IUNDERSTAND.pubnub.com');
## ---------------------------------------------------------------------------
## Define Messaging Channel
## ---------------------------------------------------------------------------
$channel = "php_ping";
## ---------------------------------------------------------------------------
## Publish Example
## ---------------------------------------------------------------------------
echo "Running publish\r\n";
while (1) {
    $t = time() . "";
    $m = array("serial" => $t, "message" => "Hello from PHP! " . $t);
    $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => $m));
    echo $t . " " . $publish_success[0] . " " . $publish_success[1];
    echo "\r\n";
    sleep(1);
Exemplo n.º 15
0
<?php

require_once "vendor/autoload.php";
use Pubnub\Pubnub;
$config = ['publish_key' => 'demo', 'subscribe_key' => 'demo'];
if ($_GET['ssl'] == 'true') {
    $config['ssl'] = true;
    $config['pem_path'] = "./";
}
if (!empty($_GET['cipher_key'])) {
    $config['cipher_key'] = $_GET['cipher_key'];
}
$pubnub = new Pubnub($config);
$message = $_GET['message'];
if (empty($message)) {
    $message = "<empty message>";
}
$pubnub->publish("gae-php-console", $message);
Exemplo n.º 16
0
 /**
  * @group wc
  */
 public function testSubscribeWhenOnlySubscribe()
 {
     $this->assertTrue(Pubnub::shouldWildcardMessageBePassedToUserCallback("foo.bar", "foo.*", array("foo.*"), array(), $this->logger));
 }
Exemplo n.º 17
0
## USAGE:
## ---------------------------------------------------------------------------
#
# php ./pubnubPlaintextTests.php
# php ./pubnubPlaintextTests.php [PUB-KEY] [SUB-KEY] [SECRET-KEY] [CIPHER-KEY] [USE SSL]
#
## Capture Publish and Subscribe Keys from Command Line
$publish_key = isset($argv[1]) ? $argv[1] : 'demo';
$subscribe_key = isset($argv[2]) ? $argv[2] : 'demo';
$secret_key = isset($argv[3]) ? $argv[3] : false;
$cipher_key = isset($argv[4]) ? $argv[4] : false;
$ssl_on = false;
## ---------------------------------------------------------------------------
## Create Pubnub Object
## ---------------------------------------------------------------------------
$pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on, 'IUNDERSTAND.pubnub.com');
## ---------------------------------------------------------------------------
## Define Messaging Channel
## ---------------------------------------------------------------------------
$channel = "php_noise";
## ---------------------------------------------------------------------------
## Publish Example
## ---------------------------------------------------------------------------
echo "Running publish\r\n";
function getRandom()
{
    $bits = '';
    $fp = @fopen('/dev/urandom', 'rb');
    if ($fp !== FALSE) {
        $bits .= @fread($fp, 300);
        @fclose($fp);
Exemplo n.º 18
0
<?php

require_once 'vendor/autoload.php';
use Pubnub\Pubnub;
$pubnub = new Pubnub("pub-c-c22bf29d-2eba-48c2-84f5-1946ed66539e", "sub-c-2556ee06-7916-11e5-9720-0619f8945a4f", "sec-c-MDEyMjA1MTUtODY2YS00YmI1LTlhNGItYTFiZWFjNmVhY2Y2");
$key = "05c1fa9341e3a754ba4b";
$pubnub->grant(true, true, "device_add", $key, 0);
$pubnub->grant(true, true, "device_delete", $key, 0);
Exemplo n.º 19
0
 /**
  * @group history
  */
 public function testHistoryErrorWithWrongKeys()
 {
     $pubnub = new Pubnub(array('publish_key' => 'asdf', 'subscribe_key' => 'qwer'));
     $result = $pubnub->history('channelName');
     $this->assertEquals(400, $result['status']);
     $this->assertEquals(1, $result['error']);
     $this->assertEquals('Invalid Subscribe Key', $result['message']);
 }
Exemplo n.º 20
0
// Get credentials
require_once __DIR__ . '/db.php';
// Get PubNub client
require_once 'autoloader.php';
use Pubnub\Pubnub;
$auth_code = $_REQUEST['auth_code'];
$current_view = $_REQUEST['current_view'];
try {
    // Get the new device_id
    $dbh = new PDO("mysql:host={$mysql_hostname};dbname={$mysql_dbname}", $mysql_username, $mysql_password);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $dbh->prepare("SELECT status, device_id, key_code FROM devices WHERE auth_code = :auth_code");
    $stmt->bindParam(':auth_code', $auth_code, PDO::PARAM_STR);
    $stmt->execute();
    $status = $stmt->fetchColumn();
    $device_id = $stmt->fetchColumn(1);
    $key_code = $stmt->fetchColumn(2);
} catch (Exception $e) {
    die('{"success": false, "message": "' . $e . '"}');
}
// Add an HTTP call to OAuth2 to verify the $key_code
// Record session if one is not already open
// Update session if one is open with current_view
// PubNub
$pubnub = new Pubnub('pub-c-a9afac0f-597a-4d95-a975-83b16220f02b', 'sub-c-2023456c-d1a2-11e5-bcee-0619f8945a4f');
// Use the publish command separately from the Subscribe code shown above.
// Subscribe is not async and will block the execution until complete.
$hereNow = $pubnub->hereNow($auth_code);
print_r($hereNow);
$publish_result = $pubnub->publish($auth_code, $current_view);
print_r($publish_result);
 /**
  * Subscribe to given channel.
  *
  * @param  string $channel
  * @param  Closure $callback
  * @return void
  */
 public function subscribe($channel, Closure $callback)
 {
     $this->pubnub->subscribe($channel, $callback);
 }
Exemplo n.º 22
0
 /**
  * @group pam
  * @group pam-user
  */
 public function testNewInstancesWithAuthKey()
 {
     $this->pubnub_secret->grant(1, 1, $this->channel, 'admin_key', 10);
     $this->pubnub_secret->grant(1, 0, $this->channel, 'user_key', 10);
     $this->pubnub_secret->grant(0, 0, $this->channel, null, 10);
     $nonAuthorizedClient = new Pubnub(array('subscribe_key' => self::$subscribe, 'publish_key' => self::$publish));
     $authorizedClient = new Pubnub(array('subscribe_key' => self::$subscribe, 'publish_key' => self::$publish, 'auth_key' => 'admin_key'));
     $authorizedResponse = $authorizedClient->publish($this->channel, 'hi');
     $nonAuthorizedResponse = $nonAuthorizedClient->publish($this->channel, 'hi');
     $this->assertEquals(1, $authorizedResponse[0]);
     $this->assertEquals(403, $nonAuthorizedResponse['status']);
     $nonAuthorizedClient->setAuthKey('admin_key');
     $nonAuthorizedResponse = $nonAuthorizedClient->publish($this->channel, 'hi');
     $this->assertEquals(1, $nonAuthorizedResponse[0]);
 }
Exemplo n.º 23
0
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     $this->eventDispatcher = new EventDispatcher();
 }
 /**
  * @group complex-parsing
  */
 public function testSubscribeChannelGroupMessage()
 {
     $this->assertTrue(Pubnub::shouldComplexMessageBePassedToUserCallback("foo", "bar", array(), array(), array("bar"), $this->logger));
 }
Exemplo n.º 25
0
<?php

require_once __DIR__ . '/../lib/autoloader.php';
use Pubnub\Pubnub;
$pubnub = new Pubnub('demo', 'demo', false, false, false, 'IUNDERSTAND.pubnub.com');
$here = $pubnub->here_now(array('channel' => 'php_here_now'));
$occupancy = $here['occupancy'];
$user_ids = $here['uuids'];
print "UUIDs (userIDs): ";
print_r($user_ids);
print "\n";
print "OCCUPANTS: {$occupancy}\n\n";
Exemplo n.º 26
0
 public function takePhoto($number, $callid, $optional = array())
 {
     $data = array_merge($optional, ['session' => $callid, 'number' => $number]);
     error_log('sending to: ' . $this->channel);
     $this->pubnub->publish($this->channel, $data);
 }