Skip to content

Commit

Permalink
Update Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
denis_sz committed Oct 8, 2024
1 parent 188589e commit 212bc45
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 66 deletions.
148 changes: 94 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,139 +1,179 @@
<p align="center">Documentation <b>EN</b> | <a href="https://github.com/denis660/laravel-centrifuge/blob/master/README_RU.md">RU</a></p>
<p align="center">Documentation <a href="https://github.com/denis660/laravel-centrifugo/blob/master/README.md">EN</a> | <b>RU</b></p>

<h1 align="center">Laravel + Centrifugo</h1>
<h2 align="center">Centrifugo broadcast driver for Laravel 8.75.0 - 11 </h2>
<h2 align="center">Centrifugo broadcast driver for Laravel 8.75.0 - 11</h2>

<p align="center">
<a href="https://scrutinizer-ci.com/g/denis660/laravel-centrifugo"><img src="https://scrutinizer-ci.com/g/denis660/laravel-centrifugo/badges/quality-score.png?b=master" alt="Build Status"></a>
<a href="https://github.com/denis660/laravel-centrifugo/actions/workflows/tests.yml"><img src="https://github.com/denis660/laravel-centrifugo/actions/workflows/tests.yml/badge.svg" alt="Build Status"></a>
<a href="https://github.com/denis660/laravel-centrifugo/releases"><img src="https://img.shields.io/github/release/denis660/laravel-centrifugo.svg?style=flat-square" alt="Latest Version"></a>
<a href="https://scrutinizer-ci.com/g/denis660/laravel-centrifugo"><img src="https://img.shields.io/scrutinizer/g/denis660/laravel-centrifugo.svg?style=flat-square" alt="Quality Score"></a>
<a href="https://github.styleci.io/repos/324202212"><img src="https://github.styleci.io/repos/324202212/shield?branch=master" alt="StyleCI"></a>
<a href="https://packagist.org/packages/denis660/laravel-centrifugo"><img src="https://img.shields.io/packagist/dt/denis660/laravel-centrifugo.svg?style=flat-square" alt="Total Downloads"></a>
<a href="https://github.com/denis660/Centrifuge/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Software License"></a>
</p>

