Skip to content

Commit

Permalink
chore(audio): audio contraints
Browse files Browse the repository at this point in the history
  • Loading branch information
molimauro committed Sep 21, 2021
1 parent 570076d commit 3afc338
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
39 changes: 15 additions & 24 deletions components/tailored/settings/pages/audio/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default Vue.extend({
isBitrate: {
set(state) {
this.$store.commit('bitrate', state)
this.setConstraint('bitrate', state)
this.setConstraint('sampleRate', state)
},
get() {
return this.settings.bitrate
Expand Down Expand Up @@ -232,33 +232,24 @@ export default Vue.extend({
inputVolumeControlValueChange(volume: number) {
this.$store.commit('setInputVolume', volume)
},
hasConstraint(prop: string): Boolean {
const supports = navigator.mediaDevices.getSupportedConstraints() as {
[key: string]: Boolean
}
return supports[prop]
hasConstraint(prop: keyof MediaTrackConstraintSet): Boolean {
const supports = navigator.mediaDevices.getSupportedConstraints()
return Boolean(supports[prop])
},
setConstraint(prop: string, value: any) {
if (this.hasConstraint(prop)) {
setConstraint(prop: keyof MediaTrackConstraintSet, value: any) {
// hasConstraint is true only if the prop is supported by the browser
if (!this.hasConstraint(prop)) {
return
}
if (this.$data.userHasGivenAudioAccess) {
const track = this.$data.track as MediaStreamTrack
const constraints = track.getConstraints() as { [key: string]: any }
constraints[prop] = value
track.applyConstraints(constraints)
if (this.$data.userHasGivenAudioAccess && this.$data.stream) {
this.$data.stream
.getAudioTracks()
.forEach(function (track: MediaStreamTrack) {
const constraints = track.getConstraints()
constraints[prop] = value
track.applyConstraints(constraints)
})
}
// navigator.mediaDevices
// .getUserMedia({ video: false, audio: true })
// .then(function (stream: MediaStream) {
// const track = stream.getAudioTracks()[0]
// const constraints = track.getConstraints() as { [key: string]: any }
// constraints[prop] = value
// track.applyConstraints(constraints)
// })
// .catch((error) => {
// console.log(error)
// })
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion store/audio/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const mutations = {
state.audio = {
...state.audio,
previousVolume: volume,
volume
volume,
}
},
setInputVolume(state: NuxtState, inputVolume: Number) {
Expand Down

0 comments on commit 3afc338

Please sign in to comment.