Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 4a5f354

Browse files
authored
Merge pull request #446 from beyondcode/fix/config
[2.x] Config Changes
2 parents d11daad + 1e08b80 commit 4a5f354

File tree

3 files changed

+179
-93
lines changed

3 files changed

+179
-93
lines changed

config/websockets.php

Lines changed: 172 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,79 @@
11
<?php
22

3-
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
4-
53
return [
64

75
/*
8-
* Set a custom dashboard configuration
9-
*/
6+
|--------------------------------------------------------------------------
7+
| Dashboard Settings
8+
|--------------------------------------------------------------------------
9+
|
10+
| You can configure the dashboard settings from here.
11+
|
12+
*/
13+
1014
'dashboard' => [
15+
1116
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
17+
18+
'path' => 'laravel-websockets',
19+
20+
'middleware' => [
21+
'web',
22+
\BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize::class,
23+
],
24+
25+
],
26+
27+
'managers' => [
28+
29+
/*
30+
|--------------------------------------------------------------------------
31+
| Application Manager
32+
|--------------------------------------------------------------------------
33+
|
34+
| An Application manager determines how your websocket server allows
35+
| the use of the TCP protocol based on, for example, a list of allowed
36+
| applications.
37+
| By default, it uses the defined array in the config file, but you can
38+
| anytime implement the same interface as the class and add your own
39+
| custom method to retrieve the apps.
40+
|
41+
*/
42+
43+
'app' => \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class,
44+
45+
/*
46+
|--------------------------------------------------------------------------
47+
| Channel Manager
48+
|--------------------------------------------------------------------------
49+
|
50+
| When users subscribe or unsubscribe from specific channels,
51+
| the connections are stored to keep track of any interaction with the
52+
| WebSocket server.
53+
| You can however add your own implementation that will help the store
54+
| of the channels alongside their connections.
55+
|
56+
*/
57+
58+
'channel' => \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager::class,
59+
1260
],
1361

1462
/*
15-
* This package comes with multi tenancy out of the box. Here you can
16-
* configure the different apps that can use the webSockets server.
17-
*
18-
* Optionally you specify capacity so you can limit the maximum
19-
* concurrent connections for a specific app.
20-
*
21-
* Optionally you can disable client events so clients cannot send
22-
* messages to each other via the webSockets.
23-
*/
63+
|--------------------------------------------------------------------------
64+
| Applications Repository
65+
|--------------------------------------------------------------------------
66+
|
67+
| By default, the only allowed app is the one you define with
68+
| your PUSHER_* variables from .env.
69+
| You can configure to use multiple apps if you need to, or use
70+
| a custom App Manager that will handle the apps from a database, per se.
71+
|
72+
| You can apply multiple settings, like the maximum capacity, enable
73+
| client-to-client messages or statistics.
74+
|
75+
*/
76+
2477
'apps' => [
2578
[
2679
'id' => env('PUSHER_APP_ID'),
@@ -35,107 +88,142 @@
3588
],
3689

3790
/*
38-
* This class is responsible for finding the apps. The default provider
39-
* will use the apps defined in this config file.
40-
*
41-
* You can create a custom provider by implementing the
42-
* `AppProvider` interface.
43-
*/
44-
'app_provider' => BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class,
91+
|--------------------------------------------------------------------------
92+
| Allowed Origins
93+
|--------------------------------------------------------------------------
94+
|
95+
| If not empty, you can whitelist certain origins that will be allowed
96+
| to connect to the websocket server.
97+
|
98+
*/
4599

46-
/*
47-
* This array contains the hosts of which you want to allow incoming requests.
48-
* Leave this empty if you want to accept requests from all hosts.
49-
*/
50100
'allowed_origins' => [
51101
//
52102
],
53103

54104
/*
55-
* The maximum request size in kilobytes that is allowed for an incoming WebSocket request.
56-
*/
105+
|--------------------------------------------------------------------------
106+
| Maximum Request Size
107+
|--------------------------------------------------------------------------
108+
|
109+
| The maximum request size in kilobytes that is allowed for
110+
| an incoming WebSocket request.
111+
|
112+
*/
113+
57114
'max_request_size_in_kb' => 250,
58115

59116
/*
60-
* This path will be used to register the necessary routes for the package.
61-
*/
62-
'path' => 'laravel-websockets',
117+
|--------------------------------------------------------------------------
118+
| SSL Configuration
119+
|--------------------------------------------------------------------------
120+
|
121+
| By default, the configuration allows only on HTTP. For SSL, you need
122+
| to set up the the certificate, the key, and optionally, the passphrase
123+
| for the private key.
124+
| You will need to restart the server for the settings to take place.
125+
|
126+
*/
127+
128+
'ssl' => [
129+
130+
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
131+
132+
'capath' => env('LARAVEL_WEBSOCKETS_SSL_CA', null),
133+
134+
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
135+
136+
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
137+
138+
'verify_peer' => env('APP_ENV') === 'production',
139+
140+
'allow_self_signed' => env('APP_ENV') !== 'production',
63141

64-
/*
65-
* Dashboard Routes Middleware
66-
*
67-
* These middleware will be assigned to every dashboard route, giving you
68-
* the chance to add your own middleware to this list or change any of
69-
* the existing middleware. Or, you can simply stick with this list.
70-
*/
71-
'middleware' => [
72-
'web',
73-
Authorize::class,
74142
],
75143

76144
'statistics' => [
145+
77146
/*
78-
* This model will be used to store the statistics of the WebSocketsServer.
79-
* The only requirement is that the model should extend
80-
* `WebSocketsStatisticsEntry` provided by this package.
81-
*/
147+
|--------------------------------------------------------------------------
148+
| Statistics Eloquent Model
149+
|--------------------------------------------------------------------------
150+
|
151+
| This model will be used to store the statistics of the WebSocketsServer.
152+
| The only requirement is that the model should extend
153+
| `WebSocketsStatisticsEntry` provided by this package.
154+
|
155+
*/
156+
82157
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
83158

84-
/**
85-
* The Statistics Logger will, by default, handle the incoming statistics, store them
86-
* and then release them into the database on each interval defined below.
87-
*/
159+
/*
160+
|--------------------------------------------------------------------------
161+
| Statistics Logger Handler
162+
|--------------------------------------------------------------------------
163+
|
164+
| The Statistics Logger will, by default, handle the incoming statistics,
165+
| store them into an array and then store them into the database
166+
| on each interval.
167+
|
168+
*/
169+
88170
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger::class,
89171

90172
/*
91-
* Here you can specify the interval in seconds at which statistics should be logged.
92-
*/
173+
|--------------------------------------------------------------------------
174+
| Statistics Interval Period
175+
|--------------------------------------------------------------------------
176+
|
177+
| Here you can specify the interval in seconds at which
178+
| statistics should be logged.
179+
|
180+
*/
181+
93182
'interval_in_seconds' => 60,
94183

95184
/*
96-
* When the clean-command is executed, all recorded statistics older than
97-
* the number of days specified here will be deleted.
98-
*/
185+
|--------------------------------------------------------------------------
186+
| Statistics Deletion Period
187+
|--------------------------------------------------------------------------
188+
|
189+
| When the clean-command is executed, all recorded statistics older than
190+
| the number of days specified here will be deleted.
191+
|
192+
*/
193+
99194
'delete_statistics_older_than_days' => 60,
100195

101196
/*
102-
* Use an DNS resolver to make the requests to the statistics logger
103-
* default is to resolve everything to 127.0.0.1.
104-
*/
197+
|--------------------------------------------------------------------------
198+
| DNS Lookup
199+
|--------------------------------------------------------------------------
200+
|
201+
| Use an DNS resolver to make the requests to the statistics logger
202+
| default is to resolve everything to 127.0.0.1.
203+
|
204+
*/
205+
105206
'perform_dns_lookup' => false,
106-
],
107207

108-
/*
109-
* Define the optional SSL context for your WebSocket connections.
110-
* You can see all available options at: http://php.net/manual/en/context.ssl.php
111-
*/
112-
'ssl' => [
113208
/*
114-
* Path to local certificate file on filesystem. It must be a PEM encoded file which
115-
* contains your certificate and private key. It can optionally contain the
116-
* certificate chain of issuers. The private key also may be contained
117-
* in a separate file specified by local_pk.
118-
*/
119-
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
209+
|--------------------------------------------------------------------------
210+
| DNS Lookup TLS Settings
211+
|--------------------------------------------------------------------------
212+
|
213+
| You can configure the DNS Lookup Connector the TLS settings.
214+
| Check the available options here:
215+
| https://github.com/reactphp/socket/blob/master/src/Connector.php#L29
216+
|
217+
*/
120218

121-
/*
122-
* Path to local private key file on filesystem in case of separate files for
123-
* certificate (local_cert) and private key.
124-
*/
125-
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
219+
'tls' => [
220+
221+
'verify_peer' => env('APP_ENV') === 'production',
222+
223+
'verify_peer_name' => env('APP_ENV') === 'production',
224+
225+
],
126226

127-
/*
128-
* Passphrase for your local_cert file.
129-
*/
130-
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
131227
],
132228

133-
/*
134-
* Channel Manager
135-
* This class handles how channel persistence is handled.
136-
* By default, persistence is stored in an array by the running webserver.
137-
* The only requirement is that the class should implement
138-
* `ChannelManager` interface provided by this package.
139-
*/
140-
'channel_manager' => \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager::class,
141229
];

src/Console/StartWebSocketServer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ protected function configureStatisticsLogger()
5656
{
5757
$connector = new Connector($this->loop, [
5858
'dns' => $this->getDnsResolver(),
59-
'tls' => [
60-
'verify_peer' => config('app.env') === 'production',
61-
'verify_peer_name' => config('app.env') === 'production',
62-
],
59+
'tls' => config('websockets.statistics.tls'),
6360
]);
6461

6562
$browser = new Browser($this->loop, $connector);

src/WebSocketsServiceProvider.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@ public function register()
5454
});
5555

5656
$this->app->singleton(ChannelManager::class, function () {
57-
return config('websockets.channel_manager') !== null && class_exists(config('websockets.channel_manager'))
58-
? app(config('websockets.channel_manager')) : new ArrayChannelManager();
57+
$channelManager = config('websockets.managers.channel', ArrayChannelManager::class);
58+
59+
return new $channelManager;
5960
});
6061

6162
$this->app->singleton(AppProvider::class, function () {
62-
return app(config('websockets.app_provider'));
63+
return app(config('websockets.managers.app'));
6364
});
6465
}
6566

6667
protected function registerRoutes()
6768
{
68-
Route::prefix(config('websockets.path'))->group(function () {
69-
Route::middleware(config('websockets.middleware', [AuthorizeDashboard::class]))->group(function () {
69+
Route::prefix(config('websockets.dashboard.path'))->group(function () {
70+
Route::middleware(config('websockets.dashboard.middleware', [AuthorizeDashboard::class]))->group(function () {
7071
Route::get('/', ShowDashboard::class);
7172
Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']);
7273
Route::post('auth', AuthenticateDashboard::class);

0 commit comments

Comments
 (0)