Skip to content

Commit

Permalink
Switch to reverb
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Mar 12, 2024
1 parent 0e58f0e commit a97db7f
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 76 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/run-table-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ jobs:
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: cd app && php artisan dusk --stop-on-error --stop-on-failure --group=table
max_attempts: 1
command: cd app && php artisan dusk --group=table
on_retry_command: cd app && php artisan migrate:fresh --seed
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
Expand All @@ -188,8 +188,8 @@ jobs:
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: cd app && php artisan dusk --stop-on-error --stop-on-failure --group=table
max_attempts: 1
command: cd app && php artisan dusk --group=table
on_retry_command: cd app && php artisan migrate:fresh --seed
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
Expand All @@ -199,8 +199,8 @@ jobs:
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: cd app && php artisan dusk --stop-on-error --stop-on-failure --group=table
max_attempts: 1
command: cd app && php artisan dusk --group=table
on_retry_command: cd app && php artisan migrate:fresh --seed

- name: Upload Screenshots
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ jobs:
cd app
./vendor/laravel/dusk/bin/chromedriver-linux &
# - name: Start Laravel Websockets
# run: |
# cd app
# php artisan websockets:serve &
- name: Start Laravel Reverb
run: |
cd app
php artisan reverb:start &
- name: Start SSR server
run: |
Expand All @@ -131,8 +131,8 @@ jobs:
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: cd app && php artisan dusk --stop-on-error --stop-on-failure --exclude-group=table
max_attempts: 1
command: cd app && php artisan dusk --exclude-group=table
on_retry_command: cd app && php artisan migrate:fresh --seed

- name: Upload Screenshots
Expand Down
24 changes: 10 additions & 14 deletions app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LOG_LEVEL=debug

DB_CONNECTION=sqlite

BROADCAST_DRIVER=pusher
BROADCAST_DRIVER=reverb
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
Expand All @@ -32,19 +32,15 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

PUSHER_APP_ID=1234567
PUSHER_APP_KEY=12345678901234567890
PUSHER_APP_SECRET=12345678901234567890
PUSHER_APP_CLUSTER=eu
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=http

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
REVERB_APP_KEY=12345678901234567890
REVERB_APP_SECRET=12345678901234567890
REVERB_APP_ID=1234567
REVERB_SCHEME=http

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_APP_SECRET="${REVERB_APP_SECRET}"
VITE_REVERB_APP_ID="${REVERB_APP_ID}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

DEBUGBAR_ENABLED=false
SPLADE_SSR_ENABLED=false
22 changes: 9 additions & 13 deletions app/.env.example.mysql
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

PUSHER_APP_ID=1234567
PUSHER_APP_KEY=12345678901234567890
PUSHER_APP_SECRET=12345678901234567890
PUSHER_APP_CLUSTER=eu
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=http

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
REVERB_APP_KEY=12345678901234567890
REVERB_APP_SECRET=12345678901234567890
REVERB_APP_ID=1234567
REVERB_SCHEME=http

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_APP_SECRET="${REVERB_APP_SECRET}"
VITE_REVERB_APP_ID="${REVERB_APP_ID}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

DEBUGBAR_ENABLED=false
SPLADE_SSR_ENABLED=false
22 changes: 9 additions & 13 deletions app/.env.example.postgres
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

PUSHER_APP_ID=1234567
PUSHER_APP_KEY=12345678901234567890
PUSHER_APP_SECRET=12345678901234567890
PUSHER_APP_CLUSTER=eu
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=http

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
REVERB_APP_KEY=12345678901234567890
REVERB_APP_SECRET=12345678901234567890
REVERB_APP_ID=1234567
REVERB_SCHEME=http

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_APP_SECRET="${REVERB_APP_SECRET}"
VITE_REVERB_APP_ID="${REVERB_APP_ID}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

DEBUGBAR_ENABLED=false
SPLADE_SSR_ENABLED=false
5 changes: 3 additions & 2 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"php": "^8.3|^8.2",
"guzzlehttp/guzzle": "^7.2",
"kirschbaum-development/eloquent-power-joins": "^3.0",
"laravel/framework": "^10.48.2|^11.0.1",
"laravel/reverb": "^1.0@beta",
"laravel/sanctum": "^3.2|^4.0",
"laravel/tinker": "^2.7",
"maatwebsite/excel": "^3.1",
"monolog/monolog": "^3.0",
"nesbot/carbon": "^2.63",
"psr/simple-cache": "^2.0",
"pusher/pusher-php-server": "^7.0,<7.2.0",
"ramsey/collection": "^1.2",
"spatie/laravel-medialibrary": "^11.0",
"spatie/laravel-query-builder": "^5.0"
Expand Down Expand Up @@ -83,4 +84,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
16 changes: 16 additions & 0 deletions app/config/broadcasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@

