Exemplo n.º 1
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]);
 }
 /**
  * {@inheritdoc}
  */
 public function broadcast(array $channels, $event, array $payload = array())
 {
     $payload = ['event' => $event, 'data' => $payload];
     foreach ($channels as $channel) {
         $this->pubnub->publish($channel, $payload);
     }
 }
 /**
  * Publish new message on given channel.
  *
  * @param  string $channel
  * @param  mixed $message
  * @return bool
  */
 public function publish($channel, $message)
 {
     $result = $this->pubnub->publish($channel, $message);
     if (isset($result['error'])) {
         throw new Exception('PubNub error: ' . $result['message']);
     }
     return $result[1] === 'Sent';
 }
Exemplo n.º 4
0
 /**
  * @group history
  */
 public function testHistoryEncodedMessagesMultipleLevel()
 {
     $pubnub = new Pubnub(array('publish_key' => 'demo', 'subscribe_key' => 'demo', 'cipher_key' => 'blah'));
     $m1 = static::$message . time();
     $m2 = static::$message_2 . time();
     $m3 = static::$message . time();
     $m4 = static::$message_2 . time();
     $ary1 = array('first' => $m1, 'second' => $m2);
     $ary2 = array('third' => $m3, 'fourth' => $m4);
     $pubnub->publish($this->channel, $ary1);
     $pubnub->publish($this->channel, $ary2);
     sleep(1);
     $response = $pubnub->history($this->channel, 2);
     $this->assertEquals($ary1, $response['messages'][count($response['messages']) - 2]);
     $this->assertEquals($ary2, $response['messages'][count($response['messages']) - 1]);
 }
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
## ---------------------------------------------------------------------------
#
# 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.º 8
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.º 9
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.º 10
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);
Exemplo n.º 11
0
$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);
    }
    return utf8_encode($bits);
}
while (1) {
    $message = getRandom();
    $t = time();
    $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => $t . " " . $message . " END"));
    echo $t . " " . $publish_success[0] . " " . $publish_success[1];
    echo "\r\n";
}
Exemplo n.º 12
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);
 }