spiral / roadrunner-broadcast
RoadRunner broadcast plugin bridge
Installs: 29 179
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 11
Forks: 1
Open Issues: 1
Requires
- php: >=7.4
- ext-json: *
- google/protobuf: ^3.7
- spiral/goridge: ^3.1
- spiral/roadrunner: ^2.0
- symfony/polyfill-php80: ^1.23
Requires (Dev)
- phpunit/phpunit: ^8.0
- roave/security-advisories: dev-master
- spiral/code-style: ^1.0
- symfony/var-dumper: ^5.1
- vimeo/psalm: >=4.4
This package is auto-updated.
Last update: 2023-05-12 06:31:01 UTC
README
This repository contains the codebase bridge for broadcast RoadRunner plugin.
Installation
To install application server and broadcast codebase
$ composer require spiral/roadrunner-broadcast
You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:
$ composer require spiral/roadrunner-cli --dev $ vendor/bin/rr get
Usage
For example, such a configuration would be quite feasible to run:
rpc: listen: tcp://127.0.0.1:6001 server: # Don't forget to create a "worker.php" file command: "php worker.php" relay: "pipes" http: address: 127.0.0.1:80 # Indicate that HTTP support ws protocol middleware: [ "websockets" ] websockets: broker: default path: "/ws" broadcast: default: driver: memory config: {}
Read more about all available brokers on the documentation page.
After configuring and starting the RoadRunner server, the corresponding API will become available to you.
<?php use Spiral\Goridge\RPC\RPC; use Spiral\RoadRunner\Broadcast\Broadcast; require __DIR__ . '/vendor/autoload.php'; $broadcast = new Broadcast(RPC::create('tcp://127.0.0.1:6001')); // // Now we can send a message to a specific topic // $broadcast->publish('channel-1', 'message for channel #1');
Select Specific Topic
Alternatively, you can also use a specific topic (or set of topics) as a separate entity and post directly to it.
// Now we can select the topic we need to work only with it $topic = $broadcast->join(['channel-1', 'channel-2']); // And send messages there $topic->publish('message'); $topic->publish(['another message', 'third message']);
Read more about all the possibilities in the documentation page.
Client
In addition to the server (PHP) part, the client part is also present in most projects. In most cases, this is a browser in which the connection to the server is made using the WebSocket protocol.
const ws = new WebSocket('ws://127.0.0.1/broadcast'); ws.onopen = e => { const message = { command: 'join', topics: ['channel-1', 'channel-2'] }; ws.send(JSON.stringify(message)); }; ws.onmessage = e => { const message = JSON.parse(e.data); console.log(`${message.topic}: ${message.payload}`); }
Examples
Examples are available in the corresponding directory ./example.
License
The MIT License (MIT). Please see LICENSE
for more information.
Maintained by Spiral Scout.