dizard/fire-ws-php

PHP client for FireWS real-time messaging server and store

dev-master 2017-04-27 09:28 UTC

This package is auto-updated.

Last update: 2024-09-22 06:20:17 UTC


README

composer require dizard/fire-ws-php

For communicate with Fire Web Socket Server

Example

use FireWSClient\FireWSClient;
$nameSpace = 'nameYouNamePace';
$userId = 5;
$ttl = 60;

try{
    $Client = new FireWSClient('tcp://127.0.0.1:8085');
    $sKeyForNameSpace = $Client->registerNameSpace($nameSpace,'secretKeyForServer');

    $Client->auth($nameSpace, $sKeyForNameSpace);
    $Client->send('channel', ['message' => 'hello world']);

    // Send Message for user with id 5
    $Client->send('@channel', ['message' => 'hello world'], $userId);

    // Send base state for channel
    // the state send user after subscribe there channel
    $Client->setAndSend('channel', ['message' => 'hello world']);
    // the state send user after subscribe there channel
    $Client->setAndSend('@channel', ['message' => 'hello world'], $userId);
    // the state send user after subscribe there channel with lifetime $ttl
    $Client->setAndSend('@channel', ['message' => 'hello world'], $userId, $ttl);

    // get base state channel
    $stateChannel = $Client->get('channel');

    // get base state channel for user with $userId
    $stateChannel = $Client->get('@channel', $userId);
    
    // Subscribe to private channel
    $Client->subscribe('#privateChannel', $userId);

    // Unsubscribe from private channel
    $Client->unsubscribe('#privateChannel', $userId);

    $channelInf = $Client->channelInfo('channel');
}catch(\FireWSClient\Exceptions\FireWsException $e) {

}