upload.js 1.8 KB

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