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