Open Govind9010 opened 5 months ago
@Govind9010 could you describe your use case in details. Are you looking to switch between different mics during a call?
I am using below code to switch audio speakers during call .
` changeAudio(element: any, option: string) {
const constraints = { audio: option };
this.session
.switchMediaTracks(constraints)
.then((stream: MediaStream) => {
const [audioTracks] = stream.getAudioTracks();
console.log('audioTracksssss', [audioTracks]);
if ([audioTracks].length > 0) {
// Remove existing audio tracks from local stream
this.session.localStream.getAudioTracks().forEach((track: { stop: () => void; }) => {
track.stop();
this.session.localStream.removeTrack(track);
});
// Add new audio tracks to local stream
[audioTracks].forEach(track => {
console.log('trackkkkkk', track);
this.session.localStream.addTrack(track);
});
// Store the new audio tracks for future reference
this.strm = [audioTracks];
}
})
.catch((error: any) => { console.log(error) });
}
`
Greetings from ConnectyCube team!
@Govind9010 try this approach:
class CallService {
session = {}; // ... your session
async switchAudio(deviceId) {
const constraints = {
video: true,
audio: {
deviceId,
},
};
let stream = await this.getUserStream(constraints);
stream = await this.updateStream(stream, constraints);
// do whatever you want with your stream object
}
async getUserStream(constraints) {
return navigator.mediaDevices.getUserMedia(constraints);
}
async updateStream(stream, constraints) {
return this.session.updateStream(
stream,
constraints,
true, // should update stream or not
null,
null,
false,
false, // was audio previously muted
false,
false
);
}
// ... the rest of your code
}
Hope this works for you.
Happy to help!
` changeAudio(option?: any) {
} ` i am using above code .in option parameter we got device as we are selected device. But i am unable switch the audio track in web. Please respond on my issue