コード例 #1
0
ファイル: PushClient.php プロジェクト: bazo/phpusher
 /**
  * Emit an event
  * @param string $room
  * @param string $event
  * @param array $data
  * @return \Bazo\PHPusher\PHPusher
  */
 public function push($room, $event, array $data)
 {
     if ($this->connected === false) {
         throw new NotConnectedException('You need to connect to server before pushing events.');
     }
     $payload = ['room' => $room, 'event' => $event, 'data' => $data, 'timestamp' => time()];
     if ($this->key !== NULL) {
         $signature = hash_hmac('md5', json_encode($payload), $this->key);
         $payload['signature'] = $signature;
     }
     $this->client->emit('push', $payload);
     return $this;
 }
コード例 #2
0
ファイル: client.php プロジェクト: bazo/phpusher
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Tembo\SocketIOClient;
use Tembo\Message;
$client = new SocketIOClient('http://localhost:8080');
$client->connect();
$client->emit('subscribe', ['room' => 'test']);
try {
    $client->listen(function ($event, Message $message = null) {
        if ($message !== null) {
            $args = current($message->getArgs());
            $msg = sprintf('%s: event: %s, message: %s', date('H:i:s', $args->timestamp), $message->getName(), $args->message);
            echo $msg . "\n";
        }
    });
} catch (\RuntimeException $e) {
    echo $e->getMessage();
}