mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
Add stream start + end events
This commit is contained in:
parent
6bf68c147e
commit
a45deb93ed
3 changed files with 103 additions and 1 deletions
49
app/Events/LiveStream/StreamEnd.php
Normal file
49
app/Events/LiveStream/StreamEnd.php
Normal 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() ];
|
||||||
|
}
|
||||||
|
}
|
49
app/Events/LiveStream/StreamStart.php
Normal file
49
app/Events/LiveStream/StreamStart.php
Normal 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() ];
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,8 @@ use App\Events\LiveStream\DeleteChatComment;
|
||||||
use App\Events\LiveStream\BanUser;
|
use App\Events\LiveStream\BanUser;
|
||||||
use App\Events\LiveStream\PinChatMessage;
|
use App\Events\LiveStream\PinChatMessage;
|
||||||
use App\Events\LiveStream\UnpinChatMessage;
|
use App\Events\LiveStream\UnpinChatMessage;
|
||||||
|
use App\Events\LiveStream\StreamStart;
|
||||||
|
use App\Events\LiveStream\StreamEnd;
|
||||||
|
|
||||||
class LiveStreamController extends Controller
|
class LiveStreamController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -373,6 +375,8 @@ class LiveStreamController extends Controller
|
||||||
if($request->filled('name') && $token == false) {
|
if($request->filled('name') && $token == false) {
|
||||||
$stream->live_at = now();
|
$stream->live_at = now();
|
||||||
$stream->save();
|
$stream->save();
|
||||||
|
|
||||||
|
StreamStart::dispatch($stream);
|
||||||
return [];
|
return [];
|
||||||
} else {
|
} else {
|
||||||
abort(400);
|
abort(400);
|
||||||
|
@ -389,7 +393,7 @@ class LiveStreamController extends Controller
|
||||||
$name = $url['name'] ?? $request->input('name');
|
$name = $url['name'] ?? $request->input('name');
|
||||||
|
|
||||||
$stream = LiveStream::whereStreamId($name)->whereStreamKey($url['key'])->firstOrFail();
|
$stream = LiveStream::whereStreamId($name)->whereStreamKey($url['key'])->firstOrFail();
|
||||||
|
StreamEnd::dispatch($stream);
|
||||||
LiveStreamService::clearChat($stream->profile_id);
|
LiveStreamService::clearChat($stream->profile_id);
|
||||||
|
|
||||||
if(config('livestreaming.broadcast.delete_token_after_finished')) {
|
if(config('livestreaming.broadcast.delete_token_after_finished')) {
|
||||||
|
|
Loading…
Reference in a new issue