oktopost / tattler-php
PHP Tattler client
1.0.11
2018-08-12 12:18 UTC
Requires
- php: >=7.1-stable
- 00f100/uuid: 4.0.0
- firebase/php-jwt: ^4.0
- oktopost/objection: ^1.0
- oktopost/skeleton: ^1.0.10
- satooshi/php-coveralls: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^6.2
- nategood/httpful: ^0.2.20
- oktopost/squanch: ^1.1
- oktopost/squid: ^1.0
- phpunit/phpunit: ^6.2
- predis/predis: ^1.1
Suggests
- guzzlehttp/guzzle: Communicate with Tattler backend through guzzle (optional, by default CURL will be used)
- nategood/httpful: Communicate with Tattler backend through httpful (optional, by default CURL will be used)
- oktopost/squanch: Store users/channels tokens with Squanch client
- oktopost/squid: Store users/channels tokens in MySQL DB
- predis/predis: Store users/channels tokens in Redis DB
README
Send async messages to your users using Tattler
Installation
$ composer require oktopost/tattler-php
Or add to composer.json
:
"require": { "oktopost/tattler-php": "^1.0" }
and then run composer update
.
Setup
$config = new TattlerConfig(); $tattlerConfig->fromArray([ 'WsAddress' => 'TATTLER_WEBSOCKET_ADDRESS', 'ApiAddress' => 'TATTLER_API_ADDRESS', 'Namespace' => 'YOUR APPLICATION_NAME', 'Secret' => 'TATTLER_SECRET', 'TokenTTL' => 'USER_TOKEN_TTL', 'DBConnector' => new RedisConnector(), 'NetworkConnector' => new CurlConnector() ]); /** @var ITattlerModule::class $tattler */ $tattler = Tattler::getInstance($tattlerConfig);
note: for using redis db connector you need to install predis
- TATTLER_WEBSOCKET_ADDRESS - websocket transport address e.g. ws://websocket.domain.tld:80 or wss://websocket.domain.tld:443
- TATTLER_API_ADDRESS - api address e.g. http://websocket.domain.tld:80 or https://websocket.domain.tld:443
- YOUR APPLICATION_NAME - namespace for your application. You can use same tattler server with multiple applications.
- TATTLER_SECRET - same secret that was defined in tattler-server configuration
- USER_TOKEN_TTL - time in seconds for users auth tokens used with tattler-server
Then create TattlerController available from your website. See example in DummyControllerExample
note: all methods from that controller should response with JSON body
When php configuration is done, include js/tattler.min.js to your html and initialize tattler
window.tattler = TattlerFactory.create();
Usage
Setup listener in your js code
window.tattler.addHandler('myMessage', 'globalNamespace', function(data){ alert(data.message); });
Send payload to all users from php
/** var ITattlerMessage::class $message */ $message = new TattlerMessage(); $message->setHandler('myMessage')->setNamespace('globalNamespace')->setPayload(['message' => 'Hello world']]); $tattler->message($message)->broadcast()->say();
See more docs in docs/