messaggeria/static/js/upload.js
2020-03-22 00:31:56 +01:00

65 lines
1.8 KiB
JavaScript

/* jshint browser: true */
/* global $ */
/**
*
* @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3
*/
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)
}
function upload(content) {
// questa funzione non critta, ma si deve comunque chiamare così!
$('#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)
})
}
$(function guiFunctions() {
$('#preview').hide()
$('#stop_record').hide()
$('#visualizer').hide()
$('body').on('recording-start-ok', function() {
$('#help').hide()
$('#record_audio').hide()
$('#stop_record').show()
$('#visualizer').show()
})
$('body').on('recording-start-fail', function(evt, err) {
$('#help').hide()
$('#content').hide()
$('#container').text('Errore! apri il microfono')
})
$('body').on('recording-stop-ready', function(evt, content) {
$('#stop_record').hide()
$('#visualizer').hide()
$('#preview').show()
putPreview(content)
upload(content)
})
})