Skip to content

Commit

Permalink
Added suggestions and improved flow (Remove time, Reverted MJPEG Test…
Browse files Browse the repository at this point in the history
…ing, Switched to TCP)
  • Loading branch information
JahleelAbraham committed Mar 21, 2024
1 parent ab2f4a3 commit 4896efd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
21 changes: 11 additions & 10 deletions www/ajax/editip.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public function postData()
$id = intval($_POST['id']);
$camera = new ipCamera($id);
$result = $camera->edit($_POST);
$camera->checkConnection();
data::responseJSON($result[0], array(
$result[1],
str_replace(array("%TYPE%", "%TIME%"), array("RTSP", $camera->info['connection_status']['lastTimeChecked']),
$camera = new ipCamera($id); // Reinstance the object to update information
$camera->checkConnection(); // Test the connection
data::responseJSON($result[0], $result[1], array(
json_encode($camera->info['connection_status']),
str_replace("%TYPE%", str_replace("IP-", "", $camera->info['protocol']),
$camera->info['connection_status']['success'] ? AIP_CONNECTION_SUCCESS : AIP_CONNECTION_FAIL)
), json_encode($camera->info['connection_status']));
));
exit();
}

Expand All @@ -34,11 +35,11 @@ public function postTest()
$id = intval($_POST['id']);
$camera = new ipCamera($id);
$camera->checkConnection();
data::responseJSON(10, array( 1 => str_replace( //-> 10 as status to avoid the "changes saved successfully" popup
array("%TYPE%", "%TIME%"),
array("RTSP", $camera->info['connection_status']['lastTimeChecked']),
$camera->info['connection_status']['success'] ? AIP_CONNECTION_SUCCESS : AIP_CONNECTION_FAIL)
), json_encode($camera->info['connection_status']));
data::responseJSON(10, "", array(
json_encode($camera->info['connection_status']),
str_replace("%TYPE%", str_replace("IP-", "", $camera->info['protocol']),
$camera->info['connection_status']['success'] ? AIP_CONNECTION_SUCCESS : AIP_CONNECTION_FAIL)
));
exit();
}
}
4 changes: 2 additions & 2 deletions www/lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@
define('AIP_LIMIT_ALLOWED_DEVICES', 'Could not add a camera, because exceeds the limit of the allowed devices.');
define('AIP_TEST_CONNECTION', 'Test Connection');
define('AIP_TEST_CONNECTION_MESSAGE', 'Test connection to IP Camera');
define('AIP_CONNECTION_SUCCESS', 'Connection Successful using %TYPE%. Tested at %TIME%');
define('AIP_CONNECTION_FAIL', 'Connection Unsuccessful using %TYPE%. Tested at %TIME%');
define('AIP_CONNECTION_SUCCESS', 'Connection Successful using %TYPE%');
define('AIP_CONNECTION_FAIL', 'Connection Unsuccessful using %TYPE%');

