Skip to content

Commit

Permalink
Add WebRTC
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jan 12, 2025
1 parent e5c41d4 commit 5dc7bee
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 159 deletions.
2 changes: 1 addition & 1 deletion plugin/Live/getUploadMenuButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class="faa-parent animated-hover">
</a>
</li>
<li>
<a href="<?php echo "{$global['webSiteRootURL']}plugin/Live"; ?>" data-toggle="tooltip" title="<?php echo __('Go Live'); ?>" data-placement="left"
<a href="#" onclick="avideoModalIframeFull(webSiteRootURL + 'plugin/WebRTC/');return false;" data-toggle="tooltip" title="<?php echo __('Go Live'); ?>" data-placement="left"
class="faa-parent animated-hover">
<i class="fa-solid fa-camera"></i> <?php echo __('Go Live'); ?>
</a>
Expand Down
80 changes: 0 additions & 80 deletions plugin/Live/tabs/tabStreamSettings.new.php

This file was deleted.

7 changes: 5 additions & 2 deletions plugin/Live/tabs/tabStreamSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
</style>

<?php
include $global['systemRootPath'] . 'plugin/Live/tabs/tabStreamSettings.old.php';
//include $global['systemRootPath'] . 'plugin/Live/tabs/tabStreamSettings.new.php';
if(AVideoPlugin::isEnabledByName('WebRTC')){
include $global['systemRootPath'] . 'plugin/Live/tabs/tabStreamSettings.webcam.php';
}else{
include $global['systemRootPath'] . 'plugin/Live/tabs/tabStreamSettings.software.php';
}
?>
<div class="tabbable-line <?php echo getCSSAnimationClassAndStyle('animate__fadeInLeft', 'live'); ?>">
<ul class="nav nav-tabs">
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions plugin/Live/tabs/tabStreamSettings.webcam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="tabbable-line ">
<ul class="nav nav-tabs">
<li class="active" data-toggle="tooltip" data-placement="bottom" title="<?php echo __('Stream Software'); ?>">
<a data-toggle="tab" href="#tabStreamSoftware">
<i class="fa-solid fa-key"></i>
<?php echo __('Stream Software'); ?>
</a>
</li>
<li class="" data-toggle="tooltip" data-placement="bottom" title="<?php echo __('Webcam'); ?>">
<a data-toggle="tab" href="#tabWebcam">
<i class="fa-solid fa-camera"></i>
<?php echo __('Webcam'); ?>
</a>
</li>
</ul>
<div class="tab-content">
<div id="tabStreamSoftware" class="tab-pane fade in active">
<?php
include $global['systemRootPath'] . 'plugin/Live/tabs/tabStreamSettings.software.php';
?>
</div>
<div id="tabWebcam" class="tab-pane fade ">
<?php
include $global['systemRootPath'] . 'plugin/WebRTC/panel.php';
?>
</div>
</div>
</div>
79 changes: 46 additions & 33 deletions plugin/WebRTC/WebRTC.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public function getUUID()
return "webrtc-e578-4b91-96bb-4baaae5c0884";
}

