mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
1 line
22 KiB
JSON
1 line
22 KiB
JSON
|
|
{"ast":null,"code":"import _asyncToGenerator from \"C:/Users/eudes.inacio/GabineteDigital/gabinete-digital-fo/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport getBlobDuration from 'get-blob-duration';\nimport { alreadyRecordingError, couldNotQueryPermissionStatusError, deviceCannotVoiceRecordError, emptyRecordingError, failedToFetchRecordingError, failedToRecordError, failureResponse, missingPermissionError, recordingHasNotStartedError, successResponse } from './predefined-web-responses';\n// these mime types will be checked one by one in order until one of them is found to be supported by the current browser\nconst possibleMimeTypes = ['audio/aac', 'audio/webm;codecs=opus', 'audio/mp4', 'audio/webm', 'audio/ogg;codecs=opus'];\nconst neverResolvingPromise = () => new Promise(() => undefined);\nexport class VoiceRecorderImpl {\n constructor() {\n this.mediaRecorder = null;\n this.chunks = [];\n this.pendingResult = neverResolvingPromise();\n }\n static canDeviceVoiceRecord() {\n return _asyncToGenerator(function* () {\n var _a;\n if (((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) == null || VoiceRecorderImpl.getSupportedMimeType() == null) {\n return failureResponse();\n } else {\n return successResponse();\n }\n })();\n }\n startRecording() {\n var _this = this;\n return _asyncToGenerator(function* () {\n if (_this.mediaRecorder != null) {\n throw alreadyRecordingError();\n }\n const deviceCanRecord = yield VoiceRecorderImpl.canDeviceVoiceRecord();\n if (!deviceCanRecord.value) {\n throw deviceCannotVoiceRecordError();\n }\n const havingPermission = yield VoiceRecorderImpl.hasAudioRecordingPermission().catch(() => successResponse());\n if (!havingPermission.value) {\n throw missingPermissionError();\n }\n navigator.mediaDevices.getUserMedia({\n audio: true\n }).then(_this.onSuccessfullyStartedRecording.bind(_this)).catch(_this.onFailedToStartRecording.bind(_this));\n return successResponse();\n })();\n }\n stopRecording() {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n if (_this2.mediaRecorder == null) {\n throw recordingHasNotStartedError();\n }\n try {\n _this2.mediaRecorder.stop();\n _this2.mediaRecorder.stream.getTracks().forEach(track => track.stop());\n return _this2.pendingResult;\n } catch (ignore) {\n throw failedToFetchRecordingError();\n } finally {\n _this2.prepareInstanceForNextOperation();\n }\n })();\n }\n static hasAudioRecordingPermission() {\n return _asyncToGenerator(function* () {\n return navigator.permissions.query({\n name: 'microphone'\n }).then(result => ({\n value: result.state === 'granted'\n })).catch(() => {\n throw couldNotQueryPermissionStatusError();\n });\n })();\n }\n static requestAudioRecordingPermission() {\n return _asyncToGenerator(function* () {\n const havingPermission = yield VoiceRecorderImpl.hasAudioRecordingPermission().catch(() => failureResponse());\n if (havingPermission.value) {\n return successResponse();\n }\n return navigator.mediaDevices.getUserMedia({\n audio: true\n }).then(() => successResponse()).catch(() => failureResponse());\n })();\n }\n pauseRecording() {\n if (this.mediaRecorder == null) {\n throw recordingHasNotStartedError();\n } else if (this.mediaRecorder.state === 'recording') {\n this.mediaRecorder.pause();\n return Promise.resolve(successResponse());\n } else {\n return Promise.resolve(failureResponse());\n }\n }\n resumeRecording() {\n if (this.mediaRecorder == null) {\n throw recordingHasNotStartedError();\n } else if (this.mediaRecorder.state === 'paused') {\n this.mediaRecorder.resume();\n return Promise.resolve(successResponse());\n } els
|