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

Commit 016a6f4

Browse files
committed
clean up endpoint
1 parent e1eecbc commit 016a6f4

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/Dashboard/Http/Controllers/SendMessage.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,42 @@
22

33
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
44

5+
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
56
use Pusher\Pusher;
67
use Illuminate\Http\Request;
78
use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
89

910
class SendMessage
1011
{
1112
public function __invoke(Request $request)
13+
{
14+
$validated = $request->validate([
15+
'appId' => ['required', new AppId()],
16+
'key' => 'required',
17+
'secret' => 'required',
18+
'channel' => 'required',
19+
'event' => 'required',
20+
'data' => 'json',
21+
]);
22+
23+
$this->getPusherBroadcaster($validated)->broadcast(
24+
[$validated['channel']],
25+
$validated['event'],
26+
json_decode($validated['data'], true)
27+
);
28+
29+
return 'ok';
30+
}
31+
32+
protected function getPusherBroadcaster(array $validated): PusherBroadcaster
1233
{
1334
$pusher = new Pusher(
14-
$request->key,
15-
$request->secret,
16-
$request->appId,
35+
$validated['key'],
36+
$validated['secret'],
37+
$validated['appId'],
1738
config('broadcasting.connections.pusher.options', [])
1839
);
1940

20-
return (new PusherBroadcaster($pusher))
21-
->broadcast(
22-
[$request->channel],
23-
$request->event,
24-
json_decode($request->data, true)
25-
);
41+
return new PusherBroadcaster($pusher);
2642
}
2743
}

0 commit comments

Comments
 (0)