2020-03-18 01:35:58 +01:00
|
|
|
/* jshint browser: true */
|
|
|
|
/* global $ */
|
|
|
|
|
2020-03-22 00:31:56 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-03-18 01:55:57 +01:00
|
|
|
function putPreview (arrayBuf) {
|
|
|
|
var arrayBufView = new Uint8Array(arrayBuf)
|
|
|
|
var blob = new Blob([arrayBufView.buffer], { type: "audio/ogg" })
|
|
|
|
console.log(blob)
|
|
|
|
var url = URL.createObjectURL(blob);
|
|
|
|
var au = document.createElement('audio');
|
|
|
|
|
|
|
|
//name of .wav file to use during upload and download (without extendion)
|
|
|
|
var filename = new Date().toISOString();
|
|
|
|
|
|
|
|
//add controls to the <audio> element
|
|
|
|
au.controls = true;
|
|
|
|
au.src = url;
|
|
|
|
document.getElementById('preview').appendChild(au)
|
|
|
|
}
|
|
|
|
|
2020-03-18 02:19:21 +01:00
|
|
|
function upload(content) {
|
2020-03-18 01:35:58 +01:00
|
|
|
// questa funzione non critta, ma si deve comunque chiamare così!
|
2020-03-18 01:55:57 +01:00
|
|
|
|
|
|
|
$('#upload').on('click', function () {
|
|
|
|
// TODO: fai questo alla conferma
|
|
|
|
var submit = new XMLHttpRequest()
|
|
|
|
submit.open('POST', "upload/" + $('body').data('site'),true)
|
|
|
|
submit.onload = function (evt) {
|
|
|
|
console.log('ok, caricato!')
|
|
|
|
$('#bar').hide()
|
|
|
|
$('#spiegazione1').hide()
|
|
|
|
$('#status').text('Hai lasciato un messaggio in segreteria, grazie!')
|
|
|
|
}
|
|
|
|
submit.send(content)
|
|
|
|
})
|
2020-03-18 01:35:58 +01:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:19:21 +01:00
|
|
|
$(function guiFunctions() {
|
2020-03-18 01:55:57 +01:00
|
|
|
$('#preview').hide()
|
2020-03-18 01:35:58 +01:00
|
|
|
$('#stop_record').hide()
|
|
|
|
$('#visualizer').hide()
|
2020-03-18 02:19:21 +01:00
|
|
|
$('body').on('recording-start-ok', function() {
|
2020-03-22 00:31:48 +01:00
|
|
|
$('#help').hide()
|
2020-03-18 01:35:58 +01:00
|
|
|
$('#record_audio').hide()
|
|
|
|
$('#stop_record').show()
|
|
|
|
$('#visualizer').show()
|
|
|
|
})
|
2020-03-18 02:19:21 +01:00
|
|
|
$('body').on('recording-start-fail', function(evt, err) {
|
2020-03-22 00:31:48 +01:00
|
|
|
$('#help').hide()
|
2020-03-18 02:19:21 +01:00
|
|
|
$('#content').hide()
|
|
|
|
$('#container').text('Errore! apri il microfono')
|
|
|
|
})
|
|
|
|
$('body').on('recording-stop-ready', function(evt, content) {
|
2020-03-18 01:35:58 +01:00
|
|
|
$('#stop_record').hide()
|
|
|
|
$('#visualizer').hide()
|
2020-03-18 02:19:21 +01:00
|
|
|
$('#preview').show()
|
|
|
|
putPreview(content)
|
|
|
|
upload(content)
|
2020-03-18 01:35:58 +01:00
|
|
|
})
|
|
|
|
})
|