PHP code example of weblivehub / sdk
1. Go to this page and download the library: Download weblivehub/sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
weblivehub / sdk example snippets
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 (
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
]);
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
]);
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
]
]);
}
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'
]
]);
WLSDK::setup([
'hb_endpoint' => 'https://console.weblivehub.com/WL_HOST/abc123.../backend.php',
'user_id' => 'client_user_id',
'password' => 'client_password'
]);
echo WLSDK::script();
echo WLSDK::iframe([
'hostLabel' => 'live',
'streamer' => 'streamer_user_id',
'id' => 'my-custom-id',
'attrs' => [
'style' => 'width: 800px; height: 600px;',
'data-room' => 'vip-room'
]
]);
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: ' echo $client_user_id;