Proyectos de Subversion Moodle

Rev

Rev 1 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"version":3,"file":"audio_recorder.min.js","sources":["../src/audio_recorder.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Tiny Record RTC - audio recorder configuration.\n *\n * @module      tiny_recordrtc/audio_recorder\n * @copyright   2022 Stevani Andolo <stevani@hotmail.com.au>\n * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport BaseClass from './base_recorder';\nimport Modal from './modal';\nimport {component} from 'tiny_recordrtc/common';\nimport {convertMp3} from './convert_to_mp3';\nimport {add as addToast} from 'core/toast';\n\nexport default class Audio extends BaseClass {\n\n    // A mapping of MIME types to their corresponding file extensions.\n    fileExtensions = {\n        'audio/ogg': 'ogg',\n        'audio/mp4': 'mp4',\n        'audio/webm': 'webm',\n    };\n\n    configurePlayer() {\n        return this.modalRoot.querySelector('audio');\n    }\n\n    getSupportedTypes() {\n        return [\n            // Firefox supports webm and ogg but Chrome only supports ogg.\n            // So we use ogg to maximize the compatibility.\n            'audio/ogg;codecs=opus',\n\n            // Safari supports mp4.\n            'audio/mp4;codecs=opus',\n            'audio/mp4;codecs=wav',\n            'audio/mp4;codecs=mp3',\n\n            // Set webm as a fallback.\n            'audio/webm;codecs=opus',\n        ];\n    }\n\n    getRecordingOptions() {\n        return {\n            audioBitsPerSecond: parseInt(this.config.audiobitrate),\n            audioBitsPerSecondInKb: parseInt(this.config.audiobitrate / 1000),\n        };\n    }\n\n    getMediaConstraints() {\n        return {\n            audio: true,\n        };\n    }\n\n    getRecordingType() {\n        return 'audio';\n    }\n\n    getTimeLimit() {\n        return this.config.audiotimelimit;\n    }\n\n    getEmbedTemplateName() {\n        return 'tiny_recordrtc/embed_audio';\n    }\n\n    getFileName(prefix) {\n        return `${prefix}-audio.${this.getFileExtension()}`;\n    }\n\n    getFileExtension() {\n        if (this.config.audiortcformat === 1) {\n            return 'mp3';\n        }\n\n        const options = super.getParsedRecordingOptions(); // Call parent method.\n        if (options?.mimeType) {\n            const mimeType = options.mimeType.split(';')[0];\n            return this.fileExtensions[mimeType];\n        }\n\n        window.console.warn(`Unknown file type for MediaRecorder API`);\n        return '';\n    }\n\n    static getModalClass() {\n        return class extends Modal {\n            static TYPE = `${component}/audio_recorder`;\n            static TEMPLATE = `${component}/audio_recorder`;\n        };\n    }\n\n    async uploadRecording() {\n        if (this.getFileExtension() === \"mp3\") {\n            try {\n                const options = this.getRecordingOptions();\n                this.blob = await convertMp3(this.player.src, options.audioBitsPerSecondInKb);\n                this.player.src = URL.createObjectURL(this.blob);\n            } catch (error) {\n                // Display a user-friendly error message\n                const message = `MP3 conversion failed: ${error.message || 'Unknown error'}. Please try again.`;\n                addToast(message, {type: 'error', delay: 6000});\n\n                // Disable the upload button.\n                this.setUploadButtonState(false);\n\n                return;\n            }\n        }\n\n        super.uploadRecording();\n    }\n}\n"],"names":["Audio","BaseClass","configurePlayer","this","modalRoot","querySelector","getSupportedTypes","getRecordingOptions","audioBitsPerSecond","parseInt","config","audiobitrate","audioBitsPerSecondInKb","getMediaConstraints","audio","getRecordingType","getTimeLimit","audiotimelimit","getEmbedTemplateName","getFileName","prefix","getFileExtension","audiortcformat","options","super","getParsedRecordingOptions","mimeType","split","fileExtensions","window","console","warn","Modal","component","blob","player","src","URL","createObjectURL","error","message","type","delay","setUploadButtonState","uploadRecording"],"mappings":"unBA6BqBA,cAAcC,+FAGd,aACA,kBACA,mBACC,SAGlBC,yBACWC,KAAKC,UAAUC,cAAc,SAGxCC,0BACW,CAGH,wBAGA,wBACA,uBACA,uBAGA,0BAIRC,4BACW,CACHC,mBAAoBC,SAASN,KAAKO,OAAOC,cACzCC,uBAAwBH,SAASN,KAAKO,OAAOC,aAAe,MAIpEE,4BACW,CACHC,OAAO,GAIfC,yBACW,QAGXC,sBACWb,KAAKO,OAAOO,eAGvBC,6BACW,6BAGXC,YAAYC,wBACEA,yBAAgBjB,KAAKkB,oBAGnCA,sBACuC,IAA/BlB,KAAKO,OAAOY,qBACL,YAGLC,QAAUC,MAAMC,+BAClBF,MAAAA,SAAAA,QAASG,SAAU,OACbA,SAAWH,QAAQG,SAASC,MAAM,KAAK,UACtCxB,KAAKyB,eAAeF,iBAG/BG,OAAOC,QAAQC,gDACR,mEAIA,cAAcC,kCACAC,kFACIA,wEAKO,QAA5B9B,KAAKkB,6BAEKE,QAAUpB,KAAKI,2BAChB2B,WAAa,6BAAW/B,KAAKgC,OAAOC,IAAKb,QAAQX,6BACjDuB,OAAOC,IAAMC,IAAIC,gBAAgBnC,KAAK+B,MAC7C,MAAOK,aAECC,yCAAoCD,MAAMC,SAAW,4DAClDA,QAAS,CAACC,KAAM,QAASC,MAAO,gBAGpCC,sBAAqB,SAM5BC"}