Exercises: Remove wami, update code from 1.11.x

pull/3768/head^2
Julio Montoya 4 years ago
parent e53d284379
commit cba83a54a3
  1. 9
      assets/css/scss/_base.scss
  2. 23
      public/main/inc/ajax/record_audio_rtc.ajax.php
  3. 56
      public/main/inc/lib/javascript/record_audio/record_audio.js
  4. 23
      public/main/template/default/document/record_audio.html.twig
  5. 41
      public/main/template/default/exercise/oral_expression.html.twig
  6. 8
      public/main/template/default/message/record_audio.html.twig
  7. 90
      src/CoreBundle/Resources/views/LearnPath/record_voice.html.twig

@ -3629,11 +3629,6 @@ table.certaintyTable {
border-radius: 25px;
}
.wami-container {
height: 144px;
position: relative;
}
/****** MAIN QUESTION ******/
.exercise_overview_options {
@ -3991,3 +3986,7 @@ table.certaintyTable {
.img-responsive {
@extend .img-fluid;
}
.hidden {
display: none!important;
}

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
@ -9,10 +10,10 @@ api_block_anonymous_users();
$courseInfo = api_get_course_info();
/** @var string $tool document or exercise */
$tool = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : '';
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
$tool = $_REQUEST['tool'] ?? '';
$type = $_REQUEST['type'] ?? 'document'; // can be document or message
if ('document' == $type) {
if ('document' === $type) {
api_protect_course_script();
}
@ -23,15 +24,21 @@ if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
header('Content-Type: application/json');
echo json_encode([
'error' => true,
'message' => Display::return_message(get_lang('Upload failed, please check maximum file size limits and folder rights.'), 'error'),
'message' => Display::return_message(
get_lang('Upload failed, please check maximum file size limits and folder rights.'),
'error'
),
]);
Display::cleanFlashMessages();
//Display::cleanFlashMessages();
exit;
}
Display::addFlash(
Display::return_message(get_lang('Upload failed, please check maximum file size limits and folder rights.'), 'error')
Display::return_message(
get_lang('Upload failed, please check maximum file size limits and folder rights.'),
'error'
)
);
exit;
}
@ -86,11 +93,11 @@ switch ($type) {
header('Content-Type: application/json');
echo json_encode([
'error' => $error,
'message' => Display::getFlashToString(),
//'message' => Display::getFlashToString(),
'fileUrl' => $data['document_url'],
]);
Display::cleanFlashMessages();
//Display::cleanFlashMessages();
exit;
}

@ -72,7 +72,7 @@ window.RecordAudio = (function () {
}
$.ajax({
url: _p.web_ajax + 'record_audio_rtc.ajax.php?' + $.param({
url: rtcInfo.recordAudioUrl + '?'+ $.param({
type: rtcInfo.type,
tool: (!!txtName.length ? 'document' : 'exercise')
}) + courseParams,
@ -214,57 +214,9 @@ window.RecordAudio = (function () {
}
}
function useWami(wamiInfo, fileName) {
$(wamiInfo.blockId).show();
if (!fileName) {
$('#btn-activate-wami').on('click', function (e) {
e.preventDefault();
fileName = $('#audio-title-wami').val();
if (!$.trim(fileName)) {
return;
}
$('#audio-title-wami').prop('readonly', true);
$(this).prop('disabled', true);
Wami.setup({
id: wamiInfo.containerId,
onReady : setupGUI,
swfUrl: _p.web_lib + 'wami-recorder/Wami.swf'
});
});
} else {
Wami.setup({
id: wamiInfo.containerId,
onReady: setupGUI,
swfUrl: _p.web_lib + 'wami-recorder/Wami.swf'
});
}
function setupGUI() {
var gui = new Wami.GUI({
id: wamiInfo.containerId,
singleButton: true,
recordUrl: _p.web_ajax + 'record_audio_wami.ajax.php?' + $.param({
waminame: fileName + '.wav',
wamidir: wamiInfo.directory,
wamiuserid: wamiInfo.userId,
type: wamiInfo.type
}),
buttonUrl: _p.web_lib + 'wami-recorder/buttons.png',
buttonNoUrl: _p.web_img + 'blank.gif'
});
gui.setPlayEnabled(false);
}
}
return {
init: function (rtcInfo, wamiInfo, fileName) {
$(rtcInfo.blockId + ', ' + wamiInfo.blockId).hide();
init: function (rtcInfo, fileName) {
$(rtcInfo.blockId).hide();
var webRTCIsEnabled = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.getUserMedia ||
navigator.mediaDevices.getUserMedia;
@ -274,8 +226,6 @@ window.RecordAudio = (function () {
return;
}
useWami(wamiInfo, fileName);
}
}
})();

@ -9,6 +9,17 @@
<div class="form-group">
<span class="fa fa-microphone fa-5x fa-fw" aria-hidden="true"></span>
<span class="sr-only">{{ 'RecordAudio'|get_lang }}</span>
<div id="timer" style="display: none">
<h2>
<div class="label label-danger">
<span id="hour">00</span>
<span class="divider">:</span>
<span id="minute">00</span>
<span class="divider">:</span>
<span id="second">00</span>
</div>
</h2>
</div>
</div>
<div class="form-group">
<input type="text" name="audio_title" id="audio-title-rtc" class="form-control" placeholder="{{ 'InputNameHere'|get_lang }}">
@ -24,7 +35,7 @@
<span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'StopRecordingAudio'|get_lang }}
</button>
<button class="btn btn-success hidden" type="button" id="btn-save-record"
data-loadingtext="{{ 'Uploading'|get_lang }}" disabled>
data-loadingtext="{{ 'Uploading'|get_lang }}" disabled>
<span class="fa fa-send fa-fw" aria-hidden="true"></span> {{ 'SaveRecordedAudio'|get_lang }}
</button>
</div>
@ -65,15 +76,11 @@
btnStopId: '#btn-stop-record',
btnSaveId: '#btn-save-record',
plyrPreviewId: '#record-preview',
cidReq :'{{ course_url_params }}',
directory: '{{ directory }}',
reload_page: 1,
type: 'document',
},
{
blockId: '#record-audio-wami',
containerId: 'record-audio-wami-container',
directory: '{{ directory }}',
userId: {{ user_id }},
type: 'document'
recordAudioUrl: '{{ url('legacy_main', {name: 'inc/ajax/record_audio_rtc.ajax.php'}) }}',
},
null
);

@ -1,15 +1,15 @@
<div id="record-audio-recordrtc-{{ question_id }}" class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="col-sm-12">
<div class="form-group text-center">
<span class="fa fa-microphone fa-5x fa-fw" aria-hidden="true"></span>
<span class="sr-only">{{ 'RecordAudio'|get_lang }}</span>
<span class="sr-only">{{ 'Record audio'|trans }}</span>
</div>
</div>
<div class="col-sm-12">
<div class="form-group text-center">
<div id="timer" style="display: none">
<h2>
<div class="label label-danger">
<div class="badge badge-danger">
<span id="hour">00</span>
<span class="divider">:</span>
<span id="minute">00</span>
@ -21,31 +21,36 @@
</div>
<button class="btn btn-primary" type="button" id="btn-start-record-{{ question_id }}">
<span class="fa fa-circle fa-fw" aria-hidden="true"></span> {{ 'StartRecordingAudio'|get_lang }}
<span class="fa fa-circle fa-fw" aria-hidden="true"></span> {{ 'Start recording'|trans }}
</button>
<button class="btn btn-primary hidden" type="button" id="btn-pause-record-{{ question_id }}" disabled>
<span class="fa fa-pause fa-fw" aria-hidden="true"></span> {{ 'PauseRecordingAudio'|get_lang }}
<span class="fa fa-pause fa-fw" aria-hidden="true"></span> {{ 'Pause recording'|trans }}
</button>
<button class="btn btn-primary hidden" type="button" id="btn-play-record-{{ question_id }}" disabled>
<span class="fa fa-play fa-fw" aria-hidden="true"></span> {{ 'PlayRecordingAudio'|get_lang }}
<span class="fa fa-play fa-fw" aria-hidden="true"></span> {{ 'Resume recording'|trans }}
</button>
<button class="btn btn-danger hidden" type="button" id="btn-stop-record-{{ question_id }}" disabled>
<span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'StopRecordingAudio'|get_lang }}
<span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'Stop recording'|trans }}
</button>
<button class="btn btn-success hidden" type="button" id="btn-save-record-{{ question_id }}"
data-loadingtext="{{ 'Uploading'|get_lang }}"
data-loadingtext="{{ 'Uploading'|trans }}"
disabled>
<span class="fa fa-send fa-fw" aria-hidden="true"></span> {{ 'SaveRecordedAudio'|get_lang }}
<span class="fa fa-send fa-fw" aria-hidden="true"></span> {{ 'Save recorded audio'|trans }}
</button>
<button id="hide_description_{{ question_id }}" type="button" class="btn btn-default advanced_options" data-toggle="button" aria-pressed="false" autocomplete="off">
<em class="fa fa-bars"></em> {{ 'AddText' | get_lang }}
<button
id="hide_description_{{ question_id }}"
type="button"
class="btn btn-default advanced_options" data-toggle="button" aria-pressed="false" autocomplete="off">
<em class="fa fa-bars"></em> {{ 'Add text' | trans }}
</button>
</div>
<div class="form-group text-center">
<audio class="skip hidden center-block" controls id="record-preview-{{ question_id }}"></audio>
</div>
<div class="well">
{{ 'OralExpressionHelpText' | get_lang }}
<div class="card bg-light mb-3">
<div class="card-body">
{{ 'When you start recording, you can pause whenever you want. If you are not satisfied, register again. This will overwrite the previous version. Satisfied? the file is automatically sent to the server so you can just continue your exercise.'|trans }}
</div>
</div>
<div class="record-message"></div>
</div>
@ -67,13 +72,9 @@
btnStopId: '#btn-stop-record-{{ question_id }}',
plyrPreviewId: '#record-preview-{{ question_id }}',
directory: '{{ directory }}',
type: 'document'
}, {
blockId: '#record-audio-wami-{{ question_id }}',
containerId: 'record-audio-wami-container-{{ question_id }}',
directory: '{{ directory }}',
userId: {{ user_id }},
type: 'document'
type: 'document',
recordAudioUrl: '{{ url('legacy_main', {name: 'inc/ajax/record_audio_rtc.ajax.php'}) }}',
cidReq: '{{ course_url_params }}'
}, '{{ file_name }}');
if (0 === $('#hide_description_{{ question_id }}_options').length) {

@ -58,13 +58,7 @@
directory: '{{ directory }}',
reload_page: '{{ reload_page }}',
type: 'message',
},
{
blockId: '#record-audio-wami',
containerId: 'record-audio-wami-container',
directory: '{{ directory }}',
userId: {{ user_id }},
type: 'message'
recordAudioUrl: '{{ url('legacy_main', {name: 'inc/ajax/record_audio_rtc.ajax.php'}) }}',
},
null
);

