public function testGetPostData()
 {
     $ortcConfig = new OrtcConfig();
     $ortcConfig->setApplicationKey('abcede');
     $ortcConfig->setPrivateKey('123456');
     $ortcConfig->setMaxChunkSize(10);
     $request = new SendMessageRequest();
     $request->setOrtcConfig($ortcConfig);
     $request->setAuthToken('wxyz123');
     $request->setMessage('{message:foo bar}');
     $request->setChannelName('channel_name');
     $postData = $request->getPostData();
     $this->assertEquals(2, count($postData));
     $this->assertEquals(5, count($postData[0]));
     $this->assertEquals('abcede', $postData[0]['AK']);
     $this->assertEquals('123456', $postData[0]['PK']);
     $this->assertEquals('wxyz123', $postData[0]['AT']);
     $this->assertEquals('channel_name', $postData[0]['C']);
     $this->assertRegExp('/^[A-Za-z0-9]{8}_1-2_\\{message:f$/', $postData[0]['M']);
     $this->assertEquals(5, count($postData[1]));
     $this->assertEquals('abcede', $postData[1]['AK']);
     $this->assertEquals('123456', $postData[1]['PK']);
     $this->assertEquals('wxyz123', $postData[1]['AT']);
     $this->assertEquals('channel_name', $postData[1]['C']);
     $this->assertRegExp('/^[A-Za-z0-9]{8}_2-2_oo bar\\}$/', $postData[1]['M']);
 }
Example #2
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());
 }
 /**
  * create OrtcConfig from laravel config
  */
 protected function createOrtcConfig(array $config)
 {
     $ortcConfig = new OrtcConfig();
     $ortcConfig->setApplicationKey($config['credentials']['application_key']);
     $ortcConfig->setPrivateKey($config['credentials']['private_key']);
     $ortcConfig->setBalancerUrl($config['api']['balancer_url']);
     $ortcConfig->setAuthenticationPath($config['api']['authentication']['path']);
     $ortcConfig->setSendPath($config['api']['send_message']['path']);
     $ortcConfig->setMaxChunkSize($config['api']['send_message']['max_chunk_size']);
     $ortcConfig->setBatchPoolSize($config['api']['send_message']['batch_pool_size']);
     $ortcConfig->setPreMessageString($config['api']['send_message']['pre_message_string']);
     $ortcConfig->setVerifySsl($config['api']['verify_ssl']);
     $this->ortcConfig = $ortcConfig;
 }
Example #4
0
<?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);