So i decided to change to using replaceTrack to switch cameras on mobile devices which works a lot better than removing a publisher, removing the publisher messes up the subscriber side.
However i have noticed now that when replacing the track for the camera, the sound gets lost. In my initial publish the sound works, i then get the front and back camera id and the audio id :
this.OVPublisher.once('accessAllowed', (event) => {
console.log("ACCESS ALLOWED")
this.OV.getDevices().then((devices)=> {
let videoDevices = devices.filter(device => device.kind === 'videoinput' && device.label !== 'Snap Camera');
if (videoDevices && videoDevices.length > 1) {
this.canSwitchCam = true;
this.frontDeviceId = videoDevices[0].deviceId;
this.backDeviceId = videoDevices[0].deviceId;
}
let audioDevices = devices.filter(device => device.kind === 'audioinput');
if(audioDevices && audioDevices.length >= 1){
this.audioDeviceId = audioDevices[0].deviceId;
}
})
})
Then to switch camera
this.OV.getUserMedia(<any>{
videoSource: this.OVCurrentCamera === 'front' ? this.backDeviceId : this.frontDeviceId,
audioSource: this.audioDeviceId
}).then((mediaStream) => {
let track = mediaStream.getVideoTracks()[0];
console.log("USING TRACK FOR",track)
this.OVPublisher.replaceTrack(track).then(() => {
this.OVCurrentCamera = this.OVCurrentCamera === 'front' ? 'back' : 'front';
}).catch(() => {
this.toast.error('There was a problem switching cameras.');
})
}).catch(() => {
this.toast.error('Could not access devices');
})
The camera switches fine but yeh, the audio is lost? So basically the microphone on my iphone stops taking sound input?