Exemplo n.º 1
0
 public function testAttributePrivate()
 {
     $request = new AuthRequest();
     $this->assertFalse($request->isPrivate());
     $request->setPrivate(1);
     $this->assertTrue($request->isPrivate());
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
$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/>
    <input type="submit" value="Send to channel"/>