Call Recordings: Audio waveform generation integration.

This commit is contained in:
fusionate
2024-02-09 13:09:52 -07:00
parent 1dae61de51
commit b11901ad4d
2 changed files with 135 additions and 9 deletions

View File

@@ -230,16 +230,16 @@
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param, "class='shrink'");
}
echo th_order_by('caller_id_name', $text['label-caller_id_name'], $order_by, $order, null, "class='hide-sm-dn shrink'");
echo th_order_by('caller_id_number', $text['label-caller_id_number'], $order_by, $order, null, "class='pct-10'");
echo th_order_by('caller_id_number', $text['label-caller_id_number'], $order_by, $order, null, "class='pct-20'");
echo th_order_by('caller_destination', $text['label-caller_destination'], $order_by, $order, null, "class='hide-sm-dn shrink'");
echo th_order_by('destination_number', $text['label-destination_number'], $order_by, $order, null, "class='hide-sm-dn shrink'");
echo th_order_by('call_recording_name', $text['label-call_recording_name'], $order_by, $order, null, "class='pct-40 hide-sm-dn'");
echo th_order_by('destination_number', $text['label-destination_number'], $order_by, $order, null, "class='pct-20 shrink'");
echo th_order_by('call_recording_name', $text['label-call_recording_name'], $order_by, $order, null, "class='pct-30 hide-sm-dn'");
if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) {
echo "<th class='shrink center'>".$text['label-recording']."</th>\n";
$col_count++;
}
echo th_order_by('call_recording_length', $text['label-call_recording_length'], $order_by, $order, null, "class='right hide-sm-dn shrink'");
echo th_order_by('call_recording_date', $text['label-call_recording_date'], $order_by, $order, null, "class='center'");
echo th_order_by('call_recording_date', $text['label-call_recording_date'], $order_by, $order, null, "class='pct-30 center'");
echo th_order_by('call_direction', $text['label-call_direction'], $order_by, $order, null, "class='hide-sm-dn shrink'");
if (permission_exists('xml_cdr_details')) {
echo " <td class='action-button'>&nbsp;</td>\n";
@@ -254,7 +254,7 @@
//playback progress bar
if (permission_exists('call_recording_play')) {
echo "<tr class='list-row' id='recording_progress_bar_".escape($row['call_recording_uuid'])."' style='display: none;'><td class='playback_progress_bar_background' style='padding: 0; border: none;' colspan='".$col_count."'><span class='playback_progress_bar' id='recording_progress_".escape($row['call_recording_uuid'])."'></span></td>".(permission_exists('xml_cdr_details') ? "<td class='action-button' style='border-bottom: none !important;'></td>" : null)."</tr>\n";
echo "<tr class='list-row' id='recording_progress_bar_".escape($row['call_recording_uuid'])."' style='display: none;' onclick=\"recording_play('".escape($row['call_recording_uuid'])."')\"><td id='playback_progress_bar_background_".escape($row['call_recording_uuid'])."' class='playback_progress_bar_background' colspan='".$col_count."'><span class='playback_progress_bar' id='recording_progress_".escape($row['call_recording_uuid'])."'></span></td>".(permission_exists('xml_cdr_details') ? "<td class='action-button' style='border-bottom: none !important;'></td>" : null)."</tr>\n";
echo "<tr class='list-row' style='display: none;'><td></td></tr>\n"; // dummy row to maintain alternating background color
}
if (permission_exists('call_recording_play')) {
@@ -273,8 +273,8 @@
echo " <td class='hide-sm-dn shrink'>".escape($row['caller_id_name'])."</td>\n";
echo " <td class='overflow'>".escape($row['caller_id_number'])."</td>\n";
echo " <td class='overflow hide-sm-dn shrink'>".escape($row['caller_destination'])."</td>\n";
echo " <td class='overflow hide-sm-dn shrink'>".escape($row['destination_number'])."</td>\n";
echo " <td class='hide-sm-dn nowrap'>".escape($row['call_recording_name'])."</td>\n";
echo " <td class='overflow shrink'>".escape($row['destination_number'])."</td>\n";
echo " <td class='overflow hide-sm-dn nowrap'>".escape($row['call_recording_name'])."</td>\n";
if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) {
echo " <td class='middle button center no-link no-wrap'>";
if (file_exists($row['call_recording_path'].'/'.$row['call_recording_name'])) {
@@ -295,7 +295,7 @@
echo " </td>\n";
}
echo " <td class='right overflow hide-sm-dn shrink'>".($row['call_recording_length'] <= 59 ? '0:' : null).escape($call_recording_length_padding)."</td>\n";
echo " <td class='center no-wrap'>".escape($row['call_recording_date_formatted'])." <span class='hide-sm-dn'>".escape($row['call_recording_time_formatted'])."</span></td>\n";
echo " <td class='overflow center no-wrap'>".escape($row['call_recording_date_formatted'])." <span class='hide-sm-dn'>".escape($row['call_recording_time_formatted'])."</span></td>\n";
echo " <td class='left hide-sm-dn shrink'>".($row['call_direction'] != '' ? escape($text['label-'.$row['call_direction']]) : null)."</td>\n";
if (permission_exists('xml_cdr_details')) {
echo " <td class='action-button'>\n";
@@ -317,4 +317,4 @@
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@@ -0,0 +1,126 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2024
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform;
//check permisions
if (permission_exists('call_recording_play')) {
//access granted
}
else {
echo "access denied";
exit;
}
//create the waveform file
if (is_uuid($_GET['id'])) {
//get call recording details from database
$sql = "select call_recording_name, call_recording_path ";
if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) {
$sql = ", call_recording_base64 ";
}
$sql .= "from view_call_recordings ";
$sql .= "where call_recording_uuid = :call_recording_uuid ";
$parameters['call_recording_uuid'] = $_GET['id'];
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$call_recording_name = $row['call_recording_name'];
$call_recording_path = $row['call_recording_path'];
if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) {
file_put_contents($call_recording_path.'/'.$call_recording_name, base64_decode($row['call_recording_base64']));
}
}
unset($sql, $parameters);
//build full path
$full_recording_path = $call_recording_path.'/'.$call_recording_name;
//stream waveform file
if ($full_recording_path != '/' && file_exists($full_recording_path)) {
//temporary waveform image filename
$temp_filename = 'waveform_'.$_GET['id'].'_'.rand(0000,9999).'.png';
//create temporary waveform image, if doesn't exist
if (file_exists($temp_filename)) {
$wf = true;
}
else {
//create temporary waveform image
$waveform = new Waveform($full_recording_path);
Waveform::$linesPerPixel = 1; // default: 8
Waveform::$samplesPerLine = 512; // default: 512
Waveform::$colorA = !empty($_SESSION['theme']['audio_player_waveform_color_a_leg']['text']) ? color_to_rgba_array($_SESSION['theme']['audio_player_waveform_color_a_leg']['text']) : [32,134,37,0.6]; // array rgba, left (a-leg) wave color
Waveform::$colorB = !empty($_SESSION['theme']['audio_player_waveform_color_b_leg']['text']) ? color_to_rgba_array($_SESSION['theme']['audio_player_waveform_color_b_leg']['text']) : [0,125,232,0.6]; // array rgba, right (b-leg) wave color
Waveform::$backgroundColor = !empty($_SESSION['theme']['audio_player_waveform_color_background']['text']) ? color_to_rgba_array($_SESSION['theme']['audio_player_waveform_color_background']['text']) : [0,0,0,0]; // array rgba, default: transparent
Waveform::$axisColor = !empty($_SESSION['theme']['audio_player_waveform_color_axis']['text']) ? color_to_rgba_array($_SESSION['theme']['audio_player_waveform_color_axis']['text']) : [0,0,0,0.3]; // array rgba
Waveform::$singlePhase = empty($_SESSION['theme']['audio_player_waveform_single_phase']['boolean']) || $_SESSION['theme']['audio_player_waveform_single_phase']['boolean'] !== 'true' ? false : true; // positive phase only - left (a-leg) top, right (b-leg) bottom
Waveform::$singleAxis = empty($_SESSION['theme']['audio_player_waveform_single_axis']['boolean']) || $_SESSION['theme']['audio_player_waveform_single_axis']['boolean'] !== 'false' ? true : false; // combine channels into single axis
$height = !empty($_SESSION['theme']['audio_player_waveform_height']['text']) && is_numeric(str_replace('px','',$_SESSION['theme']['audio_player_waveform_height']['text'])) ? 2.2 * (int) str_replace('px','',$_SESSION['theme']['audio_player_waveform_height']['text']) : null;
$wf = $waveform->getWaveform($temp_filename, 1600, $height ?? 180); // input: png filename returns boolean true/false, or 'base64' returns base64 string
}
//stream image to browser
if ($wf === true && file_exists($temp_filename)) {
ob_clean();
$fd = fopen($temp_filename, 'rb');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Type: image/png");
header('Content-Disposition: attachment; filename="'.$temp_filename.'"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Length: ".filesize($temp_filename));
ob_clean();
fpassthru($fd);
}
}
//if base64, remove temp recording file
if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) {
@unlink($full_recording_path);
}
unset($row);
//delete temp waveform image
@unlink($temp_filename);
}
?>