Skip to content

Commit

Permalink
Merge pull request #40 from Dyz598/feat/broadcasting
Browse files Browse the repository at this point in the history
feat(broadcasting): added broadcasting bundle
  • Loading branch information
bl4ckbon3 committed Oct 25, 2023
2 parents 7a98a86 + 4758b66 commit dc75223
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Bundle/BroadcastingBundle/BroadcastingBundle.php
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Pandawa\Bundle\BroadcastingBundle;

use Illuminate\Broadcasting\BroadcastManager;
use Illuminate\Broadcasting\BroadcastServiceProvider;
use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactory;
use Illuminate\Contracts\Support\DeferrableProvider;
use Pandawa\Bundle\FoundationBundle\Plugin\ImportConfigurationPlugin;
use Pandawa\Bundle\FoundationBundle\Plugin\RegisterBundlesPlugin;
use Pandawa\Component\Foundation\Bundle\Bundle;
use Pandawa\Contracts\Foundation\HasPluginInterface;

/**
* @author Aldi Arief <aldiarief598@gmail.com>
*/
class BroadcastingBundle extends Bundle implements HasPluginInterface, DeferrableProvider
{
protected array $deferred = [
BroadcastManager::class,
BroadcastingFactory::class,
BroadcasterContract::class,
];

public function configure(): void
{
$this->app->singleton(BroadcastManager::class, function ($app) {
return new BroadcastManager($app);
});

$this->app->singleton(BroadcasterContract::class, function ($app) {
return $app->make(BroadcastManager::class)->connection();
});

$this->app->alias(
BroadcastManager::class, BroadcastingFactory::class
);
}

public function plugins(): array
{
return [
new ImportConfigurationPlugin(),
new RegisterBundlesPlugin([
BroadcastServiceProvider::class,
]),
];
}
}
71 changes: 71 additions & 0 deletions src/Bundle/BroadcastingBundle/Resources/config/config.php
@@ -0,0 +1,71 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "ably", "redis", "log", "null"
|
*/

'default' => env('BROADCAST_DRIVER', 'null'),

/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/

'connections' => [

'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'host' => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com',
'port' => env('PUSHER_PORT', 443),
'scheme' => env('PUSHER_SCHEME', 'https'),
'encrypted' => true,
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
],
'client_options' => [
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
],

'ably' => [
'driver' => 'ably',
'key' => env('ABLY_KEY'),
],

'redis' => [
'driver' => 'redis',
'connection' => 'default',
],

'log' => [
'driver' => 'log',
],

'null' => [
'driver' => 'null',
],

],

];
40 changes: 40 additions & 0 deletions src/Bundle/BroadcastingBundle/composer.json
@@ -0,0 +1,40 @@
{
"name": "pandawa/broadcasting-bundle",
"description": "The pandawa broadcasting bundle",
"license": "MIT",
"authors": [
{
"name": "Iqbal Maulana",
"email": "iq.bluejack@gmail.com"
},
{
"name": "Aldi Arief",
"email": "aldiarief598@gmail.com"
}
],
"require": {
"php": ">=8.1",
"pandawa/dependency-injection-bundle": "^5.0",
"pandawa/foundation-bundle": "^5.0",
"illuminate/broadcasting": "^9.0"
},
"autoload": {
"psr-4": {
"Pandawa\\Bundle\\BroadcastingBundle\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.x-dev"
},
"laravel": {
"providers": [
"Pandawa\\Bundle\\BroadcastingBundle\\BroadcastingBundle"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}

0 comments on commit dc75223

Please sign in to comment.