@ -1,37 +1,38 @@
<div id="record-audio-recordrtc" class="text-center">
<p>
<span class="fa fa-microphone fa-5x fa-fw" aria-hidden="true"></span>
<span class="sr-only">{{ 'RecordAudio'|trans }}</span>
<div id="timer" style="display: none">
<h2>
<div class="label label-danger">
<span id="hour">00</span>
<span class="divider">:</span>
<span id="minute">00</span>
<span class="divider">:</span>
<span id="second">00</span>
</div>
</h2>
<br />
</div>
<div class="form-group">
<input type="text" name="audio_title" id="audio-title-rtc" class="form-control" placeholder="{{ 'InputNameHere'|trans }}" />
</div>
<span class="sr-only">{{ 'Record audio'|trans }}</span>
<div id="timer" style="display: none">
<h2>
<div class="badge badge-danger">
<span id="hour">00</span>
<span class="divider">:</span>
<span id="minute">00</span>
<span class="divider">:</span>
<span id="second">00</span>
</div>
</h2>
<br />
</div>
<div class="form-group">
<input
type="text"
name="audio_title"
id="audio-title-rtc"
class="form-control"
placeholder="{{ 'Enter filename here'|trans }}"
/>
</div>
</p>
<button class="btn btn-primary" type="button" id="btn-start-record">
<span class="fa fa-circle fa-fw" aria-hidden="true"></span> {{ 'StartRecordingAudio'|trans }}
<span class="fa fa-circle fa-fw" aria-hidden="true"></span> {{ 'Start recording'|trans }}
</button>
<button class="btn btn-success" type="button" id="btn-stop-record" disabled>
<span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'StopRecordingAudio'|trans }}
<span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'Stop recording'|trans }}
</button>
</div>
<div id="record-audio-wami" class="wami-container"></div>
<script>
$(function() {
var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
function startTimer() {
$("#timer").show();
@ -84,7 +85,7 @@
btnStart.on('click', function () {
if ('' === audioTitle.val()) {
alert('{{ 'TitleIsRequired'|trans | escape }} ');
alert('{{ 'Title is required'|trans | escape }} ');
return false;
}
@ -93,11 +94,12 @@
stopTimer();
startTimer();
recordRTC = RecordRTC(stream, {
recorderType: isSafari ? RecordRTC.StereoAudioRecorder : RecordRTC.MediaStreamRecorder,
type: 'audio'
recorderType: RecordRTC.StereoAudioRecorder,
type: 'audio',
mimeType: 'audio/wav',
numberOfAudioChannels: 2
});
recordRTC.startRecording();
btnStop.prop('disabled', false);
btnStart.prop('disabled', true);
}
@ -155,38 +157,6 @@
});
}
function useWami(){
$('#record-audio-wami').show();
function setupGUI() {
var gui = new Wami.GUI({
id : 'record-audio-wami',
singleButton : true,
recordUrl : '{{ url('legacy_main', {name: 'inc/ajax/record_audio_wami.ajax.php'}) }}?' + $.param({
waminame: 'rec_' + (new Date()).getTime() + '.wav',
wamidir: '{{ cur_dir_path }}',
wamiuserid: {{ app.user.id }},
lp_item_id: {{ lp_item_id }}
}),
buttonUrl : 'wami-recorder/buttons.png',
buttonNoUrl: 'blank.gif',
onRecordFinish: function() {
$('#start-recording').hide();
window.location.reload();
}
});
gui.setPlayEnabled(false);
}
Wami.setup({
id : "record-audio-wami",
onReady : setupGUI,
swfUrl: '{{ url('legacy_main', {name: 'inc/lib/wami-recorder/Wami.swf'}) }}'
});
}
$('#record-audio-recordrtc, #record-audio-wami').hide();
var webRTCIsEnabled = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.getUserMedia ||
navigator.mediaDevices.getUserMedia;
@ -195,7 +165,5 @@
return;
}
useWami();
});
</script>

Loading…
Cancel
Save