public function getPluginVersion() {
public function getPluginVersion()
{
return "1.0";
}

public function getEmptyDataObject() {
public function getEmptyDataObject()
{
global $global;
$obj = new stdClass();

Expand All @@ -40,46 +42,75 @@ public function getEmptyDataObject() {
return $obj;
}

function executeEveryMinute() {
function executeEveryMinute()
{
self::startIfIsInactive();
}

static function startIfIsInactive(){
if(!self::checkIfIsActive()){
static function startIfIsInactive()
{
if (!self::checkIfIsActive()) {
self::startServer();
}
}

static function checkIfIsActive(){
static function checkIfIsActive()
{
$json = self::getJson();
if(!empty($json)){
return ($json->phpTimestamp > strtotime('-2 min')) ? $json->phpTimestamp : false;
}
return false;
}


public function getPluginMenu() {
global $global;
$btn = '<button onclick="avideoModalIframe(webSiteRootURL+\'plugin/WebRTC/status.php\')" class="btn btn-primary btn-sm btn-xs btn-block"><i class="fa-solid fa-list-check"></i> Server Status</button>';
return $btn;
}

static function getJson()
{
global $global;
$file = "{$global['systemRootPath']}plugin/WebRTC/WebRTC2RTMP.json";
if(file_exists($file)){
if (file_exists($file)) {
$content = file_get_contents($file);
if(!empty($content)){
if (!empty($content)) {
$json = json_decode($content);
if(!empty($json)){
return $json->phpTimestamp > strtotime('-2 min');
}
if (!empty($json)) {
return $json;
}
}
}
return false;
}


static function startServer(){
static function getLog()
{
global $global;
$file = "{$global['systemRootPath']}videos/WebRTC2RTMP.log";
if (file_exists($file)) {
return file_get_contents($file);
}
return false;
}

static function startServer()
{
_error_log('Starting WebRTC Server');
global $global;
$obj = AVideoPlugin::getDataObject('WebRTC');
$file = "{$global['systemRootPath']}plugin/WebRTC/WebRTC2RTMP";
$log = "{$global['systemRootPath']}videos/WebRTC2RTMP.log";
$command = "{$file} --port={$obj->port} > $log ";

// Check if the file has executable permissions
if (!is_executable($file)) {
// Attempt to give executable permissions
chmod($file, 0755); // 0755 grants read, write, and execute for the owner, and read and execute for others
}

// Try to execute the command
if (is_executable($file)) {
return execAsync($command);
Expand All @@ -88,22 +119,4 @@ static function startServer(){
return false;
}
}

static function killProcessOnPort() {
$obj = AVideoPlugin::getDataObject('WebRTC');
$port = intval($obj->port);
if (!empty($port)) {
echo 'Searching for port: ' . $port . PHP_EOL;
//$command = 'netstat -ano | findstr ' . $port;
//exec($command, $output, $retval);
$pid = getPIDUsingPort($port);
if (!empty($pid)) {
echo 'Server is already runing on port '.$port.' Killing, PID ' . $pid . PHP_EOL;
killProcess($pid);
} else {
echo 'No Need to kill, port NOT found' . PHP_EOL;
}
}
}

}
Binary file modified plugin/WebRTC/WebRTC2RTMP
Binary file not shown.
4 changes: 3 additions & 1 deletion plugin/WebRTC/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ function stopStreamToServer() {
}
}

function isWebcamServerConnected() {
return $('body').hasClass('WebcamServerConnected');
}

function setIsWebcamServerConnected() {
console.log('Connection success');
Expand Down Expand Up @@ -290,5 +293,4 @@ $(document).ready(function () {
startWebRTC(); // Call the startWebRTC function
}
});
requestNotifications();
});
60 changes: 30 additions & 30 deletions plugin/WebRTC/index.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<?php
require_once __DIR__ . '/../../videos/configuration.php';
AVideoPlugin::loadPlugin("Live");
$_GET['avideoIframe'] = 1;
$_page = new Page(array('Webcam'));
if (empty($_REQUEST['avideoIframe'])) {
?>
<div class="container">
<?php
include __DIR__ . '/panel.php';
?>
</div>
<style>
body {
overflow: hidden;
}

video {
position: fixed;
top: 0;
left: 0;
}
</style>

<?php
} else {
include __DIR__ . '/video.php';
?>
<div id="webcamMediaControls" class="showWhenWebRTCIsConnected">
<?php
include __DIR__ . '/video.php';
include __DIR__ . '/panel.medias.php';
include __DIR__ . '/panel.buttons.php';
?>
<div id="webcamMedias">
<?php
?>
</div>
<div id="webcamMediaControls" class="showWhenWebRTCIsConnected">
<?php
include __DIR__ . '/panel.medias.php';
include __DIR__ . '/panel.buttons.php';
?>
</div>
<div id="webcamMediaControlsMessage" class="alert alert-danger showWhenWebRTCIsNotConnected text-center">
<div class="fa-3x">
<i class="fa-solid fa-triangle-exclamation fa-fade"></i>
</div>
<strong>Error:</strong> Unable to connect to the Webcam server.<br>
<span>Please verify the server status and resolve any issues.</span>
</div>
<div id="webcamMediaControlsMessage" class="alert alert-danger showWhenWebRTCIsNotConnected text-center" style="display: none;">
<div class="fa-3x">
<i class="fa-solid fa-triangle-exclamation fa-fade"></i>
</div>
<strong>Error:</strong> Unable to connect to the Webcam server.<br>
<span>Please verify the server status and resolve any issues.</span>
</div>

<script>
$(document).ready(function() {
startWebRTC();
});
</script>
<script>
$(document).ready(function() {
startWebRTC();
});
</script>
<?php
}

$_page->print();
?>
2 changes: 1 addition & 1 deletion plugin/WebRTC/panel.buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<i class="fa fa-play"></i> Go Live
</button>
<button type="button" class="btn btn-default oval-menu animate__animated animate__bounceIn" onclick="toggleMediaSelector();" style=" -webkit-animation-delay: .2s; animation-delay: .2s;">
<i class="fa-solid fa-ellipsis-vertical"></i>
<i class="fa-solid fa-gear"></i>
</button>
</div>
<div class="text-center showWhenIsLive" style="display: none;">
Expand Down
2 changes: 1 addition & 1 deletion plugin/WebRTC/panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="panel-heading">

</div>
<div class="panel-body" style="position:relative;">
<div class="panel-body" style="position:relative; padding: 0;">
<?php
include __DIR__ . '/video.php';
?>
Expand Down
15 changes: 15 additions & 0 deletions plugin/WebRTC/status.json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
require_once dirname(__FILE__) . '/../../videos/configuration.php';

$objP = AVideoPlugin::getDataObject('WebRTC');

header('Content-Type: application/json');
$obj = array('error'=>false, 'msg'=>'');

$obj['port'] = $objP->port;
$obj['isActive'] = WebRTC::checkIfIsActive();
$obj['json'] = WebRTC::getJson();
$obj['log'] = WebRTC::getLog();

echo json_encode($obj);
?>
Loading

0 comments on commit 5dc7bee

Please sign in to comment.