Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fre5h/centrifugobundle

đŸ“Ļ Provides communication with web-socket server Centrifugo in Symfony applications.
https://github.com/fre5h/centrifugobundle

bundle centrifugo centrifugo-bundle real-time socket symfony web-socket websocket

Last synced: about 23 hours ago
JSON representation

đŸ“Ļ Provides communication with web-socket server Centrifugo in Symfony applications.

Awesome Lists containing this project

README

        

# CentrifugoBundle

đŸ“Ļ Provides communication with web-socket server [Centrifugo](https://centrifugal.dev) in [Symfony](https://symfony.com) applications.

[![Scrutinizer Quality Score](https://img.shields.io/scrutinizer/g/fre5h/CentrifugoBundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/fre5h/CentrifugoBundle/)
[![Build Status](https://img.shields.io/github/actions/workflow/status/fre5h/CentrifugoBundle/ci.yaml?branch=main&style=flat-square)](https://github.com/fre5h/CentrifugoBundle/actions?query=workflow%3ACI+branch%3Amain+)
[![CodeCov](https://img.shields.io/codecov/c/github/fre5h/CentrifugoBundle.svg?style=flat-square)](https://codecov.io/github/fre5h/CentrifugoBundle)
[![License](https://img.shields.io/packagist/l/fresh/centrifugo-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/centrifugo-bundle)
[![Latest Stable Version](https://img.shields.io/packagist/v/fresh/centrifugo-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/centrifugo-bundle)
[![Total Downloads](https://img.shields.io/packagist/dt/fresh/centrifugo-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/centrifugo-bundle)
[![StyleCI](https://styleci.io/repos/164834807/shield?style=flat-square)](https://styleci.io/repos/164834807)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/fre5h/CentrifugoBundle)

## Features 🎁

- [x] Compatible with latest [Centrifugo 5.4.7](https://github.com/centrifugal/centrifugo/releases/tag/v5.4.7) 🚀
- [x] Wrapper over [Centrifugo HTTP API](https://centrifugal.dev/docs/server/server_api#http-api) 🔌
- [X] Authentication with JWT token (HMAC algorithm) for [anonymous](./Resources/docs/authentication.md#anonymous), [authenticated user](./Resources/docs/authentication.md#authenticated-user) and [private channel](./Resources/docs/authentication.md#private-channel) 🗝ī¸
- [x] [Batch request](./Resources/docs/centrifugo_service_methods.md#batch-request) in [JSON streaming format](https://en.wikipedia.org/wiki/JSON_streaming) đŸ’Ē
- [x] [Console commands](./Resources/docs/console_commands.md "Console commands") ⚒ī¸ī¸
- [x] Integration into Symfony Web-Profiler 🎛ī¸

## Requirements 🧐

* PHP >= 8.3
* Symfony 7.0

## Installation 🌱

```bash
$ composer req fresh/centrifugo-bundle
```

##### Choose the version you need

| Bundle Version (X.Y.Z) | PHP | Symfony | Comment |
|:----------------------:|:--------:|:-------:|:--------------------|
| `6.2.*` | `>= 8.3` | `7.*` | **Current version** |
| `5.3.*` | `>= 8.2` | `7.*` | Previous version |

By default, [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) adds this bundle to the `config/bundles.php` file and adds required environment variables into `.env` file.
In case when you ignored `contrib-recipe` during bundle installation it would not be done. Then you have to do this manually.

#### Check the `config/bundles.php` file

```php
# config/bundles.php

return [
// Other bundles...
Fresh\CentrifugoBundle\FreshCentrifugoBundle::class => ['all' => true],
// Other bundles...
];
```

#### Check the `.env` file and add you configuration

```yaml
# .env

###> fresh/centrifugo-bundle ###
CENTRIFUGO_API_KEY=secret-api-key
CENTRIFUGO_API_ENDPOINT=http://localhost:8000/api
CENTRIFUGO_SECRET=secret
###< fresh/centrifugo-bundle ###
```

`CENTRIFUGO_API_KEY` should be the same value as option `api_key` in your Centrifugo config file.
`CENTRIFUGO_SECRET` should be the same value as option `token_hmac_secret_key` in your Centrifugo config file.

ℹī¸ [Customize bundle configuration](./Resources/docs/configuration.md "Customize bundle configuration")

## Using 🧑‍🎓

### Centrifugo service

```php
centrifugo->publish(['foo' => 'bar'], 'channelName');
}
}
```

ℹī¸ [More examples of using Centrifugo service](./Resources/docs/centrifugo_service_methods.md "More examples of using Centrifugo service")

### Authentication with JWT tokens 🗝ī¸

* [For anonymous](./Resources/docs/authentication.md#anonymous)
* [For authenticated User](./Resources/docs/authentication.md#authenticated-user)
* [For private channel](./Resources/docs/authentication.md#private-channel)

### Console commands ⚒ī¸

* `centrifugo:publish`
* `centrifugo:broadcast`
* `centrifugo:subscribe`
* `centrifugo:unsubscribe`
* `centrifugo:disconnect`
* `centrifugo:refresh`
* `centrifugo:presence`
* `centrifugo:presence-stats`
* `centrifugo:history`
* `centrifugo:history-remove`
* `centrifugo:channels`
* `centrifugo:info`

ℹī¸ [More examples of using console commands](./Resources/docs/console_commands.md "More examples of using console commands")

### Integration into Symfony Web-Profiler 🎛ī¸

![](./Resources/images/profiler_example.png "Profiler example")

### Autocomplete channels in console commands đŸĒ„

![](./Resources/images/autocomplete_example.gif)

## Contributing 🤝

Read the [CONTRIBUTING](https://github.com/fre5h/CentrifugoBundle/blob/master/.github/CONTRIBUTING.md) file.