Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions lib/twilio/audiohelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp: steamd -> stream

* @param stream - A media stream to use as input
* @param device - A device to use as input
*/
setInputStream(stream: MediaStream, device: MediaDeviceInfo | null): Promise<void> {
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,
Expand Down Expand Up @@ -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<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we could nix the private method and put this logic in the public setInputStream, and call that above instead?

return this._onActiveInputChanged(stream).then(() => {
this._replaceStream(stream);
this._inputDevice = device;
this._maybeStartPollingVolume();
});
}

/**
* Update the available input and output devices
*/
Expand Down