Skip to content

Commit 37719bf

Browse files
author
Chaitali Sakhale
committed
Merge branch 'master' into schema-check-breaks
2 parents c5c1161 + 8383054 commit 37719bf

File tree

10 files changed

+94
-11
lines changed

10 files changed

+94
-11
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
*/
8282
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
8383

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+
*/
88+
'logger' => BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
89+
8490
/*
8591
* Here you can specify the interval in seconds at which statistics should be logged.
8692
*/

docs/basic-usage/pusher.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ window.Echo = new Echo({
111111
key: 'your-pusher-key',
112112
wsHost: window.location.hostname,
113113
wsPort: 6001,
114+
forceTLS: false,
114115
disableStats: true,
115116
});
116117
```

docs/basic-usage/ssl.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ php artisan websockets:serve
4949
## Client configuration
5050

5151
When your SSL settings are in place and working, you still need to tell Laravel Echo that it should make use of it.
52-
You can do this by specifying the `encrypted` property in your JavaScript file, like this:
52+
You can do this by specifying the `forceTLS` property in your JavaScript file, like this:
5353

5454
```js
5555
import Echo from "laravel-echo"
@@ -62,7 +62,7 @@ window.Echo = new Echo({
6262
wsHost: window.location.hostname,
6363
wsPort: 6001,
6464
disableStats: true,
65-
encrypted: true
65+
forceTLS: true
6666
});
6767
```
6868

docs/faq/scaling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ Here is another benchmark that was run on a 2GB Digital Ocean droplet with 2 CPU
1515

1616
![Benchmark](/img/simultaneous_users_2gb.png)
1717

18-
Make sure to take a look at the [Deployment Tips](/1.0/faq/deploying.html) to find out how to improve your specific setup.
18+
Make sure to take a look at the [Deployment Tips](/docs/laravel-websockets/faq/deploying) to find out how to improve your specific setup.

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(request()->path().'/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(request()->path().'/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(request()->path().'/event') }}', {
250250
_token: '{{ csrf_token() }}',
251251
key: this.app.key,
252252
secret: this.app.secret,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Console;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\InteractsWithTime;
8+
9+
class RestartWebSocketServer extends Command
10+
{
11+
use InteractsWithTime;
12+
13+
protected $signature = 'websockets:restart';
14+
15+
protected $description = 'Restart the Laravel WebSocket Server';
16+
17+
public function handle()
18+
{
19+
Cache::forever('beyondcode:websockets:restart', $this->currentTime());
20+
21+
$this->info('Broadcasting WebSocket server restart signal.');
22+
}
23+
}

src/Console/StartWebSocketServer.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
1010
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
1111
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
12-
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
1312
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
1413
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
1514
use Clue\React\Buzz\Browser;
1615
use Illuminate\Console\Command;
16+
use Illuminate\Support\Facades\Cache;
1717
use React\Dns\Config\Config as DnsConfig;
1818
use React\Dns\Resolver\Factory as DnsFactory;
1919
use React\Dns\Resolver\ResolverInterface;
@@ -29,6 +29,9 @@ class StartWebSocketServer extends Command
2929
/** @var \React\EventLoop\LoopInterface */
3030
protected $loop;
3131

32+
/** @var int */
33+
protected $lastRestart;
34+
3235
public function __construct()
3336
{
3437
parent::__construct();
@@ -43,6 +46,7 @@ public function handle()
4346
->configureHttpLogger()
4447
->configureMessageLogger()
4548
->configureConnectionLogger()
49+
->configureRestartTimer()
4650
->registerEchoRoutes()
4751
->registerCustomRoutes()
4852
->startWebSocketServer();
@@ -61,7 +65,9 @@ protected function configureStatisticsLogger()
6165
$browser = new Browser($this->loop, $connector);
6266

6367
app()->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
64-
return new HttpStatisticsLogger(app(ChannelManager::class), $browser);
68+
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class);
69+
70+
return new $class(app(ChannelManager::class), $browser);
6571
});
6672

6773
$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function () {
@@ -104,6 +110,19 @@ protected function configureConnectionLogger()
104110
return $this;
105111
}
106112

113+
public function configureRestartTimer()
114+
{
115+
$this->lastRestart = $this->getLastRestart();
116+
117+
$this->loop->addPeriodicTimer(10, function () {
118+
if ($this->getLastRestart() !== $this->lastRestart) {
119+
$this->loop->stop();
120+
}
121+
});
122+
123+
return $this;
124+
}
125+
107126
protected function registerEchoRoutes()
108127
{
109128
WebSocketsRouter::echo();
@@ -150,4 +169,9 @@ protected function getDnsResolver(): ResolverInterface
150169
$this->loop
151170
);
152171
}
172+
173+
protected function getLastRestart()
174+
{
175+
return Cache::get('beyondcode:websockets:restart', 0);
176+
}
153177
}

src/WebSocketsServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager;
1616
use Illuminate\Support\Facades\Gate;
1717
use Illuminate\Support\Facades\Route;
18+
use Illuminate\Support\Facades\Schema;
1819
use Illuminate\Support\ServiceProvider;
1920

2021
class WebSocketsServiceProvider extends ServiceProvider
@@ -25,7 +26,7 @@ public function boot()
2526
__DIR__.'/../config/websockets.php' => base_path('config/websockets.php'),
2627
], 'config');
2728

28-
if (! class_exists('CreateWebSocketsStatisticsEntries')) {
29+
if (! Schema::hasTable('websockets_statistics_entries')) {
2930
$this->publishes([
3031
__DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_websockets_statistics_entries_table.php'),
3132
], 'migrations');
@@ -40,6 +41,7 @@ public function boot()
4041
$this->commands([
4142
Console\StartWebSocketServer::class,
4243
Console\CleanStatistics::class,
44+
Console\RestartWebSocketServer::class,
4345
]);
4446
}
4547

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Tests\Commands;
4+
5+
use Artisan;
6+
use BeyondCode\LaravelWebSockets\Tests\TestCase;
7+
use Illuminate\Support\Facades\Cache;
8+
use Illuminate\Support\InteractsWithTime;
9+
10+
class RestartWebSocketServerTest extends TestCase
11+
{
12+
use InteractsWithTime;
13+
14+
/** @test */
15+
public function it_can_broadcast_restart_signal()
16+
{
17+
$start = $this->currentTime();
18+
19+
Artisan::call('websockets:restart');
20+
21+
$this->assertGreaterThanOrEqual($start, Cache::get('beyondcode:websockets:restart', 0));
22+
}
23+
}

0 commit comments

Comments
 (0)