'connections' => [

'reverb' => [
'driver' => 'reverb',
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'options' => [
'host' => env('REVERB_HOST'),
'port' => env('REVERB_PORT', 443),
'scheme' => env('REVERB_SCHEME', 'https'),
'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
],
'client_options' => [
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
],

'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
Expand Down
81 changes: 81 additions & 0 deletions app/config/reverb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Default Reverb Server
|--------------------------------------------------------------------------
|
| This option controls the default server used by Reverb to handle
| incoming messages as well as braodcasting message to all your
| connected clients. At this time only "reverb" is supported.
|
*/

'default' => env('REVERB_SERVER', 'reverb'),

/*
|--------------------------------------------------------------------------
| Reverb Servers
|--------------------------------------------------------------------------
|
| Here you may define details for each of the supported Reverb servers.
| Each server has its own configuration options that are defined in
| the array below. You should ensure all the options are present.
|
*/

'servers' => [

'reverb' => [
'host' => env('REVERB_SERVER_HOST', '0.0.0.0'),
'port' => env('REVERB_SERVER_PORT', 8080),
'hostname' => env('REVERB_HOST'),
'options' => [
'tls' => [],
],
'scaling' => [
'enabled' => env('REVERB_SCALING_ENABLED', false),
'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'),
],
'pulse_ingest_interval' => env('REVERB_PULSE_INGEST_INTERVAL', 15),
],

],

/*
|--------------------------------------------------------------------------
| Reverb Applications
|--------------------------------------------------------------------------
|
| Here you may define how Reverb applications are managed. If you choose
| to use the "config" provider, you may define an array of apps which
| your server will support, including their connection credentials.
|
*/

'apps' => [

'provider' => 'config',

'apps' => [
[
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'options' => [
'host' => env('REVERB_HOST'),
'port' => env('REVERB_PORT', 443),
'scheme' => env('REVERB_SCHEME', 'https'),
'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
],
'allowed_origins' => ['*'],
'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60),
'max_message_size' => env('REVERB_APP_MAX_MESSAGE_SIZE', 10000),
],
],

],

];
13 changes: 6 additions & 7 deletions app/resources/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import Pusher from "pusher-js";
window.Pusher = Pusher;

const echoConfig = {
broadcaster: "pusher",
cluster: "eu",
key: import.meta.env.VITE_PUSHER_APP_KEY,
wsHost: import.meta.env.VITE_PUSHER_HOST ?? `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`,
wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80,
wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443,
forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? "https") === "https",
broadcaster: "reverb",
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT,
wssPort: import.meta.env.VITE_REVERB_PORT,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
enabledTransports: ["ws", "wss"],
};

Expand Down
7 changes: 0 additions & 7 deletions app/tests/Browser/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ class EventTest extends DuskTestCase
{
use UsesWebsocketsServerTrait;

public function setUp(): void
{
parent::setUp();

$this->markTestSkipped('Temporarily skipped until Laravel Reverb has been released.');
}

/** @test */
public function it_can_redirect_on_an_event()
{
Expand Down
11 changes: 3 additions & 8 deletions app/tests/Browser/UsesWebsocketsServerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Tests\Browser;

use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\Facades\Http;
use Symfony\Component\Process\Process;

Expand All @@ -14,17 +12,14 @@ trait UsesWebsocketsServerTrait

protected function setUpUsesWebsocketsServerTrait()
{
/** @var PusherBroadcaster $connection */
$connection = Broadcast::connection();
$reverbServer = config('reverb.servers.reverb');

$settings = $connection->getPusher()->getSettings();

$url = "{$settings['scheme']}://{$settings['host']}:{$settings['port']}";
$url = "{$reverbServer['host']}:{$reverbServer['port']}";

try {
Http::get($url);
} catch (ConnectionException $e) {
$this->websocketsServerProcess = tap(Process::fromShellCommandline('php artisan websockets:serve', base_path()))->start();
$this->websocketsServerProcess = tap(Process::fromShellCommandline('php artisan reverb:start', base_path()))->start();

retry(10, function () use ($url) {
Http::get($url);
Expand Down

0 comments on commit a97db7f

Please sign in to comment.