コード例 #1
0
 /**
  * authenticate user
  *
  * @param string|AuthRequest $authTokenOrAuthRequest
  * @param array $channels
  * @param int $ttl = 3600
  * @param bool $isPrivate = false
  * @throws \Nikapps\OrtcPhp\Exceptions\NetworkErrorException
  * @throws \Nikapps\OrtcPhp\Exceptions\UnauthorizedException
  * @return \Nikapps\OrtcPhp\Models\Responses\AuthResponse
  */
 public function authenticate($authTokenOrAuthRequest, $channels = [], $ttl = 3600, $isPrivate = false)
 {
     if (!$authTokenOrAuthRequest instanceof AuthRequest) {
         $authToken = $authTokenOrAuthRequest;
         $channelObjects = [];
         //create channel objects
         foreach ($channels as $channelName => $permission) {
             $channel = new Channel();
             $channel->setName($channelName);
             $channel->setPermission($permission);
             $channelObjects[] = $channel;
         }
         $authRequest = new AuthRequest();
         $authRequest->setAuthToken($authToken);
         $authRequest->setExpireTime($ttl);
         $authRequest->setPrivate($isPrivate);
         $authRequest->setChannels($channelObjects);
     } else {
         $authRequest = $authTokenOrAuthRequest;
     }
     $ortc = new Ortc($this->ortcConfig);
     return $ortc->authenticate($authRequest);
 }
コード例 #2
0
ファイル: send.php プロジェクト: nikapps/ortc-php
use Nikapps\OrtcPhp\Configs\OrtcConfig;
use Nikapps\OrtcPhp\Models\Channel;
use Nikapps\OrtcPhp\Models\Requests\AuthRequest;
use Nikapps\OrtcPhp\Models\Requests\SendMessageRequest;
use Nikapps\OrtcPhp\Ortc;
require_once '../vendor/autoload.php';
$ortcConfig = new OrtcConfig();
$ortcConfig->setApplicationKey('YOUR_APPLICATION_KEY');
$ortcConfig->setPrivateKey('YOUR_PRIVATE_KEY');
$ortcConfig->setVerifySsl(false);
$authToken = 'YOUR_AUTHENTICATION_TOKEN';
$channels = [];
$testChannel = new Channel();
$testChannel->setName('CHANNEL_NAME');
$testChannel->setPermission(Channel::PERMISSION_WRITE);
$channels[] = $testChannel;
$ortc = new Ortc($ortcConfig);
if (isset($_POST['message'])) {
    $sendMessageRequest = new SendMessageRequest();
    $sendMessageRequest->setAuthToken($authToken);
    $sendMessageRequest->setChannelName($testChannel->getName());
    $sendMessageRequest->setMessage($_POST['message']);
    $ortc->sendMessage($sendMessageRequest);
} else {
    $authRequest = new AuthRequest();
    $authRequest->setAuthToken($authToken);
    $authRequest->setExpireTime(5 * 60);
    $authRequest->setPrivate(true);
    $authRequest->setChannels($channels);
    $authResponse = $ortc->authenticate($authRequest);
コード例 #3
0
ファイル: client.php プロジェクト: nikapps/ortc-php
use Nikapps\OrtcPhp\Models\Channel;
use Nikapps\OrtcPhp\Models\Requests\AuthRequest;
use Nikapps\OrtcPhp\Ortc;
require_once '../vendor/autoload.php';
$ortcConfig = new OrtcConfig();
$ortcConfig->setApplicationKey('YOUR_APPLICATION_KEY');
$ortcConfig->setPrivateKey('YOUR_PRIVATE_KEY');
$ortcConfig->setVerifySsl(false);
$url = 'http://ortc-developers.realtime.co/server/2.1';
// ORTC server URL
//$authToken = Rhumsaa\Uuid\Uuid::uuid4()->toString();
$authToken = 'YOUR_AUTHENTICATION_TOKEN';
$channels = [];
$testChannel = new Channel();
$testChannel->setName('CHANNEL_NAME');
$testChannel->setPermission(Channel::PERMISSION_READ);
$channels[] = $testChannel;
$ortc = new Ortc($ortcConfig);
$authRequest = new AuthRequest();
$authRequest->setAuthToken($authToken);
$authRequest->setExpireTime(61);
$authRequest->setPrivate(true);
$authRequest->setChannels($channels);
$authResponse = $ortc->authenticate($authRequest);
?>
<!doctype html>
<html>
<head>
    <title></title>
</head>
<body>