@uppy/audio
Advanced tools
Comparing version 1.1.1 to 1.1.2
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
var id = 0; | ||
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } | ||
function isFunction(v) { | ||
return typeof v === 'function'; | ||
} | ||
function result(v) { | ||
return isFunction(v) ? v() : v; | ||
} | ||
/* Audio Oscilloscope | ||
https://github.com/miguelmota/audio-oscilloscope | ||
*/ | ||
var _draw = /*#__PURE__*/_classPrivateFieldLooseKey("draw"); | ||
export default class AudioOscilloscope { | ||
@@ -26,3 +20,2 @@ constructor(canvas, options) { | ||
} | ||
Object.defineProperty(this, _draw, { | ||
@@ -48,3 +41,2 @@ writable: true, | ||
} | ||
addSource(streamSource) { | ||
@@ -61,3 +53,2 @@ this.streamSource = streamSource; | ||
} | ||
draw() { | ||
@@ -72,7 +63,5 @@ const { | ||
const h = this.height; | ||
if (analyser) { | ||
analyser.getByteTimeDomainData(dataArray); | ||
} | ||
ctx.fillRect(0, 0, w, h); | ||
@@ -82,11 +71,8 @@ ctx.beginPath(); | ||
let x = 0; | ||
if (!bufferLength) { | ||
ctx.moveTo(0, this.height / 2); | ||
} | ||
for (let i = 0; i < bufferLength; i++) { | ||
const v = dataArray[i] / 128.0; | ||
const y = v * (h / 2); | ||
if (i === 0) { | ||
@@ -97,6 +83,4 @@ ctx.moveTo(x, y); | ||
} | ||
x += sliceWidth; | ||
} | ||
ctx.lineTo(w, h / 2); | ||
@@ -107,3 +91,2 @@ ctx.stroke(); | ||
} | ||
} |
102
lib/Audio.js
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
var id = 0; | ||
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } | ||
import { h } from 'preact'; | ||
@@ -17,3 +13,3 @@ import { UIPlugin } from '@uppy/core'; | ||
const packageJson = { | ||
"version": "1.1.1" | ||
"version": "1.1.2" | ||
}; | ||
@@ -23,41 +19,22 @@ /** | ||
*/ | ||
var _stream = /*#__PURE__*/_classPrivateFieldLooseKey("stream"); | ||
var _audioActive = /*#__PURE__*/_classPrivateFieldLooseKey("audioActive"); | ||
var _recordingChunks = /*#__PURE__*/_classPrivateFieldLooseKey("recordingChunks"); | ||
var _recorder = /*#__PURE__*/_classPrivateFieldLooseKey("recorder"); | ||
var _capturedMediaFile = /*#__PURE__*/_classPrivateFieldLooseKey("capturedMediaFile"); | ||
var _mediaDevices = /*#__PURE__*/_classPrivateFieldLooseKey("mediaDevices"); | ||
var _supportsUserMedia = /*#__PURE__*/_classPrivateFieldLooseKey("supportsUserMedia"); | ||
var _hasAudioCheck = /*#__PURE__*/_classPrivateFieldLooseKey("hasAudioCheck"); | ||
var _start = /*#__PURE__*/_classPrivateFieldLooseKey("start"); | ||
var _startRecording = /*#__PURE__*/_classPrivateFieldLooseKey("startRecording"); | ||
var _stopRecording = /*#__PURE__*/_classPrivateFieldLooseKey("stopRecording"); | ||
var _discardRecordedAudio = /*#__PURE__*/_classPrivateFieldLooseKey("discardRecordedAudio"); | ||
var _submit = /*#__PURE__*/_classPrivateFieldLooseKey("submit"); | ||
var _stop = /*#__PURE__*/_classPrivateFieldLooseKey("stop"); | ||
var _getAudio = /*#__PURE__*/_classPrivateFieldLooseKey("getAudio"); | ||
var _changeSource = /*#__PURE__*/_classPrivateFieldLooseKey("changeSource"); | ||
var _updateSources = /*#__PURE__*/_classPrivateFieldLooseKey("updateSources"); | ||
export default class Audio extends UIPlugin { | ||
constructor(uppy, opts) { | ||
var _this; | ||
super(uppy, opts); | ||
@@ -99,2 +76,3 @@ _this = this; | ||
}); | ||
// eslint-disable-next-line consistent-return | ||
Object.defineProperty(this, _start, { | ||
@@ -106,15 +84,12 @@ writable: true, | ||
} | ||
if (!_classPrivateFieldLooseBase(_this, _supportsUserMedia)[_supportsUserMedia]) { | ||
return Promise.reject(new Error('Microphone access not supported')); | ||
} | ||
_classPrivateFieldLooseBase(_this, _audioActive)[_audioActive] = true; | ||
_classPrivateFieldLooseBase(_this, _hasAudioCheck)[_hasAudioCheck]().then(hasAudio => { | ||
_this.setPluginState({ | ||
hasAudio | ||
}); // ask user for access to their camera | ||
}); | ||
// ask user for access to their camera | ||
return _classPrivateFieldLooseBase(_this, _mediaDevices)[_mediaDevices].getUserMedia({ | ||
@@ -126,3 +101,2 @@ audio: true | ||
const tracks = stream.getAudioTracks(); | ||
if (!options || !options.deviceId) { | ||
@@ -136,7 +110,6 @@ currentDeviceId = tracks[0].getSettings().deviceId; | ||
}); | ||
} // Update the sources now, so we can access the names. | ||
} | ||
// Update the sources now, so we can access the names. | ||
_classPrivateFieldLooseBase(_this, _updateSources)[_updateSources](); | ||
_this.setPluginState({ | ||
@@ -151,3 +124,2 @@ currentDeviceId, | ||
}); | ||
_this.uppy.info(err.message, 'error'); | ||
@@ -166,32 +138,26 @@ }); | ||
let stoppingBecauseOfMaxSize = false; | ||
_classPrivateFieldLooseBase(this, _recorder)[_recorder].addEventListener('dataavailable', event => { | ||
_classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks].push(event.data); | ||
const { | ||
restrictions | ||
} = this.uppy.opts; | ||
if (_classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks].length > 1 && restrictions.maxFileSize != null && !stoppingBecauseOfMaxSize) { | ||
const totalSize = _classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks].reduce((acc, chunk) => acc + chunk.size, 0); // Exclude the initial chunk from the average size calculation because it is likely to be a very small outlier | ||
const totalSize = _classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks].reduce((acc, chunk) => acc + chunk.size, 0); | ||
// Exclude the initial chunk from the average size calculation because it is likely to be a very small outlier | ||
const averageChunkSize = (totalSize - _classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks][0].size) / (_classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks].length - 1); | ||
const expectedEndChunkSize = averageChunkSize * 3; | ||
const maxSize = Math.max(0, restrictions.maxFileSize - expectedEndChunkSize); | ||
if (totalSize > maxSize) { | ||
stoppingBecauseOfMaxSize = true; | ||
this.uppy.info(this.i18n('recordingStoppedMaxSize'), 'warning', 4000); | ||
_classPrivateFieldLooseBase(this, _stopRecording)[_stopRecording](); | ||
} | ||
} | ||
}); // use a "time slice" of 500ms: ondataavailable will be called each 500ms | ||
}); | ||
// use a "time slice" of 500ms: ondataavailable will be called each 500ms | ||
// smaller time slices mean we can more accurately check the max file size restriction | ||
_classPrivateFieldLooseBase(this, _recorder)[_recorder].start(500); | ||
_classPrivateFieldLooseBase(this, _recorder)[_recorder].start(500); // Start the recordingLengthTimer if we are showing the recording length. | ||
// Start the recordingLengthTimer if we are showing the recording length. | ||
this.recordingLengthTimer = setInterval(() => { | ||
@@ -215,5 +181,3 @@ const currentRecordingLength = this.getPluginState().recordingLengthSeconds; | ||
}); | ||
_classPrivateFieldLooseBase(this, _recorder)[_recorder].stop(); | ||
clearInterval(this.recordingLengthTimer); | ||
@@ -231,4 +195,4 @@ this.setPluginState({ | ||
try { | ||
_classPrivateFieldLooseBase(this, _capturedMediaFile)[_capturedMediaFile] = file; // create object url for capture result preview | ||
_classPrivateFieldLooseBase(this, _capturedMediaFile)[_capturedMediaFile] = file; | ||
// create object url for capture result preview | ||
this.setPluginState({ | ||
@@ -282,6 +246,4 @@ recordedAudio: URL.createObjectURL(file.data) | ||
const audioTracks = _classPrivateFieldLooseBase(this, _stream)[_stream].getAudioTracks(); | ||
audioTracks.forEach(track => track.stop()); | ||
} | ||
if (_classPrivateFieldLooseBase(this, _recorder)[_recorder]) { | ||
@@ -292,9 +254,6 @@ await new Promise(resolve => { | ||
}); | ||
_classPrivateFieldLooseBase(this, _recorder)[_recorder].stop(); | ||
clearInterval(this.recordingLengthTimer); | ||
}); | ||
} | ||
_classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks] = null; | ||
@@ -315,3 +274,2 @@ _classPrivateFieldLooseBase(this, _recorder)[_recorder] = null; | ||
_classPrivateFieldLooseBase(this, _stop)[_stop](); | ||
_classPrivateFieldLooseBase(this, _start)[_start]({ | ||
@@ -336,3 +294,2 @@ deviceId | ||
this.type = 'acquirer'; | ||
this.icon = () => h("svg", { | ||
@@ -350,5 +307,5 @@ className: "uppy-DashboardTab-iconAudio", | ||
})); | ||
this.defaultLocale = locale; | ||
this.opts = { ...opts | ||
this.opts = { | ||
...opts | ||
}; | ||
@@ -366,3 +323,2 @@ this.i18nInit(); | ||
} | ||
render() { | ||
@@ -372,5 +328,3 @@ if (!_classPrivateFieldLooseBase(this, _audioActive)[_audioActive]) { | ||
} | ||
const audioState = this.getPluginState(); | ||
if (!audioState.audioReady || !audioState.hasAudio) { | ||
@@ -383,4 +337,4 @@ return h(PermissionsScreen, { | ||
} | ||
return h(RecordingScreen // eslint-disable-next-line react/jsx-props-no-spreading | ||
return h(RecordingScreen | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
, _extends({}, audioState, { | ||
@@ -401,3 +355,2 @@ audioActive: _classPrivateFieldLooseBase(this, _audioActive)[_audioActive], | ||
} | ||
install() { | ||
@@ -411,13 +364,9 @@ this.setPluginState({ | ||
} = this.opts; | ||
if (target) { | ||
this.mount(target, this); | ||
} | ||
if (_classPrivateFieldLooseBase(this, _mediaDevices)[_mediaDevices]) { | ||
_classPrivateFieldLooseBase(this, _updateSources)[_updateSources](); | ||
_classPrivateFieldLooseBase(this, _mediaDevices)[_mediaDevices].ondevicechange = () => { | ||
_classPrivateFieldLooseBase(this, _updateSources)[_updateSources](); | ||
if (_classPrivateFieldLooseBase(this, _stream)[_stream]) { | ||
@@ -434,6 +383,4 @@ let restartStream = true; | ||
}); | ||
if (restartStream) { | ||
_classPrivateFieldLooseBase(this, _stop)[_stop](); | ||
_classPrivateFieldLooseBase(this, _start)[_start](); | ||
@@ -445,3 +392,2 @@ } | ||
} | ||
uninstall() { | ||
@@ -451,8 +397,5 @@ if (_classPrivateFieldLooseBase(this, _stream)[_stream]) { | ||
} | ||
this.unmount(); | ||
} | ||
} | ||
function _hasAudioCheck2() { | ||
@@ -462,3 +405,2 @@ if (!_classPrivateFieldLooseBase(this, _mediaDevices)[_mediaDevices]) { | ||
} | ||
return _classPrivateFieldLooseBase(this, _mediaDevices)[_mediaDevices].enumerateDevices().then(devices => { | ||
@@ -468,3 +410,2 @@ return devices.some(device => device.kind === 'audioinput'); | ||
} | ||
function _getAudio2() { | ||
@@ -476,12 +417,8 @@ // Sometimes in iOS Safari, Blobs (especially the first Blob in the recordingChunks Array) | ||
var _blob$type; | ||
return ((_blob$type = blob.type) == null ? void 0 : _blob$type.length) > 0; | ||
}).type; | ||
const fileExtension = getFileTypeExtension(mimeType); | ||
if (!fileExtension) { | ||
return Promise.reject(new Error(`Could not retrieve recording: Unsupported media type "${mimeType}"`)); | ||
} | ||
const name = `audio-${Date.now()}.${fileExtension}`; | ||
@@ -501,3 +438,2 @@ const blob = new Blob(_classPrivateFieldLooseBase(this, _recordingChunks)[_recordingChunks], { | ||
} | ||
Audio.VERSION = packageJson.version; |
import { h } from 'preact'; | ||
function DiscardButton(_ref) { | ||
@@ -31,3 +30,2 @@ let { | ||
} | ||
export default DiscardButton; |
@@ -9,3 +9,2 @@ import { h } from 'preact'; | ||
} = _ref; | ||
if (recording) { | ||
@@ -33,3 +32,2 @@ return h("button", { | ||
} | ||
return h("button", { | ||
@@ -36,0 +34,0 @@ className: "uppy-u-reset uppy-c-btn uppy-Audio-button", |
@@ -27,4 +27,5 @@ /* eslint-disable jsx-a11y/media-has-caption */ | ||
const canvasEl = useRef(null); | ||
const oscilloscope = useRef(null); // componentDidMount / componentDidUnmount | ||
const oscilloscope = useRef(null); | ||
// componentDidMount / componentDidUnmount | ||
useEffect(() => { | ||
@@ -35,4 +36,5 @@ return () => { | ||
}; | ||
}, [onStop]); // componentDidUpdate | ||
}, [onStop]); | ||
// componentDidUpdate | ||
useEffect(() => { | ||
@@ -52,3 +54,2 @@ if (!recordedAudio) { | ||
oscilloscope.current.draw(); | ||
if (stream) { | ||
@@ -55,0 +56,0 @@ const audioContext = new AudioContext(); |
import { h } from 'preact'; | ||
function SubmitButton(_ref) { | ||
@@ -29,3 +28,2 @@ let { | ||
} | ||
export default SubmitButton; |
export default function supportsMediaRecorder() { | ||
var _MediaRecorder$protot; | ||
/* eslint-disable compat/compat */ | ||
@@ -5,0 +4,0 @@ return typeof MediaRecorder === 'function' && typeof ((_MediaRecorder$protot = MediaRecorder.prototype) == null ? void 0 : _MediaRecorder$protot.start) === 'function'; |
{ | ||
"name": "@uppy/audio", | ||
"description": "Uppy plugin that records audio using the device’s microphone.", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"license": "MIT", | ||
@@ -29,3 +29,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "^5.3.0", | ||
"@uppy/utils": "^5.4.3", | ||
"preact": "^10.5.13" | ||
@@ -37,3 +37,3 @@ }, | ||
"peerDependencies": { | ||
"@uppy/core": "^3.2.0" | ||
"@uppy/core": "^3.4.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "publishConfig": { |
@@ -1,5 +0,5 @@ | ||
import type { PluginOptions, UIPlugin, PluginTarget } from '@uppy/core' | ||
import type { PluginTarget, UIPlugin, UIPluginOptions } from '@uppy/core' | ||
import type AudioLocale from './generatedLocale' | ||
export interface AudioOptions extends PluginOptions { | ||
export interface AudioOptions extends UIPluginOptions { | ||
target?: PluginTarget | ||
@@ -6,0 +6,0 @@ showAudioSourceDropdown?: boolean |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124682
1679
Updated@uppy/utils@^5.4.3