Add stream start + end events

This commit is contained in:
Daniel Supernault 2022-06-26 20:10:10 -06:00
parent 6bf68c147e
commit a45deb93ed
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 103 additions and 1 deletions

View file

@ -0,0 +1,49 @@
<?php
namespace App\Events\LiveStream;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use App\Models\LiveStream;
class StreamEnd implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $livestream;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(LiveStream $livestream)
{
$this->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() ];
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace App\Events\LiveStream;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use App\Models\LiveStream;
class StreamStart implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $livestream;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(LiveStream $livestream)
{
$this->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() ];
}
}

View file

@ -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')) {