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

Commit 765e772

Browse files
committed
wip
1 parent d11daad commit 765e772

File tree

2 files changed

+82
-63
lines changed

2 files changed

+82
-63
lines changed

config/websockets.php

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,61 @@
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,
1259
],
1360

1461
/*
@@ -34,15 +81,6 @@
3481
],
3582
],
3683

37-
/*
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,
45-
4684
/*
4785
* This array contains the hosts of which you want to allow incoming requests.
4886
* Leave this empty if you want to accept requests from all hosts.
@@ -57,23 +95,32 @@
5795
'max_request_size_in_kb' => 250,
5896

5997
/*
60-
* This path will be used to register the necessary routes for the package.
98+
* Define the optional SSL context for your WebSocket connections.
99+
* You can see all available options at: http://php.net/manual/en/context.ssl.php
61100
*/
62-
'path' => 'laravel-websockets',
101+
'ssl' => [
102+
/*
103+
* Path to local certificate file on filesystem. It must be a PEM encoded file which
104+
* contains your certificate and private key. It can optionally contain the
105+
* certificate chain of issuers. The private key also may be contained
106+
* in a separate file specified by local_pk.
107+
*/
108+
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
63109

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,
110+
/*
111+
* Path to local private key file on filesystem in case of separate files for
112+
* certificate (local_cert) and private key.
113+
*/
114+
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
115+
116+
/*
117+
* Passphrase for your local_cert file.
118+
*/
119+
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
74120
],
75121

76122
'statistics' => [
123+
77124
/*
78125
* This model will be used to store the statistics of the WebSocketsServer.
79126
* The only requirement is that the model should extend
@@ -85,57 +132,28 @@
85132
* The Statistics Logger will, by default, handle the incoming statistics, store them
86133
* and then release them into the database on each interval defined below.
87134
*/
135+
88136
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger::class,
89137

90138
/*
91139
* Here you can specify the interval in seconds at which statistics should be logged.
92140
*/
141+
93142
'interval_in_seconds' => 60,
94143

95144
/*
96145
* When the clean-command is executed, all recorded statistics older than
97146
* the number of days specified here will be deleted.
98147
*/
148+
99149
'delete_statistics_older_than_days' => 60,
100150

101151
/*
102152
* Use an DNS resolver to make the requests to the statistics logger
103153
* default is to resolve everything to 127.0.0.1.
104154
*/
105-
'perform_dns_lookup' => false,
106-
],
107-
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' => [
113-
/*
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),
120-
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),
126155

127-
/*
128-
* Passphrase for your local_cert file.
129-
*/
130-
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
156+
'perform_dns_lookup' => false,
131157
],
132158

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,
141159
];

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)