diff --git a/plugin/Live/standAloneFiles/WebRTCServer/extra_functions.php b/plugin/Live/standAloneFiles/WebRTCServer/extra_functions.php index f38930ba5..9bab22b49 100644 --- a/plugin/Live/standAloneFiles/WebRTCServer/extra_functions.php +++ b/plugin/Live/standAloneFiles/WebRTCServer/extra_functions.php @@ -1,118 +1,116 @@ (filemtime($cacheFile) + $lifetime))) { error_log("Verification Creating the Cache {$url}"); $result = url_get_contents($verifyURL, '', 5); file_put_contents($cacheFile, $result); } else { error_log("Verification GetFrom Cache {$url}"); $result = file_get_contents($cacheFile); } error_log("Verification Response ($verifyURL): {$result}"); return json_decode($result); } function isVerified($url) { $resultV = verify($url); if (!empty($resultV) && !$resultV->verified) { error_log("Error on Login not verified"); return false; } return true; } function make_path($path) { if (substr($path, -1) !== '/') { $path = pathinfo($path, PATHINFO_DIRNAME); } if (!is_dir($path)) { @mkdir($path, 0755, true); } } function getSelfUserAgent() { $agent = "AVideo WebRTC"; return $agent; } function url_get_contents($url, $ctx = "", $timeout = 0, $debug = false) { global $global, $mysqlHost, $mysqlUser, $mysqlPass, $mysqlDatabase, $mysqlPort; if ($debug) { error_log("url_get_contents: Start $url, $ctx, $timeout " . getSelfURI() . " " . getRealIpAddr() . " " . json_encode(debug_backtrace())); } $agent = getSelfUserAgent(); if (empty($ctx)) { $opts = array( 'http' => array('header' => "User-Agent: {$agent}\r\n"), "ssl" => array( "verify_peer" => false, "verify_peer_name" => false, "allow_self_signed" => true, ), ); if (!empty($timeout)) { ini_set('default_socket_timeout', $timeout); $opts['http'] = array('timeout' => $timeout); } $context = stream_context_create($opts); } else { $context = $ctx; } if (ini_get('allow_url_fopen')) { if ($debug) { error_log("url_get_contents: allow_url_fopen {$url}"); } try { $tmp = @file_get_contents($url, false, $context); if ($tmp != false) { $response = ($tmp); if ($debug) { -//error_log("url_get_contents: SUCCESS file_get_contents($url) {$response}"); + //error_log("url_get_contents: SUCCESS file_get_contents($url) {$response}"); error_log("url_get_contents: SUCCESS file_get_contents($url)"); } return $response; } if ($debug) { error_log("url_get_contents: ERROR file_get_contents($url) "); } } catch (ErrorException $e) { if ($debug) { error_log("url_get_contents: allow_url_fopen ERROR " . $e->getMessage() . " {$url}"); } return "url_get_contents: " . $e->getMessage(); } } elseif (function_exists('curl_init')) { if ($debug) { error_log("url_get_contents: CURL {$url} "); } $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); if (!empty($timeout)) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout + 10); } $output = curl_exec($ch); curl_close($ch); if ($debug) { error_log("url_get_contents: CURL SUCCESS {$url}"); } return remove_utf8_bom($output); } if ($debug) { error_log("url_get_contents: Nothing yet {$url}"); } return false; } diff --git a/plugin/Live/standAloneFiles/WebRTCServer/functions.php b/plugin/Live/standAloneFiles/WebRTCServer/functions.php index 05dcee10a..da37999b5 100644 --- a/plugin/Live/standAloneFiles/WebRTCServer/functions.php +++ b/plugin/Live/standAloneFiles/WebRTCServer/functions.php @@ -1,166 +1,166 @@ webRTC_SelfHostedURL = addLastSlash($live->webRTC_SelfHostedURL); - $webRTCServerURL = ($live->webRTC_SelfHostedURL).'plugin/Live/standAloneFiles/WebRTCServer/';; + $webRTCServerURL = ($live->webRTC_SelfHostedURL).'plugin/Live/standAloneFiles/WebRTCServer/'; $OME_HLS_STREAM_PORT = 7770; $OME_API_PORT = 7771; $OME_SOCKET_PORT = 7772; $OME_STREAM_PORT_TLS = 7773; $OME_TCP_RELAY_ADDRESS = 7774; $OME_ICE_CANDIDATES = '7775-7779'; $AccessToken = $global['salt'] . $ServerHost; $pushRTMP = false; $ServerHost = getHostOnlyFromURL($webRTCServerURL); $files = array( 'CertPath' => $live->webRTC_CertPath, 'KeyPath' => $live->webRTC_KeyPath, 'ChainCertPath' => $live->webRTC_ChainCertPath ); } else { //echo 'Config file not found try the standalone version ' . $configFile . PHP_EOL; $configFile = dirname(__FILE__) . '/configuration.php'; if (file_exists($configFile)) { require_once $configFile; require_once dirname(__FILE__) . '/extra_functions.php'; $parse = parse_url($webRTCServerURL); $domain = $parse['host']; $domain = str_replace("www.", "", $domain); $domain = preg_match("/^\..+/", $domain) ? ltrim($domain, '.') : $domain; $domain = preg_replace('/:[0-9]+$/', '', $domain); $ServerHost = $domain; } else { die('you need a configuration file on ' . $configFile . PHP_EOL); } } $AccessToken = md5($AccessToken); $AccessToken = $AccessToken . md5($ServerHost) . $OME_API_PORT; function getLinks($stream) { global $ServerHost, $OME_SOCKET_PORT, $OME_STREAM_PORT_TLS, $OME_HLS_STREAM_PORT; $links = array( 'publish_webrtc' => 'wss://' . $ServerHost . ':' . $OME_SOCKET_PORT . '/app/' . $stream . '?direction=send&transport=tcp', 'publish_rtmp' => 'rtmp://' . $ServerHost . ':' . $OME_SOCKET_PORT . '/app/' . $stream, 'webrtc' => 'wss://' . $ServerHost . ':' . $OME_SOCKET_PORT . '/app/' . $stream, 'hls' => 'https://' . $ServerHost . ':' . $OME_STREAM_PORT_TLS . '/app/' . $stream . '/playlist.m3u8', 'hls_local' => 'http://127.0.0.1:' . $OME_HLS_STREAM_PORT . '/app/' . $stream . '/playlist.m3u8', 'mpeg' => 'https://' . $ServerHost . ':' . $OME_STREAM_PORT_TLS . '/app/' . $stream . '/manifest.mpd', 'mpeg_low_latency' => 'https://' . $ServerHost . ':' . $OME_STREAM_PORT_TLS . '/app/' . $stream . '/manifest_ll.mpd' ); return $links; } function startLive($key, $RTMPLinkWithOutKey, $stream, $id) { global $ServerHost, $OME_API_PORT; $postFields = array( 'id' => $id, 'stream' => array('name' => $stream), 'protocol' => "rtmp ", 'url' => $RTMPLinkWithOutKey, 'streamKey' => $key ); $url = "http://{$ServerHost}:{$OME_API_PORT}/v1/vhosts/default/apps/app:startPush"; return requestWebRTCAPI($url, $postFields); } function stopLive($id) { global $ServerHost, $OME_API_PORT; $postFields = array( 'id' => $id ); $url = "http://{$ServerHost}:{$OME_API_PORT}/v1/vhosts/default/apps/app:stopPush"; return requestWebRTCAPI($url, $postFields); } function listLives() { global $ServerHost, $OME_API_PORT; $url = "http://{$ServerHost}:{$OME_API_PORT}/v1/vhosts/default/apps/app:pushes"; return requestWebRTCAPI($url, $postFields); } function stopUnused() { $obj = listLives(); $stopped = array(); foreach ($obj->responseJSON->response as $key => $value) { if ($value->secondsAgo > 60) { if (empty($value->sentBytes) && empty($value->sentTime)) { if ($value->state !== 'pushing') { $stopped[] = stopLive($value->id); } } } } return $stopped; } function requestWebRTCAPI($url, $postFields = array()) { global $AccessToken; $obj = new stdClass(); $obj->error = true; $obj->response = false; $obj->msg = ''; $obj->now = date('Y-m-d\TH:i:s'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Accept: application/json", "authorization: Basic " . base64_encode($AccessToken), )); if (!empty($postFields)) { curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields)); } $obj->response = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if ($err) { $obj->msg = "WebRTCLiveCam:request cURL Error #:" . $err; error_log($obj->msg); return $obj; } $obj->responseJSON = json_decode($obj->response); if ($obj->responseJSON->statusCode != 200) { $obj->msg = $obj->responseJSON->message; } else { $time = time(); foreach ($obj->responseJSON->response as $key => $value) { $obj->responseJSON->response[$key]->secondsAgo = $time - strtotime($obj->responseJSON->response[$key]->createdTime); } $obj->error = false; } return $obj; }