Beispiel #1
0
 public function testGetPostData()
 {
     $ortcConfig = new OrtcConfig();
     $ortcConfig->setApplicationKey('abcede');
     $ortcConfig->setPrivateKey('123456');
     $request = new AuthRequest();
     $request->setOrtcConfig($ortcConfig);
     $request->setAuthToken('wxyz123');
     $request->setExpireTime(3600);
     $request->setChannels([new Channel('channel1', 'r'), new Channel('channel2', 'w')]);
     $expected = ['AT' => 'wxyz123', 'PVT' => 0, 'AK' => 'abcede', 'TTL' => 3600, 'PK' => '123456', 'TP' => 2, 'channel1' => 'r', 'channel2' => 'w'];
     $this->assertEquals($expected, $request->getPostData());
 }
 /**
  * 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);
 }
Beispiel #3
0
$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);
}
?>
<!doctype html>
<html>
<head>
    <title>Send Message</title>
</head>
<body>
<form action="send.php" method="post">
    <label for="message">Message: </label><br/>
    <textarea id="message" name="message"></textarea>
    <br/>
Beispiel #4
0
$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>
<input type="text" id="message"/>
<input type="button" onclick="sendMessage('<?php 
echo $testChannel->getName();
?>
');" value="Send to myChannel"/>