joggapp / laravel-mux
Laravel package for Mux API
Requires
- php: ^8.1
- illuminate/http: 10.*
- illuminate/support: 10.*
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: 8.*
- phpunit/phpunit: ^10.3
- spatie/laravel-ray: ^1.29
README
This package makes using Mux' API with a laravel app easy and simple.
Installation
- You can install this package via composer using this command:
composer require joggapp/laravel-mux
-
The package will automatically register itself.
-
You can publish the config file, database tables, webhook route using the following command:
php artisan vendor:publish --provider="JoggApp\Mux\MuxServiceProvider"
This will create the package's config file called laravel-mux.php in the config directory. These are the contents of the published config file:
return [ 'access_token' => env('MUX_ACCESS_TOKEN'), 'secret_key' => env('MUX_SECRET_KEY'), 'api_url' => env('MUX_API_URL', 'https://api.mux.com/video/v1'), 'webhook_processing_queue' => env('MUX_WEBHOOK_PROCESSING_QUEUE', 'encoding'), 'webhook_secret' => env('MUX_WEBHOOK_SECRET') ];
How to use
-
Setup config
webhook_secretcan be found in Mux dashboard under Settings > Webhooks:
-
Run migrations
-
You then need to pass the route to
muxWebhookin your routes file:
Route::muxWebhook('route-you-prefer')->middleware('validate.mux.signature');
-
You need to implement the
JoggApp\Mux\Contracts\Mediainterface on the model you want to use as the one to be operated on. Eg: App\Models\Video. You will also need to implement the methods that interface asks for in your model. -
The command
JoggApp\Mux\Commands\KeepCheckingForLaravelMuxErrorsis scheduled to run every minute via this packages service-provider. Make sure you have run the migrations. You can set the threshold count in the config file, if which is crossed in the last hour the pkg will emit an eventMuxErrorsThresholdCrossedthat you can hook into and do anything you like, for eg notify on slack, swap services etc. The count has been set to a sensible default of 3 per hour. -
The available methods are:
Mux::encode(Media $media, array $options = []): Response
Mux::addCaptionsToVideo(Media $media, array $options = []): Response
Mux::getAssetDetails(string $assetId): Response
-
There is a
ValidateMuxSignaturemiddleware available which when applied to the mux webhook route, will take care of the webhook secret verification. -
This package emits the following events:
-
MuxAddingCaptionsToVideoFailed -
MuxAddingCaptionsToVideoSuccessful -
MuxMediaEncodingFailed -
MuxMediaEncodingSuccessful -
MuxVideoAssetFailedWebhookReceived -
MuxVideoAssetReadyWebhookReceived -
MuxVideoAssetStaticRenditionsReadyWebhookReceived -
MuxErrorsThresholdCrossed
Testing
You can run the tests with:
vendor/bin/phpunit
Changelog
Please see the CHANGELOG for more information about what has changed recently.
Security
If you discover any security related issues, please email them to harish@jogg.co instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see the License File for more information.