Skip to content

Commit

Permalink
Merge pull request #114 from chris-rudmin/mreinstein-master
Browse files Browse the repository at this point in the history
Mreinstein master
  • Loading branch information
chris-rudmin committed Dec 18, 2017
2 parents 074e610 + 42d0d93 commit a77705b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion dist/decoderWorker.min.js

Large diffs are not rendered by default.

Binary file modified dist/decoderWorker.min.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/encoderWorker.min.js

Large diffs are not rendered by default.

Binary file modified dist/encoderWorker.min.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/recorder.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "opus-recorder",
"version": "2.0.0",
"version": "2.0.1",
"description": "A library for recording opus encoded audio",
"homepage": "https://github.com/chris-rudmin/Recorderjs",
"homepage": "https://github.com/chris-rudmin/opus-recorder",
"author": "Chris Rudmin",
"keywords": [
"Ogg",
Expand Down Expand Up @@ -30,10 +30,10 @@
],
"repository": {
"type": "git",
"url": "git://github.com/chris-rudmin/Recorderjs.git"
"url": "git://github.com/chris-rudmin/opus-recorder.git"
},
"bugs": {
"url": "https://github.com/chris-rudmin/Recorderjs/issues",
"url": "https://github.com/chris-rudmin/opus-recorder/issues",
"email": "chris.rudmin@gmail.com"
},
"scripts": {
Expand All @@ -49,5 +49,8 @@
"sinon": "^2.4.1",
"sinon-chai": "^2.12.0",
"webpack": "^3.5.1"
},
"dependencies": {
"get-user-media-promise": "^1.1.1"
}
}
19 changes: 6 additions & 13 deletions src/recorder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use strict";

var getUserMedia = require("get-user-media-promise");


var Recorder = function( config ){

var that = this;
Expand Down Expand Up @@ -40,9 +43,7 @@ var Recorder = function( config ){
};

Recorder.isRecordingSupported = function(){
var AudioContext = global.AudioContext || global.webkitAudioContext;
var getUserMedia = global.navigator && ( global.navigator.getUserMedia || ( global.navigator.mediaDevices && global.navigator.mediaDevices.getUserMedia ) );
return AudioContext && getUserMedia;
return (global.AudioContext || global.webkitAudioContext) && getUserMedia.isSupported;
};

Recorder.prototype.addEventListener = function( type, listener, useCapture ){
Expand Down Expand Up @@ -104,15 +105,7 @@ Recorder.prototype.initStream = function(){
return global.Promise.resolve( this.stream );
}

if ( global.navigator.mediaDevices && global.navigator.mediaDevices.getUserMedia ) {
return global.navigator.mediaDevices.getUserMedia( constraints ).then( onStreamInit, onStreamError );
}

if ( global.navigator.getUserMedia ) {
return new global.Promise( function( resolve, reject ) {
global.navigator.getUserMedia( constraints, resolve, reject );
}).then( onStreamInit, onStreamError );
}
return getUserMedia(constraints).then( onStreamInit, onStreamError );
};

Recorder.prototype.pause = function(){
Expand All @@ -134,7 +127,7 @@ Recorder.prototype.resume = function() {
};

Recorder.prototype.setMonitorGain = function( gain ){
this.monitorNode.gain.value = gain;
this.monitorNode.gain.setTargetAtTime(gain, this.audioContext.currentTime, 0.01);
};

Recorder.prototype.start = function(){
Expand Down
22 changes: 18 additions & 4 deletions test/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ describe('Recorder unsupported', function(){
describe('Recorder', function(){

var sandbox = sinon.sandbox.create();
var Recorder = requireUncached('../dist/recorder.min');
var Recorder;

beforeEach(function(){
global.AudioContext = sandbox.stub();
global.AudioContext.prototype.createGain = sandbox.stub().returns({
connect: sandbox.stub(),
gain: {}
gain: {
setTargetAtTime: sandbox.stub()
}
});
global.AudioContext.prototype.createScriptProcessor = sandbox.stub().returns({
connect: sandbox.stub()
Expand Down Expand Up @@ -64,14 +66,18 @@ describe('Recorder', function(){
global.Worker.prototype.postMessage = sandbox.stub();

global.Promise = Promise;

Recorder = requireUncached('../dist/recorder.min');
});

var mockWebkit = function(){
delete global.AudioContext;
global.webkitAudioContext = sandbox.stub();
global.webkitAudioContext.prototype.createGain = sandbox.stub().returns({
connect: sandbox.stub(),
gain: {}
gain: {
setTargetAtTime: sandbox.stub()
}
});
global.webkitAudioContext.prototype.createScriptProcessor = sandbox.stub().returns({
connect: sandbox.stub()
Expand Down Expand Up @@ -192,6 +198,7 @@ describe('Recorder', function(){
global.navigator.getUserMedia = sandbox.stub().yields({
stop: sandbox.stub()
});
Recorder = requireUncached('../dist/recorder.min');

var rec = new Recorder();
return rec.initStream().then(function(){
Expand Down Expand Up @@ -284,5 +291,12 @@ describe('Recorder', function(){
expect(ev).instanceof(Error);
expect(ev.message).to.equal('PermissionDeniedError')
})
})
});

it('should set monitoring gain on init', function () {
var rec = new Recorder();
return rec.initStream().then(function(){
expect(rec.monitorNode.gain.setTargetAtTime).to.have.been.calledOnce;
});
});
});

0 comments on commit a77705b

Please sign in to comment.