diff --git a/src/page/components/media.vue b/src/page/components/media.vue index 0b1b0f2e..f39d5071 100644 --- a/src/page/components/media.vue +++ b/src/page/components/media.vue @@ -1,20 +1,40 @@ @@ -32,21 +52,40 @@ @Ref('audio') readonly _audio!: HTMLAudioElement @Ref('video') readonly _video!: HTMLVideoElement + private audioDevice: string = '' + private audioDevices: MediaDeviceInfo[] = [] + private micTracks: MediaStreamTrack[] = [] private micSenders: RTCRtpSender[] = [] + private videoDevice: string = '' + private videoDevices: MediaDeviceInfo[] = [] + private camTracks: MediaStreamTrack[] = [] private camSenders: RTCRtpSender[] = [] - //private devices: any[] = [] + mounted() { + this.loadAudioDevices() + this.loadVideoDevices() + } + + async loadAudioDevices() { + let devices = await navigator.mediaDevices.enumerateDevices() + this.audioDevices = devices.filter((device) => device.kind === 'audioinput') + console.log('audioDevices', this.audioDevices) + } async addMicrophone() { this.micTracks = [] this.micSenders = [] try { - const stream = await navigator.mediaDevices.getUserMedia({ video: false, audio: true }) + let audio = { echoCancellation: true } as MediaTrackConstraints + if (this.audioDevice != '') { + audio.deviceId = this.audioDevice + } + const stream = await navigator.mediaDevices.getUserMedia({ video: false, audio }) this._audio.srcObject = stream console.log('Got MediaStream:', stream) @@ -85,19 +124,26 @@ this.micSenders = [] } + async loadVideoDevices() { + let devices = await navigator.mediaDevices.enumerateDevices() + this.videoDevices = devices.filter((device) => device.kind === 'videoinput') + console.log('videoDevices', this.videoDevices) + } + async addWebcam() { this.camTracks = [] this.camSenders = [] try { - const stream = await navigator.mediaDevices.getUserMedia({ - video: { - width: 1280, - height: 720, - }, - audio: false, - }) + let video = { + width: 1280, + height: 720, + } as MediaTrackConstraints + if (this.videoDevice != '') { + video.deviceId = this.videoDevice + } + const stream = await navigator.mediaDevices.getUserMedia({ video, audio: false }) this._video.srcObject = stream console.log('Got MediaStream:', stream) @@ -135,11 +181,5 @@ this.camTracks = [] this.camSenders = [] } - - /*async getDevices() { - const devices = await navigator.mediaDevices.enumerateDevices(); - this.devices = devices.map(({ kind, label, deviceId }) => ({ kind, label, deviceId })) - console.log(this.devices) - }*/ }