diff --git a/plugin/Live/standAloneFiles/WebRTCServer/functions.php b/plugin/Live/standAloneFiles/WebRTCServer/functions.php index 6da7ab17d..d20644850 100644 --- a/plugin/Live/standAloneFiles/WebRTCServer/functions.php +++ b/plugin/Live/standAloneFiles/WebRTCServer/functions.php @@ -1,166 +1,164 @@ webRTC_SelfHostedURL = addLastSlash($live->webRTC_SelfHostedURL); - $webRTCServerURL = $global['webSiteRootURL'].'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 = $live->webRTC_SelfHostedURL; $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; } diff --git a/plugin/Live/standAloneFiles/WebRTCServer/server.php b/plugin/Live/standAloneFiles/WebRTCServer/server.php index a0ce0bb6b..33f7ecdf7 100644 --- a/plugin/Live/standAloneFiles/WebRTCServer/server.php +++ b/plugin/Live/standAloneFiles/WebRTCServer/server.php @@ -1,83 +1,83 @@ $value) { // copy all certificates into the folder if (!file_exists($value)) { echo ('WebRTCLiveCam server ERROR file does not exists ' . $value . PHP_EOL); } else { - $command = "cp -Lr {$value} {$certificateFolderName}{$key}.pem"; + $command = "cp -Lr {$value} {$certificateFolderName}/{$key}.pem"; echo ($command . PHP_EOL); exec($command); } } $command = 'docker stop ' . $imageName . ' && docker rm ' . $imageName; exec($command); $path = '/var/lib/docker/volumes/ome-origin-conf/_data/'; make_path($path); $ServerXML = $path . 'Server.xml'; $LoggerXML = $path . 'Logger.xml'; if (file_exists($ServerXML)) { $command = 'rm ' . $ServerXML; exec($command); } if (!file_exists($LoggerXML)) { $command = 'cp ' . dirname(__FILE__) . '/Logger.xml ' . $LoggerXML; exec($command); } $content = file_get_contents(dirname(__FILE__) . '/Server.xml'); $search = array('{ServerHost}', '{AccessToken}', '{OME_API_PORT}'); $replace = array($ServerHost, $AccessToken, $OME_API_PORT); file_put_contents($ServerXML, str_replace($search, $replace, $content)); $command = 'docker run -d ' . "-p {$OME_API_PORT}:{$OME_API_PORT} " //. "-p 41935:41935 " //. "-p 3333:3333 " . "-p {$OME_SOCKET_PORT}:{$OME_SOCKET_PORT} " . "-p {$OME_TCP_RELAY_ADDRESS}:{$OME_TCP_RELAY_ADDRESS} " . "-p {$OME_HLS_STREAM_PORT}:{$OME_HLS_STREAM_PORT} " //. "-p 20081:20081 " //Thumbnail . "-p {$OME_STREAM_PORT_TLS}:{$OME_STREAM_PORT_TLS} " //. "-p 9000:9000 " //. "-p 9999:9999/udp " //. "-p 4000-4005:4000-4005/udp " . "-p {$OME_ICE_CANDIDATES}:{$OME_ICE_CANDIDATES}/udp " . "--env OME_API_PORT={$OME_API_PORT} " . "--env OME_STREAM_PORT_TLS={$OME_STREAM_PORT_TLS} " . "--env OME_HLS_STREAM_PORT={$OME_HLS_STREAM_PORT} " . "--env OME_SOCKET_PORT={$OME_SOCKET_PORT} " . "--env OME_TCP_RELAY_ADDRESS='*:{$OME_TCP_RELAY_ADDRESS}' " . "--env OME_ICE_CANDIDATES='*:{$OME_ICE_CANDIDATES}/udp' " . '-v ome-origin-conf:/opt/ovenmediaengine/bin/origin_conf ' . '-v ome-edge-conf:/opt/ovenmediaengine/bin/edge_conf ' . '-v ' . $certificateFolderName . ':/cert ' //. '--name '.$imageName.' youphptube/ovenmediaengine:v1'; . '--name ' . $imageName . ' airensoft/ovenmediaengine:latest'; echo ('Execute WebRTCLiveCam server: ' . PHP_EOL . $command . PHP_EOL); exec($command);