Skip to content

Commit

Permalink
Add Fanout event broadcasting
Browse files Browse the repository at this point in the history
  • Loading branch information
cwt137 committed May 12, 2015
1 parent 114e028 commit b64b57e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"suggest": {
"aws/aws-sdk-php": "Required to use the SQS queue driver and SES mail driver (~2.4).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).",
"fanout/fanout": "Required to use the Fanout broadcast driver (~2.0).",
"guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers (~5.0).",
"iron-io/iron_mq": "Required to use the iron queue driver (~2.0).",
"league/flysystem-aws-s3-v2": "Required to use the Flysystem S3 driver (~1.0).",
Expand Down
15 changes: 15 additions & 0 deletions src/Illuminate/Broadcasting/BroadcastManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

use Pusher;
use Closure;
use Fanout\Fanout;
use InvalidArgumentException;
use Illuminate\Broadcasting\Broadcasters\LogBroadcaster;
use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster;
use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
use Illuminate\Broadcasting\Broadcasters\FanoutBroadcaster;
use Illuminate\Contracts\Broadcasting\Factory as FactoryContract;

class BroadcastManager implements FactoryContract
Expand Down Expand Up @@ -149,6 +151,19 @@ protected function createLogDriver(array $config)
);
}

/**
* Create an instance of the driver.
*
* @param array $config
* @return \Illuminate\Contracts\Broadcasting\Broadcaster
*/
protected function createFanoutDriver(array $config)
{
return new FanoutBroadcaster(
new Fanout($config['realm_id'], $config['realm_key'])
);
}

/**
* Get the connection configuration.
*
Expand Down
38 changes: 38 additions & 0 deletions src/Illuminate/Broadcasting/Broadcasters/FanoutBroadcaster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php namespace Illuminate\Broadcasting\Broadcasters;

use Fanout\Fanout;
use Illuminate\Contracts\Broadcasting\Broadcaster;

class FanoutBroadcaster implements Broadcaster
{

/**
* The Fanout SDK instance.
*
* @var Fanout
*/
protected $fanout;

/**
* Create a new broadcaster instance.
*
* @param Fanout $fanout
* @return void
*/
public function __construct(Fanout $fanout)
{
$this->fanout = $fanout;
}

/**
* {@inheritdoc}
*/
public function broadcast(array $channels, $event, array $payload = array())
{
$payload = ['event' => $event, 'data' => $payload];

foreach ($channels as $channel) {
$this->fanout->publish($channel, $payload);
}
}
}
1 change: 1 addition & 0 deletions src/Illuminate/Broadcasting/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}
},
"suggest": {
"fanout/fanout": "Required to use the Fanout broadcast driver (~2.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~2.0)."
},
"minimum-stability": "dev"
Expand Down

0 comments on commit b64b57e

Please sign in to comment.