Download the PHP package nikapps/ortc-php without Composer
On this page you can find all versions of the php package nikapps/ortc-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ortc-php
ORTC-PHP (PHP API Client for Realtime.co)
It's an unofficial client for ORTC (Open Real-Time Connectivity, realtime & cloud-based pub/sub framework from realtime.co for PHP 5.4+), but yet powerful, composer based and compatible with psr-1, psr-2 and psr-4.
Installation
Using composer, install this package by running this command:
Configuration
Get Application Key & Private Key
First of all, you should register on realtime.co and get your api keys.
-
Login/Register at https://accounts.realtime.co
-
Create new Subscription
-
You can see your
Application Key
andPrivate Key
- If you want to use authentication, you should enable it in your panel.
Ortc Config
Before you can call any api call, you should set your credentials.
$ortcConfig = new \Nikapps\OrtcPhp\Configs\OrtcConfig();
$ortcConfig->setApplicationKey('YOUR_APPLICATION_KEY'); //you application key
$ortcConfig->setPrivateKey('YOUR_PRIVATE_KEY'); //Your private key
$ortcConfig->setVerifySsl(true); //verify ssl/tls certificate
Done!
Usage
Get Balancer URL (Manually)
This package automatically get balancer url (best available server), but if you want fetch a new balancer url manually:
$ortc = new \Nikapps\OrtcPhp\Ortc($ortcConfig);
$balancerUrl = $ortc->getBalancerUrl();
echo 'Balancer Url: ' . $balancerUrl->getUrl();
Authentication
In order to authenticate a user:
- Create channel(s):
First, you should create your channels:
$channelOne = new \Nikapps\OrtcPhp\Models\Channel();
$channelOne->setName('CHANNEL_ONE_NAME');
$ChannelOne->setPermission(Channel::PERMISSION_WRITE);
$channelTwo = new \Nikapps\OrtcPhp\Models\Channel();
$channelTwo->setName('CHANNEL_TWO_NAME');
$channelTwo->setPermission(Channel::PERMISSION_READ);
$channels = [
$channelOne,
$channelTwo
];
- Authenticate:
Then authenticate the user:
$authToken = 'YOUR_AUTH_TOKEN'; //your authentication token
$authRequest = new \Nikapps\OrtcPhp\Models\Requests\AuthRequest();
$authRequest->setAuthToken($authToken);
$authRequest->setExpireTime(5 * 60); //token ttl (expiration time) in seconds
$authRequest->setPrivate(true); //Indicates whether the authentication token is private
$authRequest->setChannels($channels);
$ortc = new \Nikapps\OrtcPhp\Ortc($ortcConfig);
$ortc->authenticate($authRequest);
Send Message (Push)
In order to push a message to a channel:
$authToken = 'YOUR_AUTH_TOKEN'; //your authentication token
$sendMessageRequest = new \Nikapps\OrtcPhp\Models\Requests\SendMessageRequest();
$sendMessageRequest->setAuthToken($authToken);
$sendMessageRequest->setChannelName('CHANNEL_NAME');
$sendMessageRequest->setMessage('YOUR_MESSAGE');
$ortc = new \Nikapps\OrtcPhp\Ortc($ortcConfig);
$ortc->sendMessage($sendMessageRequest);
If you using UTF-8 messages, it's better to use base64_encode()
.
Exceptions
- OrtcException
Parent of other exceptions
- UnauthorizedException
When token is expired or credentials are invalid
- InvalidBalancerUrlException
When balancer url is invalid
-You can get url by getUrl()
- BatchRequestException
When at least one message response is failed
-You can get all results by getResults()
. It returns a \GuzzleHttp\BatchResults
object.
- NetworkErrorException
Guzzle ClientExcpetion
-You can get guzzle exception by getClientException()
Dependencies
Ortc Documentation
This package is based on ORTC REST API. You can download REST service documentation from this url:
Also, you can download official ORTC library for PHP from this url:
Framework Integrations
- Laravel 4/5: nikapps/ortc-laravel
TODO
add UnitTest (codeception or phpunit)(Thanks to @moura137)- subscribe to channel(s) by Ratchet/Nodejs/Icicle/Amphp
- support mobile push notification (ios & android)
- support presence channels
- Anything else?!
Contribute
Wanna contribute? simply fork this project and make a pull request!
License
This project released under the MIT License.