Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

audio-recorder-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

audio-recorder-polyfill - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

3

CHANGELOG.md
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 0.1.3
* Fix compatibility by adding `error` event (by Tom Quirk).
## 0.1.2

@@ -5,0 +8,0 @@ * Reuse Audio Context (by Ambrose Chua).

92

index.js

@@ -12,2 +12,8 @@ var AudioContext = window.AudioContext || window.webkitAudioContext

function error (method) {
var event = new Event('error')
event.data = new Error('Wrong state for ' + method)
return event
}
var context

@@ -76,31 +82,35 @@

start: function start (timeslice) {
if (this.state === 'inactive') {
this.state = 'recording'
if (this.state !== 'inactive') {
return this.em.dispatchEvent(error('start'))
}
if (!context) {
context = new AudioContext()
}
var input = context.createMediaStreamSource(this.stream)
var processor = context.createScriptProcessor(2048, 1, 1)
this.state = 'recording'
var recorder = this
processor.onaudioprocess = function (e) {
if (recorder.state === 'recording') {
recorder.encoder.postMessage([
'encode', e.inputBuffer.getChannelData(0)
])
}
if (!context) {
context = new AudioContext()
}
var input = context.createMediaStreamSource(this.stream)
var processor = context.createScriptProcessor(2048, 1, 1)
var recorder = this
processor.onaudioprocess = function (e) {
if (recorder.state === 'recording') {
recorder.encoder.postMessage([
'encode', e.inputBuffer.getChannelData(0)
])
}
}
input.connect(processor)
processor.connect(context.destination)
input.connect(processor)
processor.connect(context.destination)
this.em.dispatchEvent(new Event('start'))
this.em.dispatchEvent(new Event('start'))
if (timeslice) {
this.slicing = setInterval(function () {
if (recorder.state === 'recording') recorder.requestData()
}, timeslice)
}
if (timeslice) {
this.slicing = setInterval(function () {
if (recorder.state === 'recording') recorder.requestData()
}, timeslice)
}
return undefined
},

@@ -119,7 +129,9 @@

stop: function stop () {
if (this.state !== 'inactive') {
this.requestData()
this.state = 'inactive'
clearInterval(this.slicing)
if (this.state === 'inactive') {
return this.em.dispatchEvent(error('stop'))
}
this.requestData()
this.state = 'inactive'
return clearInterval(this.slicing)
},

@@ -138,6 +150,8 @@

pause: function pause () {
if (this.state === 'recording') {
this.state = 'paused'
this.em.dispatchEvent(new Event('pause'))
if (this.state !== 'recording') {
return this.em.dispatchEvent(error('pause'))
}
this.state = 'paused'
return this.em.dispatchEvent(new Event('pause'))
},

@@ -156,6 +170,8 @@

resume: function resume () {
if (this.state === 'paused') {
this.state = 'recording'
this.em.dispatchEvent(new Event('resume'))
if (this.state !== 'paused') {
return this.em.dispatchEvent(error('resume'))
}
this.state = 'recording'
return this.em.dispatchEvent(new Event('resume'))
},

@@ -174,5 +190,7 @@

requestData: function requestData () {
if (this.state !== 'inactive') {
this.encoder.postMessage(['dump', context.sampleRate])
if (this.state === 'inactive') {
return this.em.dispatchEvent(error('requestData'))
}
return this.encoder.postMessage(['dump', context.sampleRate])
},

@@ -183,3 +201,4 @@

*
* @param {"start"|"stop"|"pause"|"resume"|"dataavailable"} type Event type.
* @param {"start"|"stop"|"pause"|"resume"|"dataavailable"|"error"}
* type Event type.
* @param {function} listener The listener function.

@@ -201,3 +220,4 @@ *

*
* @param {"start"|"stop"|"pause"|"resume"|"dataavailable"} type Event type.
* @param {"start"|"stop"|"pause"|"resume"|"dataavailable"|"error"}
* type Event type.
* @param {function} listener The same function used in `addEventListener`.

@@ -204,0 +224,0 @@ *

{
"name": "audio-recorder-polyfill",
"version": "0.1.2",
"version": "0.1.3",
"description": "MediaRecorder polyfill to record audio in Edge and Safari",

@@ -19,52 +19,3 @@ "keywords": [

"license": "MIT",
"repository": "ai/audio-recorder-polyfill",
"devDependencies": {
"bytes": "^3.0.0",
"copy-webpack-plugin": "^4.5.1",
"docdash": "^0.4.0",
"eslint": "^4.19.1",
"eslint-config-logux": "^23.0.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-es5": "^1.3.1",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^3.1.0",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^3.2.0",
"jest": "^23.1.0",
"jsdoc": "^3.5.5",
"lint-staged": "^7.2.0",
"nanodelay": "^0.1.3",
"pre-commit": "^1.2.2",
"rimraf": "^2.6.2",
"size-limit": "^0.18.2",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4",
"yaspeller-ci": "^1.0.0"
},
"scripts": {
"lint-staged": "lint-staged",
"spell": "yarn api && yaspeller-ci *.md api/*.html",
"clean": "rimraf api/ coverage/ test/demo/build/",
"lint": "eslint *.js test/{**/,}*.js",
"api": "jsdoc --configure .jsdocrc *.js",
"unit": "jest --coverage",
"test": "yarn unit && yarn lint && size-limit && yarn spell && yarn build",
"start": "webpack-dev-server --config test/demo/webpack.config",
"build": "webpack --mode production --config test/demo/webpack.config"
},
"jest": {
"coverageThreshold": {
"global": {
"statements": 100
}
}
},
"pre-commit": [
"lint-staged"
]
"repository": "ai/audio-recorder-polyfill"
}

@@ -12,3 +12,3 @@ # Audio Recorder Polyfill

MediaRecorder, you will just remove polyfill.
* **Small.** Less than 1 KB (minified and gzipped). No dependencies.
* **Small.** 1 KB (minified and gzipped). No dependencies.
It uses [Size Limit] to control size.

@@ -15,0 +15,0 @@ * **One file.** In contrast to other recorders, this polyfill uses

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc