Skip to content

Commit

Permalink
streaming platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiritin committed Jul 14, 2023
1 parent ff1bc1b commit ee087e9
Show file tree
Hide file tree
Showing 63 changed files with 3,018 additions and 75 deletions.
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->job(new \App\Jobs\UpdateListenerCountJob())->everyMinute();
$schedule->job(new \App\Jobs\ServerAssignmentJob())->everyFifteenSeconds();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions app/Enum/ServerStatusEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Enum;

enum ServerStatusEnum: string
{
// provisioning, active, deprovisioning, deleted
case PROVISIONING = 'provisioning';
case ACTIVE = 'active';
case DEPROVISIONING = 'deprovisioning';
case DELETED = 'deleted';

}
12 changes: 12 additions & 0 deletions app/Enum/StreamStatusEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Enum;

enum StreamStatusEnum: string
{
case STARTING_SOON = 'starting_soon';
case PROVISIONING = 'provisioning';
case ONLINE = 'online';
case OFFLINE = 'offline';
case TECHNICAL_ISSUE = 'technical_issue';
}
36 changes: 36 additions & 0 deletions app/Events/ServerAssignedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Events;

use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ServerAssignedEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public readonly User $user)
{
}

public function broadcastOn(): array
{
return [
new PrivateChannel('User.'.$this->user->id.'.StreamUrl')
];
}

public function broadcastWith()
{
return ['streamUrls' => $this->user->getUserStreamUrls()];
}

public function broadcastAs(): string
{
return 'stream.url.changed';
}
}
37 changes: 37 additions & 0 deletions app/Events/StreamListenerChangeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class StreamListenerChangeEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public readonly int $listeners)
{
}

public function broadcastOn(): array
{
return [
new Channel('StreamInfo')
];
}

public function broadcastAs(): string
{
return 'stream.listeners.changed';
}

public function broadcastWith()
{
return ['listeners' => $this->listeners];
}
}
36 changes: 36 additions & 0 deletions app/Events/StreamStatusEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Events;

use App\Enum\StreamStatusEnum;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class StreamStatusEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public readonly StreamStatusEnum $status)
{
}

public function broadcastOn(): array
{
return [
new Channel('StreamInfo'),
];
}

public function broadcastAs(): string
{
return 'stream.status.changed';
}

public function broadcastWith(): array
{
return ['status' => $this->status->value];
}
}
16 changes: 16 additions & 0 deletions app/Events/UserWaitingForProvisioningEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Events;

use App\Models\User;
use Illuminate\Foundation\Events\Dispatchable;

class UserWaitingForProvisioningEvent
{
use Dispatchable;

public function __construct(public readonly User $user)
{

}
}
46 changes: 46 additions & 0 deletions app/Filament/Pages/Stream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Filament\Pages;

use App\Enum\StreamStatusEnum;
use App\Events\StreamStatusEvent;
use App\Filament\Widgets\Capacity;
use App\Filament\Widgets\ServerActive;
use App\Filament\Widgets\ServerUserActive;
use Filament\Pages\Actions\Action;
use Filament\Pages\Actions\ActionGroup;
use Filament\Pages\Page;
use Illuminate\Support\Facades\Event;

class Stream extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-cog';

protected static ?int $navigationSort = 99;

protected static ?string $navigationGroup = "Mission Control Center";
protected static ?string $navigationLabel = "Stream Settings";

protected static string $view = 'filament.pages.stream';

protected function getActions(): array
{
return [
Action::make('set_offline')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::OFFLINE)))->label('Set Stream Offline')->requiresConfirmation(),
Action::make('set_online')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::ONLINE)))->label('Set Stream Online')->requiresConfirmation(),
Action::make('set_issue')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::TECHNICAL_ISSUE)))->label('Set Stream Technical Issue')->requiresConfirmation(),
Action::make('set_pending')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::STARTING_SOON)))->label('Set Stream Starting Soon')->requiresConfirmation(),
];
}

protected function getHeaderWidgets(): array
{
return [
ServerUserActive::class,
ServerActive::class,
Capacity::class
];
}


}
88 changes: 88 additions & 0 deletions app/Filament/Resources/ServerResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\ServerResource\Pages;
use App\Filament\Resources\ServerResource\RelationManagers\UserRelationManager;
use App\Models\Server;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables\Columns\TextColumn;

class ServerResource extends Resource
{
protected static ?string $model = Server::class;

protected static ?string $slug = 'servers';

protected static ?string $recordTitleAttribute = 'id';

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('hetzner_id')
->required(),

TextInput::make('cloudflare_id')
->required(),

TextInput::make('hostname')
->required(),

TextInput::make('ip')
->required(),

TextInput::make('status')
->required(),

Placeholder::make('created_at')
->label('Created Date')
->content(fn(?Server $record): string => $record?->created_at?->diffForHumans() ?? '-'),

Placeholder::make('updated_at')
->label('Last Modified Date')
->content(fn(?Server $record): string => $record?->updated_at?->diffForHumans() ?? '-'),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('hetzner_id'),

TextColumn::make('cloudflare_id'),

TextColumn::make('hostname'),

TextColumn::make('ip'),

TextColumn::make('status'),
]);
}

public static function getRelations(): array
{
return [
UserRelationManager::class,
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListServers::route('/'),
'create' => Pages\CreateServer::route('/create'),
'edit' => Pages\EditServer::route('/{record}/edit'),
];
}

public static function getGloballySearchableAttributes(): array
{
return [];
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/ServerResource/Pages/CreateServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\ServerResource\Pages;

use App\Filament\Resources\ServerResource;
use Filament\Resources\Pages\CreateRecord;

class CreateServer extends CreateRecord
{
protected static string $resource = ServerResource::class;
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\ServerResource\Pages;

use App\Filament\Resources\ServerResource;
use Filament\Pages\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;

class EditServer extends EditRecord
{
protected static string $resource = ServerResource::class;

protected function getActions(): array
{
return [
DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/ServerResource/Pages/ListServers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\ServerResource\Pages;

use App\Filament\Resources\ServerResource;
use Filament\Pages\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;

class ListServers extends ListRecords
{
protected static string $resource = ServerResource::class;

protected function getActions(): array
{
return [
CreateAction::make(),
];
}
}
Loading

0 comments on commit ee087e9

Please sign in to comment.