audio-recorder-polyfill
Advanced tools
Comparing version 0.4.0 to 0.4.1
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 0.4.1 | ||
* Fix Safari playback icon (by @fjwong). | ||
## 0.4 | ||
@@ -5,0 +8,0 @@ * Add `sampleRate` option support (by @HuiGeGeGitHub). |
31
index.js
@@ -5,3 +5,3 @@ import waveEncoder from './wave-encoder/index.js' | ||
function createWorker (fn) { | ||
let createWorker = fn => { | ||
let js = fn | ||
@@ -15,3 +15,3 @@ .toString() | ||
function error (method) { | ||
let error = method => { | ||
let event = new Event('error') | ||
@@ -22,3 +22,3 @@ event.data = new Error('Wrong state for ' + method) | ||
let context, processor | ||
let context | ||
@@ -90,22 +90,14 @@ /** | ||
this.input = context.createMediaStreamSource(this.clone) | ||
this.processor = context.createScriptProcessor(2048, 1, 1) | ||
if (!processor) { | ||
processor = context.createScriptProcessor(2048, 1, 1) | ||
} | ||
this.encoder.postMessage(['init', context.sampleRate]) | ||
let recorder = this | ||
recorder.encoder.postMessage(['init', context.sampleRate]) | ||
processor.onaudioprocess = function (e) { | ||
if (recorder.state === 'recording') { | ||
recorder.encoder.postMessage([ | ||
'encode', | ||
e.inputBuffer.getChannelData(0) | ||
]) | ||
this.processor.onaudioprocess = e => { | ||
if (this.state === 'recording') { | ||
this.encoder.postMessage(['encode', e.inputBuffer.getChannelData(0)]) | ||
} | ||
} | ||
this.input.connect(processor) | ||
processor.connect(context.destination) | ||
this.input.connect(this.processor) | ||
this.processor.connect(context.destination) | ||
@@ -116,3 +108,3 @@ this.em.dispatchEvent(new Event('start')) | ||
this.slicing = setInterval(() => { | ||
if (recorder.state === 'recording') recorder.requestData() | ||
if (this.state === 'recording') this.requestData() | ||
}, timeslice) | ||
@@ -144,2 +136,3 @@ } | ||
}) | ||
this.processor.disconnect() | ||
this.input.disconnect() | ||
@@ -146,0 +139,0 @@ return clearInterval(this.slicing) |
{ | ||
"name": "audio-recorder-polyfill", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "MediaRecorder polyfill to record audio in Edge and Safari", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
30003
723