configuring broadcast with laravel-websockets
This commit is contained in:
@@ -6,12 +6,14 @@
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.0.2",
|
||||
"beyondcode/laravel-websockets": "^1.13",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"inertiajs/inertia-laravel": "^0.5.2",
|
||||
"laravel/framework": "^9.19",
|
||||
"laravel/jetstream": "^2.9",
|
||||
"laravel/sanctum": "^2.14.1",
|
||||
"laravel/tinker": "^2.7",
|
||||
"pusher/pusher-php-server": "^7.0",
|
||||
"spatie/laravel-permission": "^5.5",
|
||||
"tightenco/ziggy": "^1.0"
|
||||
},
|
||||
|
||||
1499
composer.lock
generated
1499
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -191,7 +191,7 @@ return [
|
||||
*/
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
App\Providers\FortifyServiceProvider::class,
|
||||
|
||||
141
config/websockets.php
Normal file
141
config/websockets.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
* Set a custom dashboard configuration
|
||||
*/
|
||||
'dashboard' => [
|
||||
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
|
||||
],
|
||||
|
||||
/*
|
||||
* This package comes with multi tenancy out of the box. Here you can
|
||||
* configure the different apps that can use the webSockets server.
|
||||
*
|
||||
* Optionally you specify capacity so you can limit the maximum
|
||||
* concurrent connections for a specific app.
|
||||
*
|
||||
* Optionally you can disable client events so clients cannot send
|
||||
* messages to each other via the webSockets.
|
||||
*/
|
||||
'apps' => [
|
||||
[
|
||||
'id' => env('PUSHER_APP_ID'),
|
||||
'name' => env('APP_NAME'),
|
||||
'key' => env('PUSHER_APP_KEY'),
|
||||
'secret' => env('PUSHER_APP_SECRET'),
|
||||
'path' => env('PUSHER_APP_PATH'),
|
||||
'capacity' => null,
|
||||
'enable_client_messages' => false,
|
||||
'enable_statistics' => true,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
* This class is responsible for finding the apps. The default provider
|
||||
* will use the apps defined in this config file.
|
||||
*
|
||||
* You can create a custom provider by implementing the
|
||||
* `AppProvider` interface.
|
||||
*/
|
||||
'app_provider' => BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class,
|
||||
|
||||
/*
|
||||
* This array contains the hosts of which you want to allow incoming requests.
|
||||
* Leave this empty if you want to accept requests from all hosts.
|
||||
*/
|
||||
'allowed_origins' => [
|
||||
//
|
||||
],
|
||||
|
||||
/*
|
||||
* The maximum request size in kilobytes that is allowed for an incoming WebSocket request.
|
||||
*/
|
||||
'max_request_size_in_kb' => 250,
|
||||
|
||||
/*
|
||||
* This path will be used to register the necessary routes for the package.
|
||||
*/
|
||||
'path' => 'laravel-websockets',
|
||||
|
||||
/*
|
||||
* Dashboard Routes Middleware
|
||||
*
|
||||
* These middleware will be assigned to every dashboard route, giving you
|
||||
* the chance to add your own middleware to this list or change any of
|
||||
* the existing middleware. Or, you can simply stick with this list.
|
||||
*/
|
||||
'middleware' => [
|
||||
'web',
|
||||
Authorize::class,
|
||||
],
|
||||
|
||||
'statistics' => [
|
||||
/*
|
||||
* This model will be used to store the statistics of the WebSocketsServer.
|
||||
* The only requirement is that the model should extend
|
||||
* `WebSocketsStatisticsEntry` provided by this package.
|
||||
*/
|
||||
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
|
||||
|
||||
/**
|
||||
* The Statistics Logger will, by default, handle the incoming statistics, store them
|
||||
* and then release them into the database on each interval defined below.
|
||||
*/
|
||||
'logger' => BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
|
||||
|
||||
/*
|
||||
* Here you can specify the interval in seconds at which statistics should be logged.
|
||||
*/
|
||||
'interval_in_seconds' => 60,
|
||||
|
||||
/*
|
||||
* When the clean-command is executed, all recorded statistics older than
|
||||
* the number of days specified here will be deleted.
|
||||
*/
|
||||
'delete_statistics_older_than_days' => 60,
|
||||
|
||||
/*
|
||||
* Use an DNS resolver to make the requests to the statistics logger
|
||||
* default is to resolve everything to 127.0.0.1.
|
||||
*/
|
||||
'perform_dns_lookup' => false,
|
||||
],
|
||||
|
||||
/*
|
||||
* Define the optional SSL context for your WebSocket connections.
|
||||
* You can see all available options at: http://php.net/manual/en/context.ssl.php
|
||||
*/
|
||||
'ssl' => [
|
||||
/*
|
||||
* Path to local certificate file on filesystem. It must be a PEM encoded file which
|
||||
* contains your certificate and private key. It can optionally contain the
|
||||
* certificate chain of issuers. The private key also may be contained
|
||||
* in a separate file specified by local_pk.
|
||||
*/
|
||||
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
|
||||
|
||||
/*
|
||||
* Path to local private key file on filesystem in case of separate files for
|
||||
* certificate (local_cert) and private key.
|
||||
*/
|
||||
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
|
||||
|
||||
/*
|
||||
* Passphrase for your local_cert file.
|
||||
*/
|
||||
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
|
||||
],
|
||||
|
||||
/*
|
||||
* Channel Manager
|
||||
* This class handles how channel persistence is handled.
|
||||
* By default, persistence is stored in an array by the running webserver.
|
||||
* The only requirement is that the class should implement
|
||||
* `ChannelManager` interface provided by this package.
|
||||
*/
|
||||
'channel_manager' => \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager::class,
|
||||
];
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateWebSocketsStatisticsEntriesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('websockets_statistics_entries', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('app_id');
|
||||
$table->integer('peak_connection_count');
|
||||
$table->integer('websocket_message_count');
|
||||
$table->integer('api_message_count');
|
||||
$table->nullableTimestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('websockets_statistics_entries');
|
||||
}
|
||||
}
|
||||
36
database/migrations/2022_07_29_034330_create_jobs_table.php
Normal file
36
database/migrations/2022_07_29_034330_create_jobs_table.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
}
|
||||
};
|
||||
41
package-lock.json
generated
41
package-lock.json
generated
@@ -6,6 +6,8 @@
|
||||
"": {
|
||||
"dependencies": {
|
||||
"@vueform/multiselect": "^2.5.1",
|
||||
"laravel-echo": "^1.13.0",
|
||||
"pusher-js": "^7.3.0",
|
||||
"sweetalert2": "^11.4.23",
|
||||
"vuedraggable": "^4.1.0"
|
||||
},
|
||||
@@ -1131,6 +1133,14 @@
|
||||
"node": ">=0.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/laravel-echo": {
|
||||
"version": "1.13.0",
|
||||
"resolved": "https://registry.npmjs.org/laravel-echo/-/laravel-echo-1.13.0.tgz",
|
||||
"integrity": "sha512-KWcr9Sthr8DUfrFtCKNMGq4IRTmswW+Xu92eL1yH2V7/C/3XGOxrTgzTB98jnk423gy+1DMyaavnujG9HeY3Jg==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/laravel-vite-plugin": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/laravel-vite-plugin/-/laravel-vite-plugin-0.2.4.tgz",
|
||||
@@ -1450,6 +1460,14 @@
|
||||
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/pusher-js": {
|
||||
"version": "7.3.0",
|
||||
"resolved": "https://registry.npmjs.org/pusher-js/-/pusher-js-7.3.0.tgz",
|
||||
"integrity": "sha512-N7uFRZGK6PKFfKd8e1aKsQ81OrilATGNhIbj42xJKmK+3zhstGBCQ110ZiF2nIngPTEKxQQqf15SJsVnQfNuqQ==",
|
||||
"dependencies": {
|
||||
"tweetnacl": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.11.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||
@@ -1696,6 +1714,11 @@
|
||||
"node": ">=8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tweetnacl": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
|
||||
},
|
||||
"node_modules/update-browserslist-db": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.4.tgz",
|
||||
@@ -2527,6 +2550,11 @@
|
||||
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
||||
"dev": true
|
||||
},
|
||||
"laravel-echo": {
|
||||
"version": "1.13.0",
|
||||
"resolved": "https://registry.npmjs.org/laravel-echo/-/laravel-echo-1.13.0.tgz",
|
||||
"integrity": "sha512-KWcr9Sthr8DUfrFtCKNMGq4IRTmswW+Xu92eL1yH2V7/C/3XGOxrTgzTB98jnk423gy+1DMyaavnujG9HeY3Jg=="
|
||||
},
|
||||
"laravel-vite-plugin": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/laravel-vite-plugin/-/laravel-vite-plugin-0.2.4.tgz",
|
||||
@@ -2741,6 +2769,14 @@
|
||||
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
|
||||
"dev": true
|
||||
},
|
||||
"pusher-js": {
|
||||
"version": "7.3.0",
|
||||
"resolved": "https://registry.npmjs.org/pusher-js/-/pusher-js-7.3.0.tgz",
|
||||
"integrity": "sha512-N7uFRZGK6PKFfKd8e1aKsQ81OrilATGNhIbj42xJKmK+3zhstGBCQ110ZiF2nIngPTEKxQQqf15SJsVnQfNuqQ==",
|
||||
"requires": {
|
||||
"tweetnacl": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.11.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||
@@ -2896,6 +2932,11 @@
|
||||
"is-number": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
|
||||
},
|
||||
"update-browserslist-db": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.4.tgz",
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@vueform/multiselect": "^2.5.1",
|
||||
"laravel-echo": "^1.13.0",
|
||||
"pusher-js": "^7.3.0",
|
||||
"sweetalert2": "^11.4.23",
|
||||
"vuedraggable": "^4.1.0"
|
||||
}
|
||||
|
||||
24
resources/js/bootstrap.js
vendored
24
resources/js/bootstrap.js
vendored
@@ -18,17 +18,17 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
||||
* allows your team to easily build robust real-time web applications.
|
||||
*/
|
||||
|
||||
// import Echo from 'laravel-echo';
|
||||
import Echo from 'laravel-echo';
|
||||
|
||||
// import Pusher from 'pusher-js';
|
||||
// window.Pusher = Pusher;
|
||||
import Pusher from 'pusher-js';
|
||||
window.Pusher = Pusher;
|
||||
|
||||
// window.Echo = new Echo({
|
||||
// broadcaster: 'pusher',
|
||||
// key: import.meta.env.VITE_PUSHER_APP_KEY,
|
||||
// wsHost: import.meta.env.VITE_PUSHER_HOST ?? `ws-${import.meta.env.VITE_PUSHER_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',
|
||||
// enabledTransports: ['ws', 'wss'],
|
||||
// });
|
||||
window.Echo = new Echo({
|
||||
broadcaster: 'pusher',
|
||||
key: import.meta.env.VITE_PUSHER_APP_KEY,
|
||||
wsHost: import.meta.env.VITE_PUSHER_APP_HOST || `localhost`,
|
||||
wsPort: import.meta.env.VITE_PUSHER_APP_PORT || 6001,
|
||||
wssPort: 443,
|
||||
forceTLS: (import.meta.env.VITE_PUSHER_SCHEME || 'http') === 'https',
|
||||
enabledTransports: ['ws', 'wss'],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user