includable/topics

Super simple websocket broadcasting.

1.0.0 2018-12-10 14:44 UTC

This package is auto-updated.

Last update: 2020-04-10 17:48:08 UTC


README

Super simple websocket message broadcasting.

Topis is a service built into the Includable Platform, making it easy for Includable app developers to use websocket functionality.

Note however that when using this library, the namespace shared by your topics is shared by all users of the library. So make sure to make your topic name something unique that won't collide with other users.

The best approach for this is to use a reverse-DNS style string, like com.thomasschoffelen.mytopic.

Installation

composer install includable/topics

Usage

See example.php.

API

The Topics class exposes the following (static) functions.

Topics::broadcast

Broadcast a message to a topic. These messages should always be plain PHP objects are arrays that can be JSON serialized.

use Includable\Topics\Topics;

Topics::broadcast('com.thomasschoffelen.test', [
    'hello' => 'world'
]);

Topics::broadcastAsync

Broadcast a message to a topic. The difference between this and the above function is that this one is asynchronous and you won't get a response back. This above function waits until the HTTP call is completed.

use Includable\Topics\Topics;

Topics::broadcastSync('com.thomasschoffelen.test', [
    'hello' => 'world'
]);