2017 © Pedro Peláez
 

library tattler-php

PHP Tattler client

image

oktopost/tattler-php

PHP Tattler client

  • Wednesday, May 23, 2018
  • by alexey-pkv
  • Repository
  • 5 Watchers
  • 0 Stars
  • 74 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 22 Versions
  • 0 % Grown

The README.md

Tattler PHP client

Build Status Coverage Status License MIT, (*1)

Send async messages to your users using Tattler, (*2)

Installation

$ composer require oktopost/tattler-php

Or add to composer.json:, (*3)

"require": {
    "oktopost/tattler-php": "^1.0"
}

and then run composer update., (*4)

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, (*5)

  • 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, (*6)

When php configuration is done, include js/tattler.min.js to your html and initialize tattler, (*7)

window.tattler = TattlerFactory.create();

Usage

Setup listener in your js code, (*8)

window.tattler.addHandler('myMessage', 'globalNamespace', function(data){
    alert(data.message);
});

Send payload to all users from php, (*9)

/** 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/, (*10)

The Versions

30/03 2017

1.0.5

1.0.5.0

PHP Tattler client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Podrabinek

03/12 2016

V1.0.4

1.0.4.0

PHP Tattler client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Podrabinek

05/11 2016

v1.0.3

1.0.3.0

PHP Tattler client

  Sources   Download

MIT

The Requires

 

by Daniel Podrabinek

24/10 2016

v1.0.2

1.0.2.0

PHP Tattler client

  Sources   Download

MIT

The Requires

 

by Daniel Podrabinek

23/10 2016

v1.0.1

1.0.1.0

PHP Tattler client

  Sources   Download

MIT

The Requires

 

by Daniel Podrabinek

22/10 2016

v1.0

1.0.0.0

PHP Tattler client

  Sources   Download

MIT

The Requires

 

by Daniel Podrabinek