Skip to content

Instantly share code, notes, and snippets.

@sasin91
Created October 25, 2022 08:32
Show Gist options
  • Save sasin91/09b22f5b1a72ba3f0cb653320b1e3fcd to your computer and use it in GitHub Desktop.
Save sasin91/09b22f5b1a72ba3f0cb653320b1e3fcd to your computer and use it in GitHub Desktop.
Action class that's called for creating Broadcast.mux_stats_jwt_token
<?php
namespace App\Actions;
use App\Enums\JWTTokenType;
use App\Models\Broadcast;
use App\Services\MuxApiClient;
use App\Values\MuxJWTToken;
use MuxPhp\ApiException;
class CreateMuxJWTToken
{
public function __construct(
public readonly MuxApiClient $mux
) {
// code...
}
/**
* @throws ApiException
*/
public function forBroadcast(Broadcast $broadcast): MuxJWTToken
{
return $this->mux->systemApi->createJWTToken(
type: JWTTokenType::VIDEO_ID,
id: $broadcast->getKey(),
expiresAt: $broadcast->ends_at->addHour()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment