mirror of https://github.com/OpenVidu/openvidu.git
ov-components: update audio device change handling and improve track retrieval logic
parent
5d9dbc114b
commit
8a236e1b67
|
@ -49,7 +49,7 @@
|
|||
<div class="control-group" *ngIf="showMicrophoneButton">
|
||||
<ov-audio-devices-select
|
||||
[compact]="true"
|
||||
(onAudioDeviceChanged)="onAudioDeviceChanged.emit($event)"
|
||||
(onAudioDeviceChanged)="audioDeviceChanged($event)"
|
||||
(onAudioEnabledChanged)="audioEnabledChanged($event)"
|
||||
(onDeviceSelectorClicked)="onDeviceSelectorClicked()"
|
||||
class="device-selector"
|
||||
|
|
|
@ -243,7 +243,7 @@ export class PreJoinComponent implements OnInit, OnDestroy {
|
|||
const updatedTracks = this.openviduService.getLocalTracks();
|
||||
|
||||
// Find the new video track
|
||||
const newVideoTrack = updatedTracks.find((track) => track.kind === 'video');
|
||||
const newVideoTrack = updatedTracks.find((track) => track.kind === Track.Kind.Video);
|
||||
|
||||
// if (newVideoTrack && newVideoTrack !== this.videoTrack) {
|
||||
this.tracks = updatedTracks;
|
||||
|
@ -260,6 +260,26 @@ export class PreJoinComponent implements OnInit, OnDestroy {
|
|||
this.hasVideoDevices = devices.length > 0;
|
||||
}
|
||||
|
||||
audioDeviceChanged(device: CustomDevice) {
|
||||
try {
|
||||
this.log.d('Audio device changed to:', device);
|
||||
|
||||
// Get the updated tracks from the service
|
||||
const updatedTracks = this.openviduService.getLocalTracks();
|
||||
|
||||
// Find the new audio track
|
||||
const newAudioTrack = updatedTracks.find((track) => track.kind === Track.Kind.Audio);
|
||||
|
||||
this.tracks = updatedTracks;
|
||||
this.audioTrack = newAudioTrack;
|
||||
|
||||
this.onAudioDeviceChanged.emit(device);
|
||||
} catch (error) {
|
||||
this.log.e('Error handling audio device change:', error);
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
async audioEnabledChanged(enabled: boolean) {
|
||||
if (enabled && !this.audioTrack) {
|
||||
const newAudioTrack = await this.openviduService.createLocalTracks(false, true);
|
||||
|
@ -316,8 +336,8 @@ export class PreJoinComponent implements OnInit, OnDestroy {
|
|||
try {
|
||||
this.tracks = await this.openviduService.createLocalTracks();
|
||||
this.openviduService.setLocalTracks(this.tracks);
|
||||
this.videoTrack = this.tracks.find((track) => track.kind === 'video');
|
||||
this.audioTrack = this.tracks.find((track) => track.kind === 'audio');
|
||||
this.videoTrack = this.tracks.find((track) => track.kind === Track.Kind.Video);
|
||||
this.audioTrack = this.tracks.find((track) => track.kind === Track.Kind.Audio);
|
||||
this.isVideoEnabled = this.openviduService.isVideoTrackEnabled();
|
||||
|
||||
return; // Success, exit retry loop
|
||||
|
|
|
@ -402,11 +402,11 @@ export class OpenViduService {
|
|||
const existingTrack = this.localTracks.find((track) => track.kind === Track.Kind.Video) as LocalVideoTrack;
|
||||
|
||||
if (existingTrack) {
|
||||
//TODO: SHould use replace track using restartTrack
|
||||
//TODO: Should use replace track using restartTrack
|
||||
// Try to restart existing track
|
||||
this.removeVideoTrack();
|
||||
// try {
|
||||
// await existingTrack.restartTrack({ deviceId: deviceId });
|
||||
// await existingTrack.restartTrack({ deviceId: deviceId });
|
||||
// this.log.d('Camera switched successfully using existing track');
|
||||
// return;
|
||||
// } catch (error) {
|
||||
|
@ -424,7 +424,6 @@ export class OpenViduService {
|
|||
|
||||
const videoTrack = newVideoTracks.find((t) => t.kind === Track.Kind.Video);
|
||||
if (videoTrack) {
|
||||
|
||||
// Mute if camera is disabled in settings
|
||||
if (!this.deviceService.isCameraEnabled()) {
|
||||
await videoTrack.mute();
|
||||
|
@ -448,8 +447,8 @@ export class OpenViduService {
|
|||
const existingTrack = this.localTracks?.find((track) => track.kind === Track.Kind.Audio) as LocalAudioTrack;
|
||||
|
||||
if (existingTrack) {
|
||||
this.removeAudioTrack();
|
||||
//TODO: SHould use replace track using restartTrack
|
||||
this.removeAudioTrack();
|
||||
//TODO: Should use replace track using restartTrack
|
||||
// Try to restart existing track
|
||||
// try {
|
||||
// await existingTrack.restartTrack({ deviceId: deviceId });
|
||||
|
|
Loading…
Reference in New Issue