承接 martinbean/mux-php-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

martinbean/mux-php-laravel

最新稳定版本:1.3.0

Composer 安装命令:

composer require martinbean/mux-php-laravel

包简介

Laravel wrapper for the official Mux PHP SDK.

README 文档

README

Installation

composer require martinbean/mux-php-laravel

Configuration

By default, the package expects two environment variables to be defined:

  • MUX_CLIENT_ID
  • MUX_CLIENT_SECRET

This should be a Mux access token ID and secret.

You can generate a Mux access token by:

  1. Logging into your Mux dashboard
  2. Going to “Settings”
  3. Then going to “Access Tokens”

Verifying webhook signatures

To verify webhook signatures from Mux, specify the signing secret for your webhook endpoint as the value of your MUX_WEBHOOK_SECRET environment variable. This means you will need to register your webhook endpoint in the Mux dashboard first.

Usage

API clients

The package will register default configuration based on the configured Mux access token. This means you can then type-hint a Mux client in your Laravel application, and it and its dependencies will be automatically resolved:

namespace App\Http\Controllers;

use MuxPhp\Api\DirectUploadsApi;

class UploadController extends Controller
{
    protected DirectUploadsApi $uploads;

    public function __construct(DirectUploadsApi $uploads)
    {
        $this->uploads = $uploads;
    }
}

Webhook handling

The package will also automatically register a route to listen for webhooks sent by Mux. The URI of this handler is /mux/webhook

The webhook handler is heavily based on Cashier’s webhook handler. When a webhook from Mux is received, an instance of the MartinBean\Laravel\Mux\Events\WebhookReceived event is dispatched containing the webhook’s payload.

You can define a listener that listens for this event:

namespace App\Listeners;

use MartinBean\Laravel\Mux\Events\WebhookReceived;

class MuxEventListener
{
    public function handle(WebhookReceived $event): void
    {
        // Handle Mux webhook event...
    }
}

This is where you would update models, etc in your application based on events from Mux:

  public function handle(WebhookReceived $event): void
  {
-     // Handle Mux webhook event...
+     match ($event->payload['type']) {
+         'video.asset.errored' => $this->handleVideoAssetErrored($event->payload),
+         'video.asset.ready' => $this->handleVideoAssetReady($event->payload),
+         default => null, // unhandled event
+     };
  }
+
+ protected function handleVideoAssetErrored(array $payload): void
+ {
+     // TODO: Retrieve associated video
+     // TODO: Update video status to 'errored'
+     // TODO: Notify user processing video errored
+ }
+
+ protected function handleVideoAssetReady(array $payload): void
+ {
+     // TODO: Retrieve associated video
+     // TODO: Update video status to 'ready'
+     // TODO: Notify user processing video succeeded
+ }

Mux Player

The package contains a Blade view component that makes displaying your Mux videos easy.

The only required property is a playback-id (in the case that the video has a “public” playback policy):

<x-mux::player playback-id="YOUR_PLAYBACK_ID" />

If your video has a “signed” playback policy, then you can provide the playback_token attribute:

<x-mux::player
    playback-id="YOUR_PLAYBACK_ID"
    playback-token="YOUR_PLAYBACK_TOKEN"
/>

In fact, any attributes are passed to the underlying Mux Player instance, so you can specify any other documented attributes such as metadata keys:

<x-mux::player
    playback-id="YOUR_PLAYBACK_ID"
    playback-token="YOUR_PLAYBACK_TOKEN"
    metadata-video-id="{{ $video->id }}"
    metadata-video-title="{{ $video->title }}"
    metadata-viewer-id="{{ Auth::id() }}"
/>

Manually including the Mux Player JavaScript library

By default, the <x-mux::player> component will include the required Mux Player JavaScript library from the jsDeliver CDN. If you do not want this, because maybe you’re installing Mux Player via a package such as npm or Yarn and building it with Vite, then you can pass the no-script attribute. You will then need to make sure you’re including the Mux Player JavaScript yourself:

@vite('resources/js/player.js')

<x-mux::player no-script playback-id="YOUR_PLAYBACK_ID" />

Contribution

Contributions are always welcome. Please open a pull request with your proposed changes, with accompanying tests.

License

Licensed under the MIT License

统计信息

  • 总下载量: 8.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固