You've already forked Atomcms-edit
Add radio embed widget, SSE real-time, song history, moderation panel, and Auto DJ
- Embed widget: standalone iframe player with dark/light/transparent themes, copy-paste embed code admin page - Real-time SSE: streaming now-playing/listeners/dj events, replaces polling in radio-player and embed - Song history: auto-records song changes to radio_song_plays table, Filament resource to view - DJ moderation: unified panel for shouts approval, song request queue, DJ applications - Auto DJ: playlist management with round-robin playback when no DJ is live - Refactored radio-player Alpine component to use EventSource API with auto-reconnect
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Miscellaneous\WebsiteSetting;
|
||||
use App\Services\Community\RadioScheduleService;
|
||||
use App\Services\Community\RadioStreamService;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioSongPlay where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioSongPlay create($attributes = [])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioSongPlay orderBy($column, $direction = 'asc')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioSongPlay latest($column = 'played_at')
|
||||
*
|
||||
* @property string $title
|
||||
* @property string|null $artist
|
||||
* @property string|null $album
|
||||
* @property string|null $artwork_url
|
||||
* @property int|null $duration
|
||||
* @property \Carbon\Carbon $played_at
|
||||
* @property int|null $dj_id
|
||||
* @property array|null $metadata
|
||||
*/
|
||||
class RadioSongPlay extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'radio_song_plays';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'played_at' => 'datetime',
|
||||
'metadata' => 'array',
|
||||
'duration' => 'integer',
|
||||
];
|
||||
|
||||
public static function recordNowPlaying(?string $title, ?string $artist = null, ?array $extra = null): ?self
|
||||
{
|
||||
if (! $title) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$last = self::latest('played_at')->first();
|
||||
|
||||
if ($last && $last->title === $title && $last->artist === $artist) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$djId = WebsiteSetting::where('key', 'radio_current_dj_id')->first()?->value;
|
||||
|
||||
return self::create([
|
||||
'title' => $title,
|
||||
'artist' => $artist,
|
||||
'album' => $extra['album'] ?? null,
|
||||
'artwork_url' => $extra['artwork_url'] ?? null,
|
||||
'duration' => $extra['duration'] ?? null,
|
||||
'played_at' => $extra['played_at'] ?? now(),
|
||||
'dj_id' => $djId ? (int) $djId : null,
|
||||
'metadata' => $extra['metadata'] ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user