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

Commit 1bfbbdb

Browse files
authored
Merge branch '2.x' into redis-replication
2 parents 6e85197 + 4a5f354 commit 1bfbbdb

File tree

7 files changed

+288
-104
lines changed

7 files changed

+288
-104
lines changed

.github/workflows/run-tests.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ jobs:
3737
with:
3838
php-version: ${{ matrix.php }}
3939
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
40-
coverage: none
40+
coverage: pcov
4141

4242
- name: Install dependencies
4343
run: |
4444
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
4545
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
4646
4747
- name: Execute tests
48-
run: vendor/bin/phpunit
48+
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
49+
50+
- uses: codecov/codecov-action@v1
51+
with:
52+
fail_ci_if_error: false

config/websockets.php

Lines changed: 199 additions & 88 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,114 +88,172 @@
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

142+
],
143+
64144
/*
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.
145+
* You can enable replication to publish and subscribe to messages across the driver
70146
*/
71-
'middleware' => [
72-
'web',
73-
Authorize::class,
147+
/*
148+
|--------------------------------------------------------------------------
149+
| Broadcasting Replication
150+
|--------------------------------------------------------------------------
151+
|
152+
| You can enable replication to publish and subscribe to
153+
| messages across the driver.
154+
|
155+
| By default, it is disabled, but you can configure it to use drivers
156+
| like Redis to ensure connection between multiple instances of
157+
| WebSocket servers.
158+
|
159+
*/
160+
'replication' => [
161+
162+
'enabled' => false,
163+
164+
'driver' => 'redis',
165+
166+
'redis' => [
167+
168+
'connection' => 'default',
169+
170+
],
171+
74172
],
75173

76174
'statistics' => [
175+
77176
/*
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-
*/
177+
|--------------------------------------------------------------------------
178+
| Statistics Eloquent Model
179+
|--------------------------------------------------------------------------
180+
|
181+
| This model will be used to store the statistics of the WebSocketsServer.
182+
| The only requirement is that the model should extend
183+
| `WebSocketsStatisticsEntry` provided by this package.
184+
|
185+
*/
186+
82187
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
83188

84189
/*
85-
* Here you can specify the interval in seconds at which statistics should be logged.
86-
*/
190+
|--------------------------------------------------------------------------
191+
| Statistics Logger Handler
192+
|--------------------------------------------------------------------------
193+
|
194+
| The Statistics Logger will, by default, handle the incoming statistics,
195+
| store them into an array and then store them into the database
196+
| on each interval.
197+
|
198+
*/
199+
200+
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger::class,
201+
202+
/*
203+
|--------------------------------------------------------------------------
204+
| Statistics Interval Period
205+
|--------------------------------------------------------------------------
206+
|
207+
| Here you can specify the interval in seconds at which
208+
| statistics should be logged.
209+
|
210+
*/
211+
87212
'interval_in_seconds' => 60,
88213

89214
/*
90-
* When the clean-command is executed, all recorded statistics older than
91-
* the number of days specified here will be deleted.
92-
*/
215+
|--------------------------------------------------------------------------
216+
| Statistics Deletion Period
217+
|--------------------------------------------------------------------------
218+
|
219+
| When the clean-command is executed, all recorded statistics older than
220+
| the number of days specified here will be deleted.
221+
|
222+
*/
223+
93224
'delete_statistics_older_than_days' => 60,
94225

95226
/*
96-
* Use an DNS resolver to make the requests to the statistics logger
97-
* default is to resolve everything to 127.0.0.1.
98-
*/
99-
'perform_dns_lookup' => false,
100-
],
227+
|--------------------------------------------------------------------------
228+
| DNS Lookup
229+
|--------------------------------------------------------------------------
230+
|
231+
| Use an DNS resolver to make the requests to the statistics logger
232+
| default is to resolve everything to 127.0.0.1.
233+
|
234+
*/
101235

102-
/*
103-
* Define the optional SSL context for your WebSocket connections.
104-
* You can see all available options at: http://php.net/manual/en/context.ssl.php
105-
*/
106-
'ssl' => [
107-
/*
108-
* Path to local certificate file on filesystem. It must be a PEM encoded file which
109-
* contains your certificate and private key. It can optionally contain the
110-
* certificate chain of issuers. The private key also may be contained
111-
* in a separate file specified by local_pk.
112-
*/
113-
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
236+
'perform_dns_lookup' => false,
114237

115238
/*
116-
* Path to local private key file on filesystem in case of separate files for
117-
* certificate (local_cert) and private key.
118-
*/
119-
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
239+
|--------------------------------------------------------------------------
240+
| DNS Lookup TLS Settings
241+
|--------------------------------------------------------------------------
242+
|
243+
| You can configure the DNS Lookup Connector the TLS settings.
244+
| Check the available options here:
245+
| https://github.com/reactphp/socket/blob/master/src/Connector.php#L29
246+
|
247+
*/
120248

121-
/*
122-
* Passphrase for your local_cert file.
123-
*/
124-
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
125-
],
249+
'tls' => [
126250

127-
/*
128-
* You can enable replication to publish and subscribe to messages across the driver
129-
*/
130-
'replication' => [
131-
'enabled' => false,
251+
'verify_peer' => env('APP_ENV') === 'production',
132252

133-
'driver' => 'redis',
253+
'verify_peer_name' => env('APP_ENV') === 'production',
134254

135-
'redis' => [
136-
'connection' => 'default',
137255
],
256+
138257
],
139258

140-
/*
141-
* Channel Manager
142-
* This class handles how channel persistence is handled.
143-
* By default, persistence is stored in an array by the running webserver.
144-
* The only requirement is that the class should implement
145-
* `ChannelManager` interface provided by this package.
146-
*/
147-
'channel_manager' => \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager::class,
148259
];

resources/views/dashboard.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
wssPort: this.port === null ? 6001 : this.port,
119119
wsPath: this.app.path === null ? '' : this.app.path,
120120
disableStats: true,
121-
authEndpoint: '/{{ request()->path() }}/auth',
121+
authEndpoint: '{{ url('/auth') }}',
122122
auth: {
123123
headers: {
124124
'X-CSRF-Token': "{{ csrf_token() }}",
@@ -162,7 +162,7 @@
162162
},
163163
164164
loadChart() {
165-
$.getJSON('/{{ request()->path() }}/api/'+this.app.id+'/statistics', (data) => {
165+
$.getJSON('{{ url('/api') }}/' + this.app.id + '/statistics', (data) => {
166166
167167
let chartData = [
168168
{
@@ -246,7 +246,7 @@
246246
},
247247
248248
sendEvent() {
249-
$.post('/{{ request()->path() }}/event', {
249+
$.post('{{ url('/event') }}', {
250250
_token: '{{ csrf_token() }}',
251251
key: this.app.key,
252252
secret: this.app.secret,

0 commit comments

Comments
 (0)