Skip to content

Commit

Permalink
update drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
ctf0 authored and ctf0 committed Jan 7, 2023
1 parent f70250d commit 4095f8b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
13 changes: 1 addition & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: ctf0
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
github: ctf0
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"illuminate/support": ">=5.5 <9.0",
"illuminate/support": ">=5.5 <10.0",
"kreait/firebase-php": "*"
},
"suggest": {
Expand Down Expand Up @@ -45,8 +45,8 @@
},
"funding": [
{
"type": "patreon",
"url": "https://www.patreon.com/ctf0"
"type": "github",
"url": "https://github.com/sponsors/ctf0"
}
]
}
13 changes: 7 additions & 6 deletions src/Broadcasters/FSDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Kreait\Firebase\ServiceAccount;
use Morrislaptop\Firestore\Factory;
use Kreait\Firebase\Factory;
use Kreait\Firebase\Exception\ApiException;
use Illuminate\Broadcasting\BroadcastException;
use Illuminate\Broadcasting\Broadcasters\Broadcaster;
Expand All @@ -15,18 +14,20 @@ class FSDB extends Broadcaster
use Common;

protected $db;

protected $config;

/**
* Create a new broadcaster instance.
*
* @param mixed $config
*/
public function __construct($config)
{
$sr_account = ServiceAccount::fromJsonFile(base_path($config['creds_file']));
$this->config = $config;
$this->db = (new Factory())
->withServiceAccount($sr_account)
->createFirestore();
->withServiceAccount($config['creds_file'])
->createDatabase();
}

/**
Expand All @@ -35,11 +36,11 @@ public function __construct($config)
public function broadcast(array $channels, $event, array $payload = [])
{
$db = $this->db;
$coll = $db->collection($this->config['collection_name']);
$socket = Arr::pull($payload, 'socket');

foreach ($this->formatChannels($channels) as $channel) {
try {
$coll = $db->collection($this->config['collection_name']);
$doc = $coll->document(md5(Str::uuid()));
$doc->set([
'channel' => $channel,
Expand Down
23 changes: 11 additions & 12 deletions src/Broadcasters/RTDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,29 @@ class RTDB extends Broadcaster
public function __construct($config)
{
$this->config = $config;
$factory = (new Factory())
$this->db = (new Factory())
->withServiceAccount(base_path($config['creds_file']))
->withDatabaseUri($config['databaseURL']);

$this->db = $factory->createDatabase();
->withDatabaseUri($config['databaseURL'])
->createDatabase();
}

/**
* {@inheritdoc}
*/
public function broadcast(array $channels, $event, array $payload = [])
{
$db = $this->db->getReference($this->config['collection_name']);
$socket = Arr::pull($payload, 'socket');

foreach ($this->formatChannels($channels) as $channel) {
try {
$this->db->getReference($this->config['collection_name'])
->push([
'channel' => $channel,
'data' => $payload,
'event' => $event,
'socket' => $socket,
'timestamp' => round(now()->valueOf()), // return date == to js Date.now()
]);
$db->push([
'channel' => $channel,
'data' => $payload,
'event' => $event,
'socket' => $socket,
'timestamp' => round(now()->valueOf()), // return date == to js Date.now()
]);
} catch (ApiException $e) {
throw new BroadcastException($e);
}
Expand Down

0 comments on commit 4095f8b

Please sign in to comment.