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

Commit 437df8b

Browse files
committed
wip
2 parents 957744d + 7abe196 commit 437df8b

35 files changed

+511
-195
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,16 @@ jobs:
1919
strategy:
2020
matrix:
2121
php:
22-
- '7.3'
23-
- '7.4'
22+
- '8.0'
23+
- '8.1'
2424
laravel:
25-
- 6.*
26-
- 7.*
27-
- 8.*
25+
- 9.*
2826
prefer:
2927
- 'prefer-lowest'
3028
- 'prefer-stable'
3129
include:
32-
- laravel: '6.*'
33-
testbench: '4.*'
34-
- laravel: '7.*'
35-
testbench: '5.*'
36-
- laravel: '8.*'
37-
testbench: '6.*'
30+
- laravel: '9.*'
31+
testbench: '7.*'
3832

3933
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} --${{ matrix.prefer }}
4034

@@ -48,6 +42,13 @@ jobs:
4842
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
4943
coverage: pcov
5044

45+
- name: Setup MySQL
46+
uses: mirromutth/[email protected]
47+
with:
48+
mysql version: '8.0'
49+
mysql database: 'websockets_test'
50+
mysql root password: 'password'
51+
5152
- name: Setup Redis
5253
uses: supercharge/[email protected]
5354
with:

composer.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@
2929
}
3030
],
3131
"require": {
32-
"cboden/ratchet": "^0.4.1",
33-
"clue/block-react": "^1.4",
32+
"php": "^8.0|^8.1",
3433
"clue/reactphp-sqlite": "^1.0",
3534
"react/mysql": "^0.5",
36-
"clue/redis-react": "^2.3",
35+
"cboden/ratchet": "^0.4.4",
36+
"clue/redis-react": "^2.6",
3737
"doctrine/dbal": "^2.9",
3838
"evenement/evenement": "^2.0|^3.0",
3939
"facade/ignition-contracts": "^1.0",
4040
"guzzlehttp/psr7": "^1.5",
41-
"illuminate/broadcasting": "^6.3|^7.0|^8.0",
42-
"illuminate/console": "^6.3|7.0|^8.0",
43-
"illuminate/http": "^6.3|^7.0|^8.0",
44-
"illuminate/queue": "^6.3|^7.0|^8.0",
45-
"illuminate/routing": "^6.3|^7.0|^8.0",
46-
"illuminate/support": "^6.3|^7.0|^8.0",
47-
"pusher/pusher-php-server": "^4.0",
48-
"react/promise": "^2.0",
49-
"symfony/http-kernel": "^4.0|^5.0",
41+
"illuminate/broadcasting": "^9.0",
42+
"illuminate/console": "^9.0",
43+
"illuminate/http": "^9.0",
44+
"illuminate/queue": "^9.0",
45+
"illuminate/routing": "^9.0",
46+
"illuminate/support": "^9.0",
47+
"pusher/pusher-php-server": "^6.0|^7.0",
48+
"react/promise": "^2.8",
49+
"symfony/http-kernel": "^5.0|^6.0",
5050
"symfony/psr-http-message-bridge": "^1.1|^2.0"
5151
},
5252
"require-dev": {
5353
"clue/buzz-react": "^2.9",
54+
"clue/block-react": "^1.4",
5455
"laravel/legacy-factories": "^1.1",
55-
"orchestra/database": "^4.0|^5.0|^6.0",
56-
"orchestra/testbench-browser-kit": "^4.0|^5.0|^6.0",
57-
"phpunit/phpunit": "^8.0|^9.0",
56+
"orchestra/testbench-browser-kit": "^7.0",
57+
"phpunit/phpunit": "^9.0",
5858
"ratchet/pawl": "^0.3.5"
5959
},
6060
"suggest": {

config/websockets.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
1717

18-
'path' => 'laravel-websockets',
18+
'domain' => env('LARAVEL_WEBSOCKETS_DOMAIN'),
19+
20+
'path' => env('LARAVEL_WEBSOCKETS_PATH', 'laravel-websockets'),
1921

2022
'middleware' => [
2123
'web',
@@ -60,16 +62,14 @@
6062
| MySql application manager
6163
|--------------------------------------------------------------------------
6264
|
63-
| The MySql database to use when using the MySql application manager.
65+
| The MySQL database connection to use.
6466
|
6567
*/
6668

6769
'mysql' => [
68-
'host' => 'localhost',
69-
'port' => 3306,
70-
'database' => 'default',
71-
'username' => 'root',
72-
'password' => 'root',
70+
'connection' => env('DB_CONNECTION', 'mysql'),
71+
72+
'table' => 'websockets_apps',
7373
]
7474
],
7575

@@ -100,7 +100,7 @@
100100
'enable_client_messages' => false,
101101
'enable_statistics' => true,
102102
'allowed_origins' => [
103-
//
103+
// env('LARAVEL_WEBSOCKETS_DOMAIN'),
104104
],
105105
],
106106
],
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateWebSocketsAppsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('websockets_apps', function (Blueprint $table) {
17+
$table->string('id')->index();
18+
$table->string('key');
19+
$table->string('secret');
20+
$table->string('name');
21+
$table->string('host')->nullable();
22+
$table->string('path')->nullable();
23+
$table->boolean('enable_client_messages')->default(false);
24+
$table->boolean('enable_statistics')->default(true);
25+
$table->unsignedInteger('capacity')->nullable();
26+
$table->string('allowed_origins');
27+
$table->nullableTimestamps();
28+
});
29+
}
30+
31+
/**
32+
* Reverse the migrations.
33+
*
34+
* @return void
35+
*/
36+
public function down()
37+
{
38+
Schema::dropIfExists('websockets_apps');
39+
}
40+
}