# HLS configuration
define('AIP_HLS_WINDOW_SIZE', 'HLS window size');
Expand Down
27 changes: 13 additions & 14 deletions www/lib/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,31 +773,29 @@ public function checkConnection() {

$path = "";

switch(($this->info['protocol'])) {
switch($this->info['protocol']) {
case 'IP-RTSP':
$path = 'rtsp://'.((empty($this->info['rtsp_username'])) ? '' : $this->info['rtsp_username'].':'.$this->info['rtsp_password'].'@').$this->info['ipAddr'].':'.$this->info['port'].$this->info['rtsp'];
break;
case 'IP-MJPEG':
$path= 'http://'.((empty($this->info['rtsp_username'])) ? '' : $this->info['rtsp_username'].':'.$this->info['rtsp_password'].'@').((empty($this->info['ipAddrMjpeg'])) ? $this->info['ipAddr'] : $this->info['ipAddrMjpeg']).':'.$this->info['portMjpeg'].$this->info['mjpeg_path'];
$path = '-rtsp_transport tcp "rtsp://'.((empty($this->info['rtsp_username'])) ? '' : $this->info['rtsp_username'].':'.$this->info['rtsp_password'].'@').$this->info['ipAddr'].':'.$this->info['port'].$this->info['rtsp'].'"';
break;
case 'IP-MJPEG':
//FIXME: This is the old logic for testing MJPEG. Testing for MJPEG is currently not supported by the bundled ffprobe method used for RTSP
$path = 'http://'.((empty($this->info['rtsp_username'])) ? '' : $this->info['rtsp_username'].':'.$this->info['rtsp_password'].'@').((empty($this->info['ipAddrMjpeg'])) ? $this->info['ipAddr'] : $this->info['ipAddrMjpeg']).':'.$this->info['portMjpeg'].$this->info['mjpeg_path'];
$headers = @get_headers($path);
if (!$headers) { $this->info['connection_status']['success'] = false; return; }
preg_match("/([0-9]{3})/", $headers[0], $response_code);
$this->info['connection_status']['success'] = ($response_code[0]=='200') ? true : false;
return;
}

//-> '-stimeout' is measured in microseconds
$ffprobe_output = shell_exec(
"LD_LIBRARY_PATH=/usr/lib/bluecherry/ /usr/lib/bluecherry/ffprobe -stimeout 5000000 -hide_banner -show_format -show_streams -print_format json \"".$path."\"");
"/usr/lib/bluecherry/ffprobe -stimeout 5000000 -hide_banner -show_format -show_streams -print_format json ".$path);

$rtsp_data = json_decode($ffprobe_output, true);

$this->info['connection_status']['lastTimeChecked'] = date("d/m/Y h:i a"); //TODO: Make date/time formatting regional
$this->info['connection_status']['success'] = array_key_exists('streams', $rtsp_data) ? count($rtsp_data['streams']) > 0 : false;


#needs server to check for RTSP //// $paths['rtsp'] = 'http://'.((empty($this->info['rtsp_username'])) ? '' : $this->info['rtsp_username'].':'.$this->info['rtsp_password'].'@').$this->info['ipAddr'].':'.$this->info['port'].$this->info['rtsp'];
//FIXME: Test mjpeg
//$paths['mjpeg'] = 'http://'.((empty($this->info['rtsp_username'])) ? '' : $this->info['rtsp_username'].':'.$this->info['rtsp_password'].'@').((empty($this->info['ipAddrMjpeg'])) ? $this->info['ipAddr'] : $this->info['ipAddrMjpeg']).':'.$this->info['portMjpeg'].$this->info['mjpeg_path'];
// TODO: Test http
//$paths['http'] = 'http://'.((empty($this->info['rtsp_username'])) ? '' : $this->info['rtsp_username'].':'.$this->info['rtsp_password'].'@').((empty($this->info['ipAddrMjpeg'])) ? $this->info['ipAddr'] : $this->info['ipAddrMjpeg']);
}

protected static function autoConfigure($driver, $info){ #auto configure known cameras
include_once("ipcamlib.php");
$result = false;
Expand Down Expand Up @@ -874,6 +872,7 @@ public function edit($data){
#if there were no errors, edit the camera
$query = data::formQueryFromArray('update', 'Devices', $data[1], 'id', $this->info['id']);
$result = data::query($query, true);

return array($result, false);
}
public static function create($rawData){
Expand Down
6 changes: 3 additions & 3 deletions www/template/dist/js/editip.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
$(function() {
});
function testCameraConnection(form, msg) {
let data = JSON.parse(msg.data);
let data = JSON.parse(msg.data[0]);

$('#connStat').find('form').show();
if(data.success)
$('#connStat').removeClass().addClass('alert alert-success').find('span').html(msg.msg[1]);
$('#connStat').removeClass().addClass('alert alert-success').find('span').html(msg.data[1]);
else
$('#connStat').removeClass().addClass('alert alert-danger').find('span').html(msg.msg[1]);
$('#connStat').removeClass().addClass('alert alert-danger').find('span').html(msg.data[1]);
}

function testCameraLoadingHeader(form, msg) {
Expand Down

0 comments on commit 4896efd

Please sign in to comment.