Developer-friendly & type-safe PHP SDK specifically designed to leverage the FastPix platform API.
The FastPix PHP SDK simplifies integration with the FastPix platform. This SDK is designed for secure and efficient communication with the FastPix API, enabling easy management of media uploads, live streaming, and simulcasting.
-
- Upload Media: Upload media files seamlessly from URLs or devices
- Manage Media: Perform operations such as listing, fetching, updating, and deleting media assets
- Playback IDs: Generate and manage playback IDs for media access
-
- Create & Manage Live Streams: Create, list, update, and delete live streams effortlessly
- Control Stream Access: Generate playback IDs for live streams to control and manage access
- Simulcast to Multiple Platforms: Stream content to multiple platforms simultaneously
For detailed usage, refer to the FastPix API Reference.
- PHP 7.4 or later
- Composer package manager
- FastPix API credentials (Access Token and Secret Key)
The SDK relies on Composer to manage its dependencies.
To install the SDK first add the below to your composer.json
file:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/FastPix/fastpix-php.git"
}
],
"require": {
"fastpix/sdk": "*"
}
}
Then run the following command:
composer update
You can set the security parameters through the security
builder method when initializing the SDK client instance. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use FastPix\Sdk;
use FastPix\Sdk\Models\Components;
$sdk = Sdk\FastPix::builder()
->setSecurity(
new Components\Security(
username: 'your-access-token-id',
password: 'your-security-key',
)
)
->build();
declare(strict_types=1);
require 'vendor/autoload.php';
use FastPix\Sdk;
use FastPix\Sdk\Models\Components;
$sdk = Sdk\FastPix::builder()
->setSecurity(
new Components\Security(
username: 'your-access-token-id',
password: 'your-security-key',
)
)
->build();
$request = new Components\CreateLiveStreamRequest(
playbackSettings: new Components\PlaybackSettings(),
inputMediaSettings: new Components\InputMediaSettings(
metadata: new Components\CreateLiveStreamRequestMetadata(),
),
);
$response = $sdk->startLiveStream->createNewStream(
request: $request
);
if ($response->liveStreamResponseDTO !== null) {
// handle response
}
Available methods
- createMedia - Create media from URL
- directUploadVideoMedia - Upload media from device
- getAllStreams - Get all live streams
- getLiveStreamById - Get stream by ID
- deleteLiveStream - Delete a stream
- updateLiveStream - Update a stream
- listMedia - Get list of all media
- getMedia - Get a media by ID
- updatedMedia - Update a media by ID
- deleteMedia - Delete a media by ID
- retrieveMediaInputInfo - Get info of media inputs
- createPlaybackIdOfStream - Create a playbackId
- deletePlaybackIdOfStream - Delete a playbackId
- getLiveStreamPlaybackId - Get stream's playbackId
- createMediaPlaybackId - Create a playback ID
- deleteMediaPlaybackId - Delete a playback ID
- createSimulcastOfStream - Create a simulcast
- deleteSimulcastOfStream - Delete a simulcast
- getSpecificSimulcastOfStream - Get a specific simulcast of a stream
- updateSpecificSimulcastOfStream - Update a specific simulcast of a stream
- createNewStream - Create a new stream
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\APIException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the createNewStream
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errors\UnauthorizedException | 401 | application/json |
Errors\InvalidPermissionException | 403 | application/json |
Errors\ValidationErrorResponse | 422 | application/json |
Errors\APIException | 4XX, 5XX | */* |
declare(strict_types=1);
require 'vendor/autoload.php';
use FastPix\Sdk;
use FastPix\Sdk\Models\Components;
use FastPix\Sdk\Models\Errors;
$sdk = Sdk\FastPix::builder()
->setSecurity(
new Components\Security(
username: 'your-access-token-id',
password: 'your-security-key',
)
)
->build();
try {
$request = new Components\CreateLiveStreamRequest(
playbackSettings: new Components\PlaybackSettings(),
inputMediaSettings: new Components\InputMediaSettings(
metadata: new Components\CreateLiveStreamRequestMetadata(),
),
);
$response = $sdk->startLiveStream->createNewStream(
request: $request
);
if ($response->liveStreamResponseDTO !== null) {
// handle response
}
} catch (Errors\UnauthorizedExceptionThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\InvalidPermissionExceptionThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\ValidationErrorResponseThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\APIException $e) {
// handle default exception
throw $e;
}
The default server can be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use FastPix\Sdk;
use FastPix\Sdk\Models\Components;
$sdk = Sdk\FastPix::builder()
->setServerURL('https://v1.fastpix.io/live')
->setSecurity(
new Components\Security(
username: 'your-access-token-id',
password: 'your-security-key',
)
)
->build();
$request = new Components\CreateLiveStreamRequest(
playbackSettings: new Components\PlaybackSettings(),
inputMediaSettings: new Components\InputMediaSettings(
metadata: new Components\CreateLiveStreamRequestMetadata(),
),
);
$response = $sdk->startLiveStream->createNewStream(
request: $request
);
if ($response->liveStreamResponseDTO !== null) {
// handle response
}
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
For a complete understanding of each API's functionality, including request and response details, parameter descriptions, and additional examples, please refer to the FastPix API Reference.
The API reference provides comprehensive documentation for all available endpoints and features, ensuring developers can integrate and utilize FastPix APIs efficiently.