database/migrations/0000_00_00_000000_create_websockets_statistics_entries_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public function up()
1616
Schema::create('websockets_statistics_entries', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->string('app_id');
19-
$table->integer('peak_connection_count');
20-
$table->integer('websocket_message_count');
21-
$table->integer('api_message_count');
19+
$table->integer('peak_connections_count');
20+
$table->integer('websocket_messages_count');
21+
$table->integer('api_messages_count');
2222
$table->nullableTimestamps();
2323
});
2424
}

database/migrations/0000_00_00_000000_rename_statistics_counters.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

database/migrations/mysql/0000_00_00_000000_create_apps_table.sql

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/API/Controller.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,15 @@ protected function handleRequest(ConnectionInterface $connection)
225225
*/
226226
protected function sendAndClose(ConnectionInterface $connection, $response)
227227
{
228-
tap($connection)->send(JsonResponse::create($response))->close();
228+
tap($connection)->send(new JsonResponse($response))->close();
229229
}
230230

231231
/**
232232
* Ensure app existence.
233233
*
234234
* @param mixed $appId
235235
* @return PromiseInterface
236+
*
236237
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
237238
*/
238239
public function ensureValidAppId($appId)

src/API/TriggerEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __invoke(Request $request)
6464
'payload' => $request->data,
6565
]);
6666

67-
$deferred->resolve($request->json()->all());
67+
$deferred->resolve((object) []);
6868
});
6969
}
7070

src/Apps/ConfigAppManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public function findBySecret($appSecret): PromiseInterface
8383
*/
8484
public function createApp($appData): PromiseInterface
8585
{
86-
return resolvePromise($this->convertIntoApp(
87-
$appData
88-
));
86+
$this->apps->push($appData);
87+
88+
return resolvePromise();
8989
}
9090

