diff --git a/react/features/local-recording/recording/WavAdapter.js b/react/features/local-recording/recording/WavAdapter.js index 1ebebcd8d..8eaababb7 100644 --- a/react/features/local-recording/recording/WavAdapter.js +++ b/react/features/local-recording/recording/WavAdapter.js @@ -139,6 +139,43 @@ export class WavAdapter extends RecordingAdapter { return Promise.resolve(); } + /** + * Implements {@link RecordingAdapter#setMicDevice()}. + * + * @inheritdoc + */ + setMicDevice(micDeviceId) { + return this._replaceMic(micDeviceId); + } + + /** + * Replaces the current microphone MediaStream. + * + * @param {*} micDeviceId - New microphone ID. + * @returns {Promise} + */ + _replaceMic(micDeviceId) { + if (this._audioContext && this._audioProcessingNode) { + return new Promise((resolve, reject) => { + this._getAudioStream(micDeviceId).then(newStream => { + const newSource = this._audioContext + .createMediaStreamSource(newStream); + + this._audioSource.disconnect(); + newSource.connect(this._audioProcessingNode); + this._stream = newStream; + this._audioSource = newSource; + resolve(); + }) + .catch(() => { + reject(); + }); + }); + } + + return Promise.resolve(); + } + /** * Creates a WAVE file header. * @@ -209,7 +246,9 @@ export class WavAdapter extends RecordingAdapter { this._getAudioStream(micDeviceId) .then(stream => { this._stream = stream; - this._audioContext = new AudioContext(); + this._audioContext = new AudioContext({ + sampleRate: WAV_SAMPLE_RATE + }); this._audioSource = this._audioContext.createMediaStreamSource(stream); this._audioProcessingNode @@ -255,7 +294,7 @@ export class WavAdapter extends RecordingAdapter { * * @private * @param {*} buffers - The stored buffers. - * @param {*} length - Total length (in bytes). + * @param {*} length - Total length (number of samples). * @returns {Blob} */ _exportMonoWAV(buffers, length) { @@ -265,7 +304,7 @@ export class WavAdapter extends RecordingAdapter { // ... // buffers[n] = Float32Array object (audio data) - const dataLength = length * 2; // why multiply by 2 here? + const dataLength = length * 2; // each sample = 16 bit = 2 bytes const buffer = new ArrayBuffer(44 + dataLength); const view = new DataView(buffer); diff --git a/react/features/local-recording/recording/flac/FlacAdapter.js b/react/features/local-recording/recording/flac/FlacAdapter.js index e4a9ec825..716c6d6f3 100644 --- a/react/features/local-recording/recording/flac/FlacAdapter.js +++ b/react/features/local-recording/recording/flac/FlacAdapter.js @@ -16,10 +16,29 @@ const logger = require('jitsi-meet-logger').getLogger(__filename); */ export class FlacAdapter extends RecordingAdapter { + /** + * Instance of flacEncodeWorker. + */ _encoder = null; + + /** + * The {@code AudioContext} instance. + */ _audioContext = null; + + /** + * The {@code ScriptProcessorNode} instance. + */ _audioProcessingNode = null; + + /** + * The {@code MediaStreamAudioSourceNode} instance. + */ _audioSource = null; + + /** + * The {@code MediaStream} instance, representing the current audio device. + */ _stream = null; /** @@ -206,7 +225,9 @@ export class FlacAdapter extends RecordingAdapter { this._getAudioStream(micDeviceId) .then(stream => { this._stream = stream; - this._audioContext = new AudioContext(); + this._audioContext = new AudioContext({ + sampleRate: 44100 + }); this._audioSource = this._audioContext.createMediaStreamSource(stream); this._audioProcessingNode