martinbean/mux-php-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

martinbean/mux-php-laravel

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

martinbean/mux-php-laravel 适用场景与选型建议

martinbean/mux-php-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.45k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2024 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「video」 「laravel」 「mux」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 martinbean/mux-php-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 martinbean/mux-php-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 martinbean/mux-php-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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