diff --git a/lib/twilio/audiohelper.ts b/lib/twilio/audiohelper.ts index 843c9abf..467de586 100644 --- a/lib/twilio/audiohelper.ts +++ b/lib/twilio/audiohelper.ts @@ -317,6 +317,15 @@ class AudioHelper extends EventEmitter { 'Related BugZilla thread: https://bugzilla.mozilla.org/show_bug.cgi?id=1299324')); } + /** + * Replace the current input steamd with a new MediaStream. + * @param stream - A media stream to use as input + * @param device - A device to use as input + */ + setInputStream(stream: MediaStream, device: MediaDeviceInfo | null): Promise { + return this._setInputStream(stream, device); + } + /** * Unset the MediaTrackConstraints to be applied on every getUserMedia call for new input * device audio. The returned Promise resolves when the media is successfully reacquired, @@ -487,14 +496,23 @@ class AudioHelper extends EventEmitter { const constraints = { audio: Object.assign({ deviceId: { exact: deviceId } }, this.audioConstraints) }; return this._getUserMedia(constraints).then((stream: MediaStream) => { - return this._onActiveInputChanged(stream).then(() => { - this._replaceStream(stream); - this._inputDevice = device; - this._maybeStartPollingVolume(); - }); + return this._setInputStream(stream, device); }); } + /** + * Replace the current input steamd with a new MediaStream. + * @param stream - A media stream to use as input + * @param device - A device to use as input + */ + private _setInputStream(stream: MediaStream, device: MediaDeviceInfo | null): Promise { + return this._onActiveInputChanged(stream).then(() => { + this._replaceStream(stream); + this._inputDevice = device; + this._maybeStartPollingVolume(); + }); + } + /** * Update the available input and output devices */