Skip to content

Commit c6c65fd

Browse files
committed
wip
1 parent f9d4404 commit c6c65fd

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

config/config.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
* Define the optional SSL context for your websocket connections.
7+
* You can see all available options at: http://php.net/manual/en/context.ssl.php
8+
*/
9+
'ssl' => [
10+
/*
11+
* Path to local certificate file on filesystem. It must be a PEM encoded file which
12+
* contains your certificate and private key. It can optionally contain the
13+
* certificate chain of issuers. The private key also may be contained
14+
* in a separate file specified by local_pk.
15+
*/
16+
'local_cert' => null,
17+
18+
/*
19+
* Path to local private key file on filesystem in case of separate files for
20+
* certificate (local_cert) and private key.
21+
*/
22+
'local_pk' => null,
23+
24+
/*
25+
* Passphrase with which your local_cert file was encoded.
26+
*/
27+
'passphrase' => null
28+
],
29+
30+
];

src/LaravelWebSocketsServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ class LaravelWebSocketsServiceProvider extends ServiceProvider
99
{
1010
public function boot()
1111
{
12+
$this->publishes([
13+
__DIR__.'/../config/config.php' => base_path('config/websockets.php'),
14+
], 'config');
15+
1216
$this->commands([
1317
Console\StartWebSocketServer::class,
1418
]);
1519
}
1620

1721
public function register()
1822
{
23+
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'websockets');
24+
1925
$this->app->singleton('websockets.router', function() {
2026
return new Router();
2127
});

src/Server/WebSocketServer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace BeyondCode\LaravelWebSockets\Server;
44

55
use Ratchet\Http\Router;
6+
use React\Socket\SecureServer;
7+
use React\Socket\Server;
68
use Ratchet\Http\HttpServer;
79
use Ratchet\Server\IoServer;
810
use React\EventLoop\LoopInterface;
9-
use React\Socket\Server as Reactor;
1011
use React\EventLoop\Factory as LoopFactory;
1112
use Symfony\Component\Routing\RequestContext;
1213
use Symfony\Component\Routing\Matcher\UrlMatcher;
@@ -63,7 +64,11 @@ public function run()
6364

6465
protected function createServer(): IoServer
6566
{
66-
$socket = new Reactor("{$this->host}:{$this->port}", $this->loop);
67+
$socket = new Server("{$this->host}:{$this->port}", $this->loop);
68+
69+
if (config('websockets.ssl.local_cert')) {
70+
$socket = new SecureServer($socket, $this->loop, config('websockets.ssl'));
71+
}
6772

6873
$urlMatcher = new UrlMatcher($this->routes, new RequestContext);
6974

0 commit comments

Comments
 (0)