socketbus / socketbus-php
There is no license information available for the latest version (v1.0.1) of this package.
v1.0.1
2021-01-06 21:05 UTC
Requires
- php: >=5.3.0
- guzzlehttp/guzzle: ^6.0|^7.0.1
Requires (Dev)
- phpunit/phpunit: ^10.0@dev
- vlucas/phpdotenv: ^5.2@dev
This package is auto-updated.
Last update: 2024-09-07 05:08:42 UTC
README
The SocketBus PHP Library
Getting Started
- Create an account -
- Minimum requirements -
- Install the library -
composer require socketbus/socketbus-php
- Using the library -
Create a SocketBus instance
require 'vendor/autoload.php'; use SocketBus\SocketBus; $config = [ 'app_id' => 's-1-J2PCu8g8sAejZeXx', 'secret' => 'cdKBpcruwYQ96kvIaYiorbTFxRDCbVfj' ]; $socketBus = new SocketBus($config);
End-to-End Encryption
To ensure that your data is secure, you can enable End-to-end encryption under Application > Settings. This setting in combination with the option custom_encryption_key
encrypts the payload and decrypts in the client when an authenticated user receives a encrypted payload.
$config = [ 'app_id' => 's-1-J2PCu8g8sAejZeXx', 'secret' => 'cdKBpcruwYQ96kvIaYiorbTFxRDCbVfj', 'custom_encryption_key' => 'my-unique-key' ];
Authentication
Defining the channel type
$channelName = $request->channel_name; if ($socketBus->isChannelPrivate($channelName)) { // The channel is private } if ($socketBus->isChannelPresence($channelName)) { // The channel is presence } if ($socketBus->isChannelPublic($channelName)) { // The channel is public }
Private Authentication
$socketId = $request->socket_id; $channelName = $request->channel_name; if (/** verifies if user can access the request channel */) { // returns the token to the client return [ 'auth' => $socketbus->auth($socketId, $channelName) ]; }
Presence Authentication
$socketId = $request->socket_id; $channelName = $request->channel_name; $userId = /** gets the current user id */; if (/** verifies if user can access the request channel */) { // returns the data return $socketbus->authPresence($socketId, $channelName, $userId, true); }
Broadcasting
$payload = [ 'type' => 'cupcake', 'flavor' => 'sweet' ]; $sockebus->broadcast('food-observer', 'new-food', $payload);
Resources
API Docs - Check-out the full documentation
Related Projects
SocketBus Laravel Library - Laravel library