From a45deb93edccb83b152bca38bea7ac84a21fa2c4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 26 Jun 2022 20:10:10 -0600 Subject: [PATCH] Add stream start + end events --- app/Events/LiveStream/StreamEnd.php | 49 +++++++++++++++++++ app/Events/LiveStream/StreamStart.php | 49 +++++++++++++++++++ app/Http/Controllers/LiveStreamController.php | 6 ++- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 app/Events/LiveStream/StreamEnd.php create mode 100644 app/Events/LiveStream/StreamStart.php diff --git a/app/Events/LiveStream/StreamEnd.php b/app/Events/LiveStream/StreamEnd.php new file mode 100644 index 000000000..15f35ce40 --- /dev/null +++ b/app/Events/LiveStream/StreamEnd.php @@ -0,0 +1,49 @@ +livestream = $livestream; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('live.chat.' . $this->livestream->profile_id); + } + + public function broadcastAs() + { + return 'stream.end'; + } + + public function broadcastWith() + { + return ['ts' => time() ]; + } +} diff --git a/app/Events/LiveStream/StreamStart.php b/app/Events/LiveStream/StreamStart.php new file mode 100644 index 000000000..c8517c2ce --- /dev/null +++ b/app/Events/LiveStream/StreamStart.php @@ -0,0 +1,49 @@ +livestream = $livestream; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('live.chat.' . $this->livestream->profile_id); + } + + public function broadcastAs() + { + return 'stream.start'; + } + + public function broadcastWith() + { + return ['ts' => time() ]; + } +} diff --git a/app/Http/Controllers/LiveStreamController.php b/app/Http/Controllers/LiveStreamController.php index bbac320ab..25c1baace 100644 --- a/app/Http/Controllers/LiveStreamController.php +++ b/app/Http/Controllers/LiveStreamController.php @@ -15,6 +15,8 @@ use App\Events\LiveStream\DeleteChatComment; use App\Events\LiveStream\BanUser; use App\Events\LiveStream\PinChatMessage; use App\Events\LiveStream\UnpinChatMessage; +use App\Events\LiveStream\StreamStart; +use App\Events\LiveStream\StreamEnd; class LiveStreamController extends Controller { @@ -373,6 +375,8 @@ class LiveStreamController extends Controller if($request->filled('name') && $token == false) { $stream->live_at = now(); $stream->save(); + + StreamStart::dispatch($stream); return []; } else { abort(400); @@ -389,7 +393,7 @@ class LiveStreamController extends Controller $name = $url['name'] ?? $request->input('name'); $stream = LiveStream::whereStreamId($name)->whereStreamKey($url['key'])->firstOrFail(); - + StreamEnd::dispatch($stream); LiveStreamService::clearChat($stream->profile_id); if(config('livestreaming.broadcast.delete_token_after_finished')) {