Skip to content

Commit

Permalink
Added New Features
Browse files Browse the repository at this point in the history
- Uppy Companion Server
- RTMP Server
- Live Stream
  • Loading branch information
PHPJunior committed Aug 6, 2021
1 parent 0e35103 commit fb6db98
Show file tree
Hide file tree
Showing 26 changed files with 3,743 additions and 333 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ LARAVEL_WEBSOCKETS_SSL_PASSPHRASE=

FFMPEG_BINARIES="/usr/local/bin/ffmpeg"
FFPROBE_BINARIES="/usr/local/bin/ffprobe"

RTMP_HOST=http://localhost:3000
UPPY_COMPANION_URL=http://localhost:3020/companion
RTMP_SERVER_URL=rtmp://localhost/live
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ LARAVEL_WEBSOCKETS_SSL_PASSPHRASE=
FFMPEG_BINARIES=
FFPROBE_BINARIES=
RTMP_HOST=http://localhost:3000
UPPY_COMPANION_URL=http://localhost:3020/companion
RTMP_SERVER_URL=rtmp://localhost/live
```

```
Expand All @@ -56,11 +60,14 @@ FFPROBE_BINARIES=
'frame_from_seconds' => 3
]
```
Start Laravel Websockets Server
Start Laravel Websockets Server, RTMP Server, Uppy Companion Server

```
php artisan websockets:serve
php artisan queue:work
npm run rtmp-server
npm run companion-server
```

## Create Admin User
Expand All @@ -84,8 +91,8 @@ php artisan create:admin
- [ ] Video Playlists
- [ ] Video Player - Google IMA Pre Roll Plugin
- [x] ~~Realtime Notifications ( Dis/Like, Un/Subscribe Channel, Comments )~~
- [ ] Admin Panel
- [ ] Companion - Uppy Standalone Server
- [x] ~~Admin Panel~~
- [x] ~~Companion - Uppy Standalone Server~~

## Credits
- All Contributors
Expand Down
44 changes: 44 additions & 0 deletions app/Http/Livewire/Frontend/Channel/LiveProducer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Http\Livewire\Frontend\Channel;

use Livewire\Component;

class LiveProducer extends Component
{
public $channel_id;
public $video_id;
public $video;
public $name;
public $description;
public $start;
public $server_url;
public $stream_key;

public function mount()
{
$this->video = auth()->user()->channels()->find($this->channel_id)->videos()->find($this->video_id);
$this->name = $this->video->name;
$this->description = $this->video->description;
$this->start = $this->video->extra_attributes->get('go_live');
$this->stream_key = $this->video->extra_attributes->get('stream_key');
$this->server_url = env('RTMP_SERVER_URL');
}

public function startLive($value)
{
$this->video->extra_attributes->set('go_live', $value);
$this->start = $value;

$this->video->name = $this->name;
$this->video->description = $this->description;
$this->video->save();

$this->emit('startLive');
}

public function render()
{
return view('livewire.frontend.channel.live-producer');
}
}
61 changes: 61 additions & 0 deletions app/Http/Livewire/Frontend/Channel/Modal/CreateStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Http\Livewire\Frontend\Channel\Modal;

use App\Models\Channel\Channel;
use Illuminate\Support\Str;
use Livewire\Component;
use Livewire\WithFileUploads;
use LivewireUI\Modal\ModalComponent;

class CreateStream extends ModalComponent
{
use WithFileUploads;

public $channel_id;
public $name;
public $description;
public $photo;

public static function closeModalOnClickAway(): bool
{
return false;
}

public function render()
{
return view('livewire.frontend.channel.modal.create-stream');
}

public function submit()
{
$stream_key = Str::random(20);
$filesystem = config('site.converted_file_driver');
$streaming_url = "/live/{$stream_key}/index.m3u8";
$media_id = Str::random(10);

$channel = Channel::find($this->channel_id);
$video = $channel->videos()->create([
'name' => $this->name,
'description' => $this->description,
'disk' => $filesystem,
'media_id' => $media_id,
'status' => 'ready',
'streaming_url' => $streaming_url,
'type' => 'live',
'extra_attributes' => [
'stream_key' => $stream_key,
'go_live' => false
]
]);

if ($this->photo)
{
$this->photo->storeAs('converted/' . $video->media_id, $video->id . '.png', $video->disk);
$video->thumbnail_url = "converted/{$video->media_id}/{$video->id}.png";
$video->save();
}

$this->redirectRoute('user.channels.live', ['channel_id' => $video->channel_id, 'video_id' => $video->id]);
}
}
2 changes: 2 additions & 0 deletions app/Http/Livewire/Frontend/Channel/Table/VideosTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public function columns(): array
Column::make(__('Name'), 'name')
->sortable()
->searchable(),
Column::make(__('Type'), 'type'),
Column::make(__('Status'), 'status'),
Column::make(__('Views')),
Column::make(__('Likes (vs. Dislikes)')),
// Column::make(__('Scheduled At'), 'scheduled_at')->sortable(),
Column::make(__('Created At'), 'created_at')->sortable(),
Column::blank(),
];
Expand Down
3 changes: 2 additions & 1 deletion app/Listeners/TusEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function handleUploadCompleted($event)
'duration' => $duration,
'status' => 'notready',
'disk' => $filesystem,
'tus_id' => $tus
'tus_id' => $tus,
'type' => 'upload',
]);
}catch (\Exception $e) {
Log::error($e->getMessage());
Expand Down
23 changes: 21 additions & 2 deletions app/Models/Channel/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,42 @@
namespace App\Models\Channel;

use App\Models\Channel\Traits\VideoRelationship;
use App\Models\HasSchemalessAttributes;
use Cklmercer\ModelSettings\HasSettings;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Jcc\LaravelVote\Traits\Votable;
use Overtrue\LaravelLike\Traits\Likeable;
use CyrildeWit\EloquentViewable\InteractsWithViews;
use CyrildeWit\EloquentViewable\Contracts\Viewable;
use Cog\Contracts\Ban\Bannable as BannableContract;
use Cog\Laravel\Ban\Traits\Bannable;
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
use Illuminate\Database\Eloquent\Builder;

class Video extends Model implements Viewable, BannableContract
{
use HasFactory, Likeable, Votable, VideoRelationship, InteractsWithViews, HasSettings, Bannable;
use HasFactory, Likeable, Votable, VideoRelationship,
InteractsWithViews, HasSettings, Bannable, SchemalessAttributesTrait;

protected $fillable = [
'tus_id', 'media_id', 'name', 'description', 'disk', 'path',
'thumbnail_url', 'file_size', 'file_type', 'duration', 'progress', 'status',
'streaming_url'
'streaming_url', 'type', 'extra_attributes'
];

protected $schemalessAttributes = [
'extra_attributes',
];

public function scopeWithExtraAttributes(): Builder
{
return $this->extra_attributes->modelScope();
}

public function getVideoSourceAttribute()
{
return $this->type == 'upload' ? Storage::disk($this->disk)->url($this->streaming_url) : env('RTMP_HOST') . $this->streaming_url;
}
}
2 changes: 1 addition & 1 deletion app/Observers/VideoObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VideoObserver
*/
public function created(Video $video)
{
dispatch(new StartConvert($video->id));
if ($video->type == 'upload') dispatch(new StartConvert($video->id));
}

/**
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"predis/predis": "^1.1",
"pusher/pusher-php-server": "~3.0",
"rappasoft/laravel-livewire-tables": "^1.10",
"spatie/laravel-schemaless-attributes": "^1.8",
"symfony/process": "^5.3",
"watson/active": "^6.0"
},
Expand Down
68 changes: 67 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddExtraAttributesColumnToVideosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('videos', function (Blueprint $table) {
$table->string('scheduled_at')->nullable();
$table->string('type')->default('upload');
$table->schemalessAttributes('extra_attributes');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('videos', function (Blueprint $table) {
$table->dropColumn('scheduled_at');
$table->dropColumn('type');
$table->dropColumn('extra_attributes');
});
}
}
Loading

0 comments on commit fb6db98

Please sign in to comment.