make0x20 / driplet
A PHP library for broadcasting messages using Driplet microservice
v0.1
2025-01-29 16:43 UTC
Requires
- php: ^8.3
- firebase/php-jwt: ^6.0
- guzzlehttp/guzzle: ^7.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
This package is not auto-updated.
Last update: 2026-03-26 21:02:50 UTC
README
A PHP library for broadcasting messages through WebSocket connections using the Driplet microservice. This library provides a way to generate JWT tokens and send messages the microservice.
Requirements
- PHP 8.3 or higher
- Composer
Installation
You can install the package via composer:
composer require make0x20/driplet
Usage
Sending a message
use Driplet\Client\DripletClient; // Initialize the client $client = new DripletClient( 'https://your-driplet-server.com/api/default/message', 'your-secret-key' ); // Create and send a message $message = $client->createMessage() ->setMessage(['event' => 'update']) ->setTopic('system') ->include() ->setTarget('roles', ['admin']) ->setTarget('departments', ['IT']) ->exclude() ->setTarget('users', [123, 456]); $success = $client->sendMessage($message);
Generate JWT tokens
use Driplet\Token\JwtManager; // Initialize the JWT manager $jwtManager = new JwtManager('your-jwt-secret', 60); // 60 seconds expiration // Generate a token with custom claims $token = $jwtManager->generateToken([ 'uid' => 123, 'roles' => ['user', 'admin'] ]);
Message structure
[
'nonce' => 'random-unique-string',
'timestamp' => 1234567890,
'message' => [
// Your message content
],
'target' => [
'include' => [
// Targets to include
],
'exclude' => [
// Targets to exclude
]
],
'topic' => 'your-topic'
]
Target system
The target system allows you to specify which clients should receive the message:
$client->createMessage() ->setMessage(['event' => 'update']) ->setTopic('system') ->include() ->setTarget('roles', ['admin']) ->setTarget('departments', ['IT']) ->exclude() ->setTarget('users', [123, 456]) ->build();