| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template Name: WPStream OvenLiveKit Broadcaster |
| 4 |
*/ |
| 5 |
|
| 6 |
// Security check |
| 7 |
if (!defined('ABSPATH')) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
// Only allow logged-in users with appropriate permissions |
| 12 |
if (!is_user_logged_in() || !current_user_can('publish_posts')) { |
| 13 |
wp_die(__('You do not have sufficient permissions to access this page.', 'wpstream')); |
| 14 |
} |
| 15 |
|
| 16 |
// Get channel ID from URL parameter |
| 17 |
$channel_id = get_query_var('channel_id'); |
| 18 |
if (empty($channel_id)) { |
| 19 |
wp_die(__('No channel ID specified.', 'wpstream')); |
| 20 |
} |
| 21 |
|
| 22 |
// Get stream information from post meta |
| 23 |
$obs_uri = get_post_meta($channel_id, 'obs_uri', true); |
| 24 |
$obs_stream = get_post_meta($channel_id, 'obs_stream', true); |
| 25 |
$whip_url = get_post_meta($channel_id, 'whipUrl', true); |
| 26 |
|
| 27 |
$onboarding = isset( $_GET['onboarding'] ) ? sanitize_text_field( wp_unslash( $_GET['onboarding'] ) ) : ''; |
| 28 |
$is_onboarding = ( $onboarding === '1' ); |
| 29 |
|
| 30 |
if (empty($whip_url)) { |
| 31 |
wp_die(__('WHIP URL not available for this channel.', 'wpstream')); |
| 32 |
} |
| 33 |
|
| 34 |
wp_enqueue_style( |
| 35 |
'wpstream-broadcaster-css', |
| 36 |
WPSTREAM_PLUGIN_DIR_URL . 'public/css/broadcaster.css', |
| 37 |
array(), |
| 38 |
filemtime(WPSTREAM_PLUGIN_PATH . 'public/css/broadcaster.css') |
| 39 |
); |
| 40 |
|
| 41 |
wp_enqueue_script( |
| 42 |
'wpstream-broadcaster-new', |
| 43 |
WPSTREAM_PLUGIN_DIR_URL . 'public/js/broadcaster.js', |
| 44 |
array(), |
| 45 |
filemtime(WPSTREAM_PLUGIN_PATH . 'public/js/broadcaster.js'), |
| 46 |
true |
| 47 |
); |
| 48 |
|
| 49 |
wp_localize_script( |
| 50 |
'wpstream-broadcaster-new', |
| 51 |
'wpstream_broadcaster_vars', |
| 52 |
array( |
| 53 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 54 |
'nonce' => wp_create_nonce('wpstream_broadcaster_nonce'), |
| 55 |
'plugin_url' => plugin_dir_url(__FILE__), |
| 56 |
'obs_uri' => $obs_uri, |
| 57 |
'obs_stream' => $obs_stream, |
| 58 |
'channel_id' => $channel_id, |
| 59 |
'is_channel_live' => get_post_meta($channel_id, 'status', true), |
| 60 |
'whip_url' => get_post_meta($channel_id, 'whipUrl', true), |
| 61 |
'no_video_audio_access' => esc_html__('We couldn’t access your camera or microphone. Please allow permissions and reload the page.', 'wpstream'), |
| 62 |
'no_audio_access' => esc_html__('We couldn’t access your microphone. Please allow permissions and reload the page.', 'wpstream'), |
| 63 |
'no_video_access' => esc_html__('We couldn’t access your camera. Please allow permissions and reload the page.', 'wpstream'), |
| 64 |
'channel_off' => esc_html__('Invalid event. Your live event may have expired or its credentials are incorrect.', 'wpstream'), |
| 65 |
'not_enough_traffic' => sprintf( |
| 66 |
esc_html__('Not enough streaming traffic to broadcast. Please %supgrade your subscription%s for extra resources.', 'wpstream'), |
| 67 |
'<a href="https://wpstream.net/pricing/" target="_blank">', |
| 68 |
'</a>' |
| 69 |
), |
| 70 |
'is_onboarding' => $is_onboarding |
| 71 |
) |
| 72 |
); |
| 73 |
|
| 74 |
if ( $is_onboarding ) { |
| 75 |
wp_enqueue_script('wpstream-on-boarding-page-js', plugin_dir_url( __DIR__ ) .'admin/js/wpstream-onboarding-page.js',array(), WPSTREAM_PLUGIN_VERSION, true); |
| 76 |
wp_localize_script( 'wpstream-on-boarding-page-js', 'wpstream_onboarding_page_vars', |
| 77 |
array( |
| 78 |
'admin_url' => get_admin_url(), |
| 79 |
'request_url' => WPSTREAM_CLICK, |
| 80 |
'wps_user' => get_option('wpstream_api_username_from_token'), |
| 81 |
'current_page' => 'broadcaster', |
| 82 |
'plugin_version' => WPSTREAM_PLUGIN_VERSION, |
| 83 |
) |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
?> |
| 88 |
<!DOCTYPE html> |
| 89 |
<html <?php language_attributes(); ?>> |
| 90 |
<head> |
| 91 |
<meta charset="<?php bloginfo('charset'); ?>"> |
| 92 |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| 93 |
<title><?php esc_html_e('WpStream Broadcaster', 'wpstream'); ?></title> |
| 94 |
|
| 95 |
<?php wp_head(); ?> |
| 96 |
|
| 97 |
<!-- Load required libraries in correct order --> |
| 98 |
<script src="https://cdn.jsdelivr.net/npm/underscore@1.12.0/underscore-min.js"></script> |
| 99 |
<script src="https://cdn.jsdelivr.net/npm/ovenlivekit@latest/dist/OvenLiveKit.min.js"></script> |
| 100 |
</head> |
| 101 |
<body class="wpstream-broadcaster-page"> |
| 102 |
<header class="broadcaster-header"> |
| 103 |
<div class="header-container"> |
| 104 |
<div class="header-logo"> |
| 105 |
<a href="<?php echo esc_url(home_url('/')); ?>"> |
| 106 |
<img src="<?php echo esc_url(WPSTREAM_PLUGIN_DIR_URL . 'img/wpstream-logo.svg'); ?>" alt="WpStream Logo"> |
| 107 |
</a> |
| 108 |
</div> |
| 109 |
<nav class="header-nav"> |
| 110 |
<span class="nav-item">Browser Broadcaster</span> |
| 111 |
</nav> |
| 112 |
</div> |
| 113 |
</header> |
| 114 |
|
| 115 |
<div id="messageContainer"></div> |
| 116 |
|
| 117 |
<div class="broadcaster-container"> |
| 118 |
<div class="wrapper"> |
| 119 |
<div class="video-container"> |
| 120 |
<button id="videoExpandToggle" class="video-expand-toggle" type="button" aria-label="<?php esc_attr_e('Toggle Full View', 'wpstream'); ?>" title="<?php esc_attr_e('Toggle Full View', 'wpstream'); ?>"> |
| 121 |
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" y1="3" x2="14" y2="10"></line><line x1="3" y1="21" x2="10" y2="14"></line></svg> |
| 122 |
</button> |
| 123 |
<div id="videoLiveIndicator" class="video-live-indicator"> |
| 124 |
<span id="videoLiveIndicatorLive" class="badge badge-pill badge-danger" style="display:none;"><?php esc_html_e('LIVE', 'wpstream'); ?></span> |
| 125 |
<span id="videoLiveIndicatorError" class="badge badge-pill badge-warning" style="display:none;"><?php esc_html_e('Connecting...', 'wpstream'); ?></span> |
| 126 |
</div> |
| 127 |
<div class="video-wrapper"> |
| 128 |
<div id="wpstream-pre-load-spinner" class="wpstream-pre-load-spinner"></div> |
| 129 |
<video id="localVideo" autoplay muted playsinline></video> |
| 130 |
</div> |
| 131 |
</div> |
| 132 |
|
| 133 |
<div class="settings-panel" id="settingsPanel"> |
| 134 |
<div> |
| 135 |
<?php |
| 136 |
$ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" ); |
| 137 |
print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">'; |
| 138 |
?> |
| 139 |
<div class="controls-container"> |
| 140 |
<button id="startBroadcast" class="button start-broadcast" disabled><?php esc_html_e('Start Broadcast', 'wpstream'); ?></button> |
| 141 |
<button id="stopBroadcast" class="button stop-broadcast hidden"><?php esc_html_e('Stop Broadcast', 'wpstream'); ?></button> |
| 142 |
</div> |
| 143 |
<div class="status-container"> |
| 144 |
<div> |
| 145 |
<span class="status-indicator" id="statusIndicator"></span> |
| 146 |
<span id="statusText"><?php esc_html_e('Not connected', 'wpstream'); ?></span> |
| 147 |
</div> |
| 148 |
</div> |
| 149 |
</div> |
| 150 |
|
| 151 |
<div class="settings-row media-row"> |
| 152 |
<div class="settings-group"> |
| 153 |
<label for="videoDevice"><?php esc_html_e('Video Source', 'wpstream'); ?></label> |
| 154 |
<div class="controls-group"> |
| 155 |
<select id="videoDevice"> |
| 156 |
<option selected></option> |
| 157 |
</select> |
| 158 |
<button id="videoToggle" class="control-button"> |
| 159 |
<img alt="" class="noll" id="video-off" src="<?php echo esc_url(WPSTREAM_PLUGIN_DIR_URL . 'img/videocam-32px.svg'); ?>"> |
| 160 |
<img alt="" class="noll" id="video-on" src="<?php echo esc_url(WPSTREAM_PLUGIN_DIR_URL . 'img/videocam-off-32px.svg'); ?>" style="display:none;"> |
| 161 |
</button> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
|
| 165 |
<div class="settings-group"> |
| 166 |
<label for="audioDevice"><?php esc_html_e('Audio Source', 'wpstream'); ?></label> |
| 167 |
<div class="controls-group"> |
| 168 |
<select id="audioDevice"> |
| 169 |
<option selected></option> |
| 170 |
</select> |
| 171 |
<button id="audioToggle" class="control-button"> |
| 172 |
<img alt="" class="noll" id="audio-off" src="<?php echo esc_url( WPSTREAM_PLUGIN_DIR_URL . 'img/mic-32px.svg' ); ?>"> |
| 173 |
<img alt="" class="noll" id="audio-on" src="<?php echo esc_url( WPSTREAM_PLUGIN_DIR_URL . 'img/mic-off-32px.svg' ); ?>" style="display:none;"> |
| 174 |
</button> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
</div> |
| 178 |
|
| 179 |
<div class="settings-row"> |
| 180 |
<div class="settings-group"> |
| 181 |
<label for="videoQuality"><?php esc_html_e('Video Resolution', 'wpstream'); ?></label> |
| 182 |
<select id="videoQuality"> |
| 183 |
<option selected value="default">Default</option> |
| 184 |
<option value="fhd"><?php esc_html_e('1920x1080', 'wpstream'); ?></option> |
| 185 |
<option value="hd"><?php esc_html_e('1280x720', 'wpstream'); ?></option> |
| 186 |
<option value="square"><?php esc_html_e('800x600', 'wpstream'); ?></option> |
| 187 |
<option value="vga"><?php esc_html_e('640x360', 'wpstream'); ?></option> |
| 188 |
</select> |
| 189 |
</div> |
| 190 |
</div> |
| 191 |
</div> |
| 192 |
</div> |
| 193 |
</div> |
| 194 |
|
| 195 |
<?php wp_footer(); ?> |
| 196 |
</body> |
| 197 |
</html> |