https://github.com/oktopost/tattler-php
PHP Tattler client
https://github.com/oktopost/tattler-php
Last synced: 5 months ago
JSON representation
PHP Tattler client
- Host: GitHub
- URL: https://github.com/oktopost/tattler-php
- Owner: Oktopost
- License: mit
- Created: 2016-10-16T20:46:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-07T11:00:14.000Z (over 1 year ago)
- Last Synced: 2025-03-28T08:35:41.289Z (over 1 year ago)
- Language: PHP
- Size: 188 KB
- Stars: 0
- Watchers: 13
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tattler PHP client
[](https://travis-ci.org/Oktopost/Tattler-php)
[](https://coveralls.io/github/Oktopost/Tattler-php?branch=master)
[](https://github.com/Oktopost/Tattler-php/blob/master/LICENSE)
Send async messages to your users using [Tattler](https://github.com/grohman/tattler)
- [Simple example project](https://github.com/grohman/tattler-php-chat-example)
## Installation
```bash
$ composer require oktopost/tattler-php
```
Or add to `composer.json`:
```json
"require": {
"oktopost/tattler-php": "^1.0"
}
```
and then run `composer update`.
## Setup
```php
$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](https://github.com/nrk/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](https://github.com/Oktopost/Tattler-php/blob/master/controller/DummyControllerExample.php)
_note: all methods from that controller should response with JSON body_
When php configuration is done, include [js/tattler.min.js](js/tattler.min.js) to your html and initialize tattler
```javascript
window.tattler = TattlerFactory.create();
```
## Usage
Setup listener in your js code
```javascript
window.tattler.addHandler('myMessage', 'globalNamespace', function(data){
alert(data.message);
});
```
Send payload to all users from php
```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/](docs/README.md)