pubnub-laravel
NOTE This is a beta release., (*1)
This is a nice, clean, OOP Laravel 4 wrapper for Pubnub's terrible php library., (*2)
All of the (useful) public methods of the base library have been wrapped and exposed with proper parameters, consistent return values, and actual exceptions instead of incomprehensible array-errors., (*3)
Two methods have not been wrapped or exposed: history()
and detailedHistory()
, because they return a completely metadata-less array of messages that isn't actually that useful., (*4)
Here are some things still to do. Got some time and a good brain? Submit a pull request!, (*5)
- [ ] Write some tests. Not sure how best to do this, we'd need to mock the Pubnub calls somehow.
- [ ] You can't work with more than one channel at once; this is a restriction of the base library, but maybe one that could be worked around?
- [ ] I'm not an expert in this sort of blocking architecture. There may be a better way to implement the
subscribe()
method, but I'm not sure what it is at this stage.
- [ ] Maybe figure out the history and detailedHistory methods.
- [ ] The
presence()
method doesn't seem to do anything, at least in my brief testing. I think it's just borken? On that note:
- [ ] Maybe stop wrapping the base library and just rewrite the whole damn thing cause seriously what is it up to.
Installing
To install, add the package to your composer.json
:, (*6)
"require" : {
...
"aura/pubnub-laravel" : "dev-master"
...
}
then run composer update
., (*7)
Add the following to your config/app.php
under 'providers'
:, (*8)
'Aura\PubnubLaravel\PubnubLaravelServiceProvider',
And then add the following to your config/app.php
under 'aliases'
:, (*9)
'Pubnub' => 'Aura\PubnubLaravel\Facades\PubnubLaravelFacade'
You'll also want to publish the config file:, (*10)
php artisan config:publish aura/pubnub-laravel
And then configure at least your 'origin'
, 'publish_key'
and 'subscriber_key'
., (*11)
Usage
To set the channel:, (*12)
Pubnub::setChannel('channel');
You can also set to channel for each method individually, as outlined below. If you try to use a method without having a channel set, a PubnubChannelException
will be thrown., (*13)
To publish a message:, (*14)
Pubnub::publish($message[, $channel]);
Returns true
on success or throws PubnubPublishFailedException
on failure., (*15)
Note This method is blocking. It will never end until there's an error, you return false from your callback, or php times out (I guess)., (*16)
To subscribe to a message:, (*17)
Pubnub::subscribe(Closure $callback[, $channel]);
Returns true
on success or throws PubnubSubscribeFailedException
on failure., (*18)
There is also a presence()
method with the same signature that is supposed to notify you of arrivals/departures in the channel you're subscribed to, but it doesn't seem to work (see note above)., (*19)
To see who's currently subscribed:, (*20)
Pubnub::hereNow([$channel]);
Returns an array of UUIDs from Pubnub., (*21)