## Introduction
Centrifugo broadcaster for laravel , based on:
- [LaraComponents/centrifugo-broadcaster](https://github.com/LaraComponents/centrifugo-broadcaster)
Centrifugo broadcaster for Laravel is based on:
- [centrifugal/phpcent](https://github.com/centrifugal/phpcent)

## Features
- Compatible with latest [Centrifugo v5.4.5](https://github.com/centrifugal/centrifugo/releases/tag/v5.4.5) 🚀
- Wrapper over [Centrifugo HTTP API](https://centrifugal.dev/docs/server/server_api) 🔌
- Authentication with JWT token (HMAC algorithm) for anonymous, authenticated user and private channel 🗝️
- Compatibility with the latest version of [Centrifugo v5.4.6](https://github.com/centrifugal/centrifugo/releases/tag/v5.4.6) 🚀
- Wrapper for [Centrifugo HTTP API](https://centrifugal.dev/docs/server/server_api) 🔌
- JWT token authentication (HMAC algorithm) for anonymous, authorized users, and private channels 🗝️

## Requirements
- PHP >= 7.4 , 8.0, 8.1, 8.2, 8.3
- Laravel 8.75.0 - 11.0
- PHP 8.0 - 8.3
- Laravel 9 - 11
- Guzzlehttp/Guzzle 6 - 7
- Centrifugo Server v5.4.5 or newer (see [here](https://github.com/centrifugal/centrifugo))
- Centrifugo Server v5 or newer (see [here](https://github.com/centrifugal/centrifugo))

## Installation
By default, broadcasting is not enabled in new Laravel 11 applications. You may enable broadcasting using the install:broadcasting Artisan command:
For Laravel 9-10:

```bash
php artisan install:broadcasting
composer require denis660/laravel-centrifugo
```
The `install:broadcasting` command will create the config/broadcasting.php configuration file. In addition, the command will create the `routes/channels.php` file where you may register your application's broadcast authorization routes and callbacks.

For Laravel 11, there are specific instructions below.



Require this package with composer:

##### Выберите нужную вам версию

| Version | PHP | Laravel | Centrifugo | Notes |
|:-------:|:--------:|:---------:|:----------:|:--------------------|
| `5.0.*` | `>= 8.0` | `9` - `11` | `5` | **Current version** |
| `3.0.*` | `>= 7.4` | `8.75.*` | `4`-`5` | Previous version |


By default, broadcasting is disabled in new Laravel 11 applications. You can enable broadcasting using the install
Artisan command:
```bash
php artisan install:broadcasting
```
If asked whether to install Reverb, answer “no.”

Then, install the package for working with Centrifugo via composer by running the following command:
```bash
composer require denis660/laravel-centrifugo
```

## Configuration
Run the command centrifuge
, which will install centrifuge-laravel with a reasonable set of default configuration options and generate default keys. If you want to make any changes to the configuration, you can update the environment variables in the .env file.
```bash
php artisan centrifuge:install
```

# Credentials
To establish a connection with Centrifugo, you need to provide a set of Centrifugo credentials from the config.json file. These credentials are configured on the Centrifugo server, but Laravel will generate example keys that you should replace. You can specify these credentials with the following environment variables:

Application Credentials
In order to establish a connection to Reverb, a set of Reverb "application" credentials must be exchanged between the client and server. These credentials are configured on the server and are used to verify the request from the client. You may define these credentials using the following environment variables:

Also you should add these two lines to your .env file:

Required parameters:
```
CENTRIFUGO_TOKEN_HMAC_SECRET_KEY=token_hmac_secret_key-from-centrifugo-config
CENTRIFUGO_API_KEY=api_key-from-centrifugo-config
CENTRIFUGO_URL=http://localhost:8000
```

These lines are optional:
Optional parameters, modify if needed:
```
CENTRIFUGO_URL=http://localhost:8000
CENTRIFUGO_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGO_VERIFY=false
```

Don't forget to change `BROADCAST_DRIVER` setting in .env file!
Make sure to check the `BROADCAST_DRIVER` parameter in the .env file:

```
BROADCAST_DRIVER=centrifugo
```

## Client SDKs
For working with clients, see the [Client SDK API](https://centrifugal.dev/docs/transports/client_api)

Here is a list of SDKs supported by Centrifugal Labs:
- [JavaScript](https://github.com/centrifugal/centrifuge-js) — for browser, NodeJS, and React Native
- [Golang](https://github.com/centrifugal/centrifuge-go) — for Go language
- [Dart](https://github.com/centrifugal/centrifuge-dart) — for Dart and Flutter (mobile and web applications)
- [Swift](https://github.com/centrifugal/centrifuge-swift) — for native iOS development
- [Java](https://github.com/centrifugal/centrifuge-java) — for native Android and general Java development
- [Python](https://github.com/centrifugal/centrifuge-python) — real-time SDK for Python on top of asyncio

## Basic Usage

To configure Centrifugo server, read [official documentation](https://centrifugal.dev)
Set up your Centrifugo server as detailed in the [official documentation](https://centrifugal.dev)
For sending events, refer to the [official Laravel documentation](https://laravel.com/docs/11.x/broadcasting)




For broadcasting events, see [official documentation of laravel](https://laravel.com/docs/8.x/broadcasting)

A simple client usage example:
Here is a simple example of client usage:

```php
<?php
declare(strict_types = 1);

namespace App\Http\Controllers;


use denis660\Centrifugo\Centrifugo;
use Illuminate\Support\Facades\Auth;

class ExampleController
{

public function example(Centrifugo $centrifugo)
{
// Send message into channel
// Send a message to the news channel
$centrifugo->publish('news', ['message' => 'Hello world']);

// Generate connection token
// Generate a connection token
$token = $centrifugo->generateConnectionToken((string)Auth::id(), 0, [
'name' => Auth::user()->name,
]);

// Generate private channel token
// Generate a token for a private channel connection
$apiSign = $centrifugo->generatePrivateChannelToken((string)Auth::id(), 'channel', time() + 5 * 60, [
'name' => Auth::user()->name,
]);

//Get a list of currently active channels.
// Get a list of active channels
$centrifugo->channels();

//Get channel presence information (all clients currently subscribed on this channel).
// Get information about the news channel and its active clients
$centrifugo->presence('news');

}
}
```

### Available methods

| Name | Description |
### Methods for generating client tokens
| Method | Description |
|------|-------------|
| publish(string $channel, array $data, $skipHistory = false) | Send message into channel. |
| broadcast(array $channels, array $data, $skipHistory = false) | Send message into multiple channel. |
| presence(string $channel) | Get channel presence information (all clients currently subscribed on this channel). |
| presenceStats(string $channel) | Get channel presence information in short form (number of clients).|
| history(string $channel, $limit = 0, $since = [], $reverse = false) | Get channel history information (list of last messages sent into channel). |
| historyRemove(string $channel) | Remove channel history information.
| subscribe(string $channel, string $user, $client = '') | subscribe user from channel. |
| unsubscribe(string $channel, string $user, string $client = '') | Unsubscribe user from channel. |
| disconnect(string $user_id) | Disconnect user by it's ID. |
| channels(string $pattern = '') | Get channels information (list of currently active channels). |
| info() | Get stats information about running server nodes. |
| generateConnectionToken(string $userId = '', int $exp = 0, array $info = [], array $channels = []) | Generate connection token. |
| generatePrivateChannelToken(string $client, string $channel, int $exp = 0, array $info = []) | Generate private channel token. |
| ```generateConnectionToken``` | Generate a token for connection |
| ```generatePrivateChannelToken``` | Generate a private token for a private channel |


### API Methods

| Название | Описание |
|------|-----------------------------------------------------------------------------------------------------|
| ```publish``` | Send a message to a channel |
| ```broadcast``` | Send a message to multiple channels. |
| ```presence``` | Get presence information for a channel (all clients currently subscribed to this channel). |
| ```presenceStats``` | Get summary information for a channel (number of clients). |
| ```history``` | Get channel history (list of recent messages sent to the channel). |
| ```historyRemove``` | Remove channel history. |
| ```subscribe``` | Subscribe a user to a channel |
| ```unsubscribe``` | Unsubscribe a user from a channel. |
| ```disconnect``` | Disconnect a user by their ID. |
| ```channels``` | List current active channels. |
| ```info``` | Statistical information about running server nodes. |


## License

The MIT License (MIT). Please see [License File](https://github.com/denis660/laravel-centrifugo/blob/master/LICENSE for more information.
MIT License. Please read the [License File](https://github.com/denis660/laravel-centrifugo/blob/master/LICENSE) for more information.

# Support the Project
USDT wallet: ```TUYJrA9VRtXhDFooESHyT8dQSyg5zmtUg7```

Network: ```TRC20```

## Contributing 🤝

32 changes: 20 additions & 12 deletions README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<p align="center">
<a href="https://github.com/denis660/laravel-centrifugo/actions/workflows/tests.yml"><img src="https://github.com/denis660/laravel-centrifugo/actions/workflows/tests.yml/badge.svg" alt="Build Status"></a>
<a href="https://github.com/denis660/laravel-centrifugo/releases"><img src="https://img.shields.io/github/release/denis660/laravel-centrifugo.svg?style=flat-square" alt="Latest Version"></a>
<a href="https://github.styleci.io/repos/324202212"><img src="https://github.styleci.io/repos/324202212/shield?branch=master" alt="StyleCI"></a>
<a href="https://packagist.org/packages/denis660/laravel-centrifugo"><img src="https://img.shields.io/packagist/dt/denis660/laravel-centrifugo.svg?style=flat-square" alt="Total Downloads"></a>
<a href="https://github.com/denis660/Centrifuge/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Software License"></a>
</p>
Expand All @@ -17,24 +16,32 @@ Centrifugo broadcaster для laravel , основан на :
- [centrifugal/phpcent](https://github.com/centrifugal/phpcent)

## Особенности
- Совместимость с последней версией [Centrifugo v5.4.5](https://github.com/centrifugal/centrifugo/releases/tag/v5.4.5) 🚀
- Совместимость с последней версией [Centrifugo v5.4.6](https://github.com/centrifugal/centrifugo/releases/tag/v5.4.6) 🚀
- Обертка над [Centrifugo HTTP API](https://centrifugal.dev/docs/server/server_api) 🔌
- Аутентификация с помощью токена JWT (HMAC алгоритм) для анонимного, авторизованного пользователя и приватного канала 🗝️

## Требования
- PHP 8.0 - 8.3
- Framework Laravel 8.75.0 - 11.0
- Laravel 9 - 11
- Guzzlehttp/Guzzle 6 - 7
- Centrifugo Сервер v3 или новее (см. [здесь](https://github.com/centrifugal/centrifugo))
- Centrifugo Сервер v5 или новее (см. [здесь](https://github.com/centrifugal/centrifugo))

## Установка

Для Laravel 9-10
```bash
composer require denis660/laravel-centrifugo
```
Для Laravel 11 есть особенности, читаем ниже



##### Выберите нужную вам версию

| Версия | PHP | Laravel | Комментарий |
|:----------------------:|:--------:|:-------:|:--------------------|
| `4.0.*` | `>= 8.0` | `11.*` | **Текущая версия** |
| `3.0.*` | `>= 7.4` | `8.75.*` | Предыдущая версия |
| Версия | PHP | Laravel | Комментарий |
|:-------:|:--------:|:---------:|:--------------------|
| `5.0.*` | `>= 8.0` | `9` - `11` | **Текущая версия** |
| `3.0.*` | `>= 7.4` | `8.75.*` | Предыдущая версия |


По умолчанию вещание не включено в новых приложениях Laravel 11. Вы можете включить вещание с помощью команды install:broadcasting Artisan:
Expand Down Expand Up @@ -77,8 +84,8 @@ CENTRIFUGO_VERIFY=false
BROADCAST_DRIVER=centrifugo
```

## Клиентские SDK
Для работы с клиентом , почитайте в [Client SDK API](https://centrifugal.dev/docs/transports/client_api)
## Клиентские SDK
Для работы с клиентом , почитайте в [Client SDK API](https://centrifugal.dev/docs/transports/client_api)

Вот список SDK, поддерживаемых Centrifugal Labs:
- [JavaScript](https://github.com/centrifugal/centrifuge-js) — для браузера, NodeJS и React Native
Expand All @@ -93,7 +100,7 @@ BROADCAST_DRIVER=centrifugo
Настройте ваш сервер Centrifugo , детальнее в [официальной документации](https://centrifugal.dev)
Для отправки событий, почитайте [официальную документацию для Laravel](https://laravel.com/docs/11.x/broadcasting)





Expand Down Expand Up @@ -165,7 +172,8 @@ class ExampleController
Лицензия MIT. Пожалуйста прочитайте [License File](https://github.com/denis660/laravel-centrifugo/blob/master/LICENSE) для получения дополнительной информации.

# Помочь проекту
Кошелек USDT: ``TUYJrA9VRtXhDFooESHyT8dQSyg5zmtUg7```
Кошелек USDT: ```TUYJrA9VRtXhDFooESHyT8dQSyg5zmtUg7```

Сеть: ```TRC20```

## Contributing 🤝
Expand Down

0 comments on commit 212bc45

Please sign in to comment.