upload.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* jshint browser: true */
  2. /* global $ */
  3. function putPreview (arrayBuf) {
  4. var arrayBufView = new Uint8Array(arrayBuf)
  5. var blob = new Blob([arrayBufView.buffer], { type: "audio/ogg" })
  6. console.log(blob)
  7. var url = URL.createObjectURL(blob);
  8. var au = document.createElement('audio');
  9. //name of .wav file to use during upload and download (without extendion)
  10. var filename = new Date().toISOString();
  11. //add controls to the <audio> element
  12. au.controls = true;
  13. au.src = url;
  14. document.getElementById('preview').appendChild(au)
  15. }
  16. function upload(content) {
  17. // questa funzione non critta, ma si deve comunque chiamare così!
  18. $('#upload').on('click', function () {
  19. // TODO: fai questo alla conferma
  20. var submit = new XMLHttpRequest()
  21. submit.open('POST', "upload/" + $('body').data('site'),true)
  22. submit.onload = function (evt) {
  23. console.log('ok, caricato!')
  24. $('#bar').hide()
  25. $('#spiegazione1').hide()
  26. $('#status').text('Hai lasciato un messaggio in segreteria, grazie!')
  27. }
  28. submit.send(content)
  29. })
  30. }
  31. $(function guiFunctions() {
  32. $('#preview').hide()
  33. $('#stop_record').hide()
  34. $('#visualizer').hide()
  35. $('body').on('recording-start-ok', function() {
  36. $('#record_audio').hide()
  37. $('#stop_record').show()
  38. $('#visualizer').show()
  39. })
  40. $('body').on('recording-start-fail', function(evt, err) {
  41. $('#content').hide()
  42. $('#container').text('Errore! apri il microfono')
  43. })
  44. $('body').on('recording-stop-ready', function(evt, content) {
  45. $('#stop_record').hide()
  46. $('#visualizer').hide()
  47. $('#preview').show()
  48. putPreview(content)
  49. upload(content)
  50. })
  51. })