9191
/**

src/Apps/MysqlAppManager.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public function __construct(ConnectionInterface $database)
2727
$this->database = $database;
2828
}
2929

30+
protected function getTableName(): string
31+
{
32+
return config('websockets.managers.mysql.table');
33+
}
34+
3035
/**
3136
* Get all apps.
3237
*
@@ -36,7 +41,7 @@ public function all(): PromiseInterface
3641
{
3742
$deferred = new Deferred();
3843

39-
$this->database->query('SELECT * FROM `apps`')
44+
$this->database->query('SELECT * FROM `'.$this->getTableName().'`')
4045
->then(function (QueryResult $result) use ($deferred) {
4146
$deferred->resolve($result->resultRows);
4247
}, function ($error) use ($deferred) {
@@ -56,7 +61,7 @@ public function findById($appId): PromiseInterface
5661
{
5762
$deferred = new Deferred();
5863

59-
$this->database->query('SELECT * from `apps` WHERE `id` = ?', [$appId])
64+
$this->database->query('SELECT * from `'.$this->getTableName().'` WHERE `id` = ?', [$appId])
6065
->then(function (QueryResult $result) use ($deferred) {
6166
$deferred->resolve($this->convertIntoApp($result->resultRows[0]));
6267
}, function ($error) use ($deferred) {
@@ -76,7 +81,7 @@ public function findByKey($appKey): PromiseInterface
7681
{
7782
$deferred = new Deferred();
7883

79-
$this->database->query('SELECT * from `apps` WHERE `key` = ?', [$appKey])
84+
$this->database->query('SELECT * from `'.$this->getTableName().'` WHERE `key` = ?', [$appKey])
8085
->then(function (QueryResult $result) use ($deferred) {
8186
$deferred->resolve($this->convertIntoApp($result->resultRows[0]));
8287
}, function ($error) use ($deferred) {
@@ -96,7 +101,7 @@ public function findBySecret($appSecret): PromiseInterface
96101
{
97102
$deferred = new Deferred();
98103

99-
$this->database->query('SELECT * from `apps` WHERE `secret` = ?', [$appSecret])
104+
$this->database->query('SELECT * from `'.$this->getTableName().'` WHERE `secret` = ?', [$appSecret])
100105
->then(function (QueryResult $result) use ($deferred) {
101106
$deferred->resolve($this->convertIntoApp($result->resultRows[0]));
102107
}, function ($error) use ($deferred) {
@@ -153,8 +158,8 @@ public function createApp($appData): PromiseInterface
153158
$deferred = new Deferred();
154159

155160
$this->database->query(
156-
'INSERT INTO `apps` (id, key, secret, name, enable_client_messages, enable_statistics, allowed_origins) VALUES (?, ?, ?, ?, ?, ?, ?)',
157-
[$appData['id'], $appData['key'], $appData['secret'], $appData['name'], $appData['enable_client_messages'], $appData['enable_statistics'], $appData['allowed_origins']])
161+
'INSERT INTO `'.$this->getTableName().'` (`id`, `key`, `secret`, `name`, `enable_client_messages`, `enable_statistics`, `allowed_origins`, `capacity`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
162+
[$appData['id'], $appData['key'], $appData['secret'], $appData['name'], $appData['enable_client_messages'], $appData['enable_statistics'], $appData['allowed_origins'] ?? '', $appData['capacity'] ?? null])
158163
->then(function () use ($deferred) {
159164
$deferred->resolve();
160165
}, function ($error) use ($deferred) {

src/Apps/SQLiteAppManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public function createApp($appData): PromiseInterface
153153
$deferred = new Deferred();
154154

155155
$this->database->query('
156-
INSERT INTO apps (id, key, secret, name, enable_client_messages, enable_statistics, allowed_origins)
157-
VALUES (:id, :key, :secret, :name, :enable_client_messages, :enable_statistics, :allowed_origins)
156+
INSERT INTO apps (id, key, secret, name, host, path, enable_client_messages, enable_statistics, capacity, allowed_origins)
157+
VALUES (:id, :key, :secret, :name, :host, :path, :enable_client_messages, :enable_statistics, :capacity, :allowed_origins)
158158
', $appData)
159159
->then(function (Result $result) use ($deferred) {
160160
$deferred->resolve();

src/ChannelManagers/RedisChannelManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public function getConnectionsFromSet(int $start = 0, int $stop = 0, bool $stric
577577
* Add a channel to the set list.
578578
*
579579
* @param string|int $appId
580-
* @param string $channel
580+
* @param string $channel
581581
* @return PromiseInterface
582582
*/
583583
public function addChannelToSet($appId, string $channel): PromiseInterface

src/Channels/Channel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function hasConnections(): bool
7373
* Add a new connection to the channel.
7474
*
7575
* @see https://pusher.com/docs/pusher_protocol#presence-channel-events
76+
*
7677
* @param \Ratchet\ConnectionInterface $connection
7778
* @param \stdClass $payload
7879
* @return bool
@@ -226,6 +227,7 @@ public function broadcastLocallyToEveryoneExcept(stdClass $payload, ?string $soc
226227
* @param \Ratchet\ConnectionInterface $connection
227228
* @param \stdClass $payload
228229
* @return void
230+
*
229231
* @throws InvalidSignature
230232
*/
231233
protected function verifySignature(ConnectionInterface $connection, stdClass $payload)

src/Channels/PresenceChannel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ class PresenceChannel extends PrivateChannel
1515
* Subscribe to the channel.
1616
*
1717
* @see https://pusher.com/docs/pusher_protocol#presence-channel-events
18+
*
1819
* @param \Ratchet\ConnectionInterface $connection
1920
* @param \stdClass $payload
2021
* @return bool
22+
*
2123
* @throws InvalidSignature
2224
*/
2325
public function subscribe(ConnectionInterface $connection, stdClass $payload): bool

src/Channels/PrivateChannel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ class PrivateChannel extends Channel
1212
* Subscribe to the channel.
1313
*
1414
* @see https://pusher.com/docs/pusher_protocol#presence-channel-events
15+
*
1516
* @param \Ratchet\ConnectionInterface $connection
1617
* @param \stdClass $payload
1718
* @return bool
19+
*
1820
* @throws InvalidSignature
1921
*/
2022
public function subscribe(ConnectionInterface $connection, stdClass $payload): bool

0 commit comments

Comments
 (0)