BxBaseUploaderRecordVideo.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Upload files using WebRTC webcam capture.
  11. * @see BxDolUploader
  12. */
  13. define('BX_UPLOADER_AUDIO_BITRATE', 128000); //128Kbit for audio
  14. define('BX_UPLOADER_VIDEO_BITRATE', 1000000); //1Mbit for video
  15. class BxBaseUploaderRecordVideo extends BxBaseUploaderSimple
  16. {
  17. public function __construct ($aObject, $sStorageObject, $sUniqId, $oTemplate)
  18. {
  19. parent::__construct($aObject, $sStorageObject, $sUniqId, $oTemplate);
  20. $this->_sButtonTemplate = 'uploader_button_record_video.html';
  21. $this->_sJsTemplate = 'uploader_button_record_video_js.html';
  22. $this->_sUploaderFormTemplate = 'uploader_form_record_video.html';
  23. $this->addJs([
  24. 'RecordRTC.min.js'
  25. ]);
  26. }
  27. public function getUploaderButtonTitle($mixed = false)
  28. {
  29. return _t('_sys_uploader_record_video_button_name');
  30. }
  31. public function getUploaderJs($mixedGhostTemplate, $isMultiple = true, $aParams = array(), $bDynamic = false)
  32. {
  33. if(!$aParams)
  34. $aParams = [];
  35. return parent::getUploaderJs($mixedGhostTemplate, $isMultiple, array_merge($aParams, [
  36. 'audio_bitrate' => BX_UPLOADER_AUDIO_BITRATE,
  37. 'video_bitrate' => BX_UPLOADER_VIDEO_BITRATE
  38. ]), $bDynamic);
  39. }
  40. public function addCssJs ($bDynamic = false)
  41. {
  42. $s = parent::addCssJs($bDynamic);
  43. $s .= $this->_oTemplate->addJsTranslation([
  44. '_sys_uploader_camera_capture_failed',
  45. '_sys_uploader_record_video_mb',
  46. '_sys_uploader_unsupported_browser',
  47. ], $bDynamic);
  48. return $bDynamic ? $s : '';
  49. }
  50. protected function getRestrictionsText ()
  51. {
  52. $sTextRestrictions = '';
  53. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  54. if (!$oStorage)
  55. return '';
  56. $sTextRestrictions = $oStorage->getRestrictionsTextFileSize(bx_get_logged_profile_id());
  57. if ($sTextRestrictions)
  58. $sTextRestrictions = '<div class="bx-uploader-msg-info bx-def-font-grayed">' . $sTextRestrictions . '</div>';
  59. return $sTextRestrictions;
  60. }
  61. /**
  62. * Handle uploads here.
  63. * @param $mixedFiles as usual $_FILES['some_name'] array, but maybe some other params depending on the uploader
  64. * @return nothing, but if some files failed to upload, the actual error message can be determined by calling BxDolUploader::getUploadErrorMessages()
  65. */
  66. public function handleUploads ($iProfileId, $mixedFiles, $isMultiple = true, $iContentId = false, $bPrivate = true)
  67. {
  68. //suppress any output here, because we are not posting to an iframe anymore and thus we must avoid a call to a window.parent as in parent::handleUploads
  69. //instead we are posting via AJAX to pass a recorded video as a blob object via a FormData object
  70. ob_start();
  71. parent::handleUploads($iProfileId, $mixedFiles, $isMultiple, $iContentId, $bPrivate);
  72. ob_end_clean();
  73. echo bx_js_string($this->getUploadErrorMessages(), BX_ESCAPE_STR_APOS);
  74. }
  75. }
  76. /** @} */