From 57c17b50ef8ebb794789231b57103abf77baee32 Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Fri, 3 Jun 2022 11:34:39 +0200 Subject: [PATCH] openvidu-components: Fixed missing device labels in Firefox --- .../components/pre-join/pre-join.component.ts | 20 ----------------- .../videoconference.component.ts | 22 ++++++++++++++++++- .../src/lib/services/device/device.service.ts | 2 ++ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts index 6eb4d5a0..cbdfde7c 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts @@ -217,24 +217,4 @@ export class PreJoinComponent implements OnInit, OnDestroy { // this.cd.markForCheck(); }); } - - //? After test in Chrome and Firefox, the devices always have labels. - //? It's not longer needed - // private handlePublisherSuccess(publisher: Publisher) { - // publisher.once('accessAllowed', async () => { - // if (this.deviceSrv.areEmptyLabels()) { - // await this.deviceSrv.forceUpdate(); - // if (this.hasAudioDevices) { - // const audioLabel = publisher?.stream?.getMediaStream()?.getAudioTracks()[0]?.label; - // this.deviceSrv.setMicSelected(audioLabel); - // } - - // if (this.hasVideoDevices) { - // const videoLabel = publisher?.stream?.getMediaStream()?.getVideoTracks()[0]?.label; - // this.deviceSrv.setCameraSelected(videoLabel); - // } - // this.setDevicesInfo(); - // } - // }); - // } } diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts index 9577c8cc..3fb50f65 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts @@ -451,7 +451,10 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni const publisher = await this.openviduService.initDefaultPublisher(undefined); if (publisher) { publisher.once('accessDenied', (e: any) => this.handlePublisherError(e)); - publisher.once('accessAllowed', () => (this.participantReady = true)); + publisher.once('accessAllowed', async () => { + await this.handlePublisherSuccess(); + this.participantReady = true; + }); publisher.once('streamPlaying', () => (this.streamPlaying = true)); } } catch (error) { @@ -681,6 +684,23 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni this.log.e(e.message); } + private async handlePublisherSuccess() { + // The devices are initialized without labels in Firefox. + // We need to force an update after publisher is allowed. + if (this.deviceSrv.areEmptyLabels()) { + await this.deviceSrv.forceUpdate(); + if (this.deviceSrv.hasAudioDeviceAvailable()) { + const audioLabel = this.participantService.getMyCameraPublisher()?.stream?.getMediaStream()?.getAudioTracks()[0]?.label; + this.deviceSrv.setMicSelected(audioLabel); + } + + if (this.deviceSrv.hasVideoDeviceAvailable()) { + const videoLabel = this.participantService.getMyCameraPublisher()?.stream?.getMediaStream()?.getVideoTracks()[0]?.label; + this.deviceSrv.setCameraSelected(videoLabel); + } + } + } + private subscribeToVideconferenceDirectives() { this.prejoinSub = this.libService.prejoin.subscribe((value: boolean) => { this.showPrejoin = value; diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/device/device.service.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/device/device.service.ts index 4a7cc980..bf1905b8 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/device/device.service.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/device/device.service.ts @@ -43,6 +43,8 @@ export class DeviceService { } async forceUpdate() { + this.cameras = []; + this.microphones = []; await this.initializeDevices(); }