Official PHP SDK for WebLiveHub - A powerful WebRTC live streaming and video-on-demand platform.
- π Simple Integration: One-line setup with Composer
- π Secure Authentication: Built-in credential management and token handling
- β‘ Multiple Embed Modes: Immediate and lazy-loading iframe support
- π¨ Customizable: Flexible attributes
- π CDN Support: Configurable CDN endpoints for optimal performance
- π± Responsive: Works seamlessly across devices
- π Auto-Retry: Built-in error handling and fallback mechanisms
- π’ Hosted Backend Support: Automatic slug detection for managed deployments
- PHP 7.4 or higher
- cURL extension (recommended) or
allow_url_fopenenabled - Valid WebLiveHub account with Hosted Backend credentials
Install via Composer:
composer require weblivehub/sdkOr add to your composer.json:
{
"require": {
"weblivehub/sdk": "^1.0.4"
}
}Then run:
composer install- Log in to your WebLiveHub Console
- Navigate to Hosted Backends β Create Backend
- Copy your Hosted Backend Endpoint (e.g.,
https://console.weblivehub.com/WL_HOST/{slug}/wl_api/backend.php)
<?php
require_once 'vendor/autoload.php';
use WebLiveHub\SDK\WLSDK;
// Configure SDK
WLSDK::setup([
'hb_endpoint' => '{your-generated-endpoint}',
'user_id' => 'client_user_id', // Your WebLiveHub user ID
'password' => 'client_password', // Your WebLiveHub password
]);
// Output the SDK script tag (required once per page)
echo WLSDK::script();
// Embed a live stream
echo WLSDK::iframe([
'hostLabel' => 'live', // Role: 'live' (streamer) or 'live-client' (viewer)
'streamer' => 'streamer_user_id' // The streamer's user ID
]);
?>WLSDK::setup([
'hb_endpoint' => 'https://your-backend-endpoint/backend.php', // Required
'user_id' => 'client_user_id', // Required
'password' => 'client_password', // Required
'debug' => false, // Optional: Enable debug mode
]);Fetches a stream token immediately on the server-side and embeds the iframe:
<?php
use WebLiveHub\SDK\WLSDK;
// Setup (do this once)
WLSDK::setup([
'hb_endpoint' => getenv('WEBLIVEHUB_ENDPOINT'),
'user_id' => 'client_user_id',
'password' => 'client_password',
]);
// Output script tag (once per page)
echo WLSDK::script();
// Embed streamer view (broadcaster interface)
echo WLSDK::iframe([
'hostLabel' => 'live',
'streamer' => 'streamer_user_id', // Streamer's user ID
'attrs' => [
'id' => 'my-stream',
'style' => 'width: 100%; height: 600px; border: none;',
'data-room' => 'room123'
]
]);
// Embed viewer view (audience interface)
echo WLSDK::iframe([
'hostLabel' => 'live-client',
'streamer' => 'streamer_user_id', // Watch this streamer
]);
?>Client-side token fetching for dynamic multi-stream pages:
<?php
use WebLiveHub\SDK\WLSDK;
WLSDK::setup([
'hb_endpoint' => getenv('WEBLIVEHUB_ENDPOINT'),
'user_id' => 'client_user_id',
'password' => 'client_password',
]);
echo WLSDK::script();
// Lazy-load multiple streams (tokens fetched on-demand)
foreach ($streamers as $streamer_id) {
echo WLSDK::lazyIframe([
'hostLabel' => 'live-client',
'streamer' => $streamer_id,
'attrs' => [
'class' => 'lazy-stream',
'data-streamer' => $streamer_id
]
]);
}
?>Benefits of Lazy-Loading:
- Reduces initial server load
- Faster page rendering
- Tokens fetched only when needed
- Ideal for multi-stream galleries
Add custom HTML attributes and JavaScript event handlers:
<?php
use WebLiveHub\SDK\WLSDK;
WLSDK::setup([/* ... */]);
echo WLSDK::script();
echo WLSDK::iframe([
'hostLabel' => 'live',
'streamer' => 'streamer_user_id',
'attrs' => [
'id' => 'main-stream',
'class' => 'featured-stream border-2',
'style' => 'width: 100%; height: 500px;',
'data-analytics-id' => 'stream-001',
'data-category' => 'gaming'
]
]);
?>
<div id="viewer-count">0</div>Initialize SDK configuration.
Parameters:
$config(array): Configuration arrayhb_endpoint(string, required): Hosted Backend endpoint URLuser_id(string, required): User ID for authenticationpassword(string, required): User passwordauthToken(string, optional): Pre-fetched auth token
Returns: bool - Always returns true
Example:
WLSDK::setup([
'hb_endpoint' => 'https://console.weblivehub.com/WL_HOST/abc123.../backend.php',
'user_id' => 'client_user_id',
'password' => 'client_password'
]);Generate the <script> tag to load the embed.js library.
Returns: string - HTML script tag
Example:
echo WLSDK::script();Note: Call this once per page, typically in the <head> or before any iframe embeds.
Generate an immediate iframe embed (server-side token fetch).
Parameters:
$opts(array): Embed optionshostLabel(string, required): Role identifier (e.g.,'live','live-client','connect')streamer(string, required): Streamer's user IDid(string, optional): DOM element ID (auto-generated if not provided)attrs(array, optional): Custom HTML attributes
Returns: string - HTML output (<wl-stream> element + optional event script)
Example:
echo WLSDK::iframe([
'hostLabel' => 'live',
'streamer' => 'streamer_user_id',
'id' => 'my-custom-id',
'attrs' => [
'style' => 'width: 800px; height: 600px;',
'data-room' => 'vip-room'
]
]);Generate a lazy-loading iframe embed (client-side token fetch).
Parameters:
$opts(array): Embed optionshostLabel(string, required): Role identifierstreamer(string, required): Streamer's user IDauthToken(string, optional): Override auth tokenhb_endpoint(string, optional): Override hosted backend endpointattrs(array, optional): Custom HTML attributes
Returns: string - HTML output (<wl-stream-lazy> element)
Example:
echo WLSDK::lazyIframe([
'hostLabel' => 'live-client',
'streamer' => 'streamer_user_id',
'attrs' => [
'class' => 'lazy-load',
'loading' => 'lazy'
]
]);<style>
wl-stream, wl-stream-lazy {
display: block;
width: 100%;
max-width: 1200px;
margin: 0 auto;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.wl-stream-error {
padding: 20px;
background: #fee;
border: 1px solid #fcc;
border-radius: 4px;
color: #c33;
text-align: center;
}
</style>// β WRONG - Never do this!
<script>
const config = {
user_id: '<?php echo $client_user_id; ?>',
password: '<?php echo $client_password; ?>' // SECURITY RISK!
};
</script>
// β
CORRECT - Keep credentials server-side only
<?php
WLSDK::setup([
'hb_endpoint' => getenv('WEBLIVEHUB_ENDPOINT'),
'user_id' => 'client_user_id',
'password' => 'client_password',
]);
echo WLSDK::iframe(['hostLabel' => 'live', 'streamer' => 'streamer_user_id']);
?>| Label | Role | Description |
|---|---|---|
live |
Streamer | Broadcaster interface with streaming controls |
live-client |
Viewer | Audience view without streaming capabilities |
connect |
Test/Demo | General-purpose testing interface |
Note: Backend configuration determines available roles and permissions for each label.
- Email: support@weblivehub.com
- Issues: GitHub Issues
- Hosted Backend slug detection
- Versioned asset path support with fallback
- Enhanced error handling
- Improved CDN configuration
Updated hostLabel links
Added event listeners for WLSDK::iframe and WLSDK::lazyIframe
Made with β€οΈ by WebLiveHub