Switch Camera

How can I switch the camera in UniversalAR? In Zapworks Studio it’s as easy as doing

cameraManager.useFrontCamera(); // Switch to the front facing camera
cameraManager.useRearCamera(); // Switch to the rear facing camera

This is explained in the Switching Between Cameras section here.

However when reading the UniversalAR documentation for PlayCanvas, I couldn’t find an explanation on how to switch cameras. Only to start using front or rear, but not how to switch. Or stop and start another camera mode, or whatever. Nothing.

Preferably I would like to know how to do this changing the mirror mode as well, because using the front face camera I use the poses option.

For reference this was already asked here and here

How can I start the camera, pause(or stop?), switch cameras? Thank you for your time guys.

Ok after a little code inspection, I managed to do it with this:

Main.attributes.add('Camera', {type: 'entity'});
//in the initialize
Camera = this.Camera;
function switchCamera() {
    ZapparCamera.prototype.source.destroy();

    if (Camera.script.zapparCamera["Front Facing Camera"]) {
        Camera.script.zapparCamera["Mirror Mode"] = "none";
        ZapparCamera.prototype.source = new Zappar.CameraSource(Camera.script.zapparCamera.pipeline, Zappar.cameraDefaultDeviceID(false));
        Camera.script.zapparCamera["Front Facing Camera"] = false;
    } else {
        Camera.script.zapparCamera["Mirror Mode"] = "poses";
        ZapparCamera.prototype.source = new Zappar.CameraSource(Camera.script.zapparCamera.pipeline, Zappar.cameraDefaultDeviceID(true));
        Camera.script.zapparCamera["Front Facing Camera"] = true;
    }

    ZapparCamera.prototype.source.start();
}

However there is a small issue, it changes the mirror mode before switching the camera. How can I avoid this? Changing the mirror mode after I call start doesn’t help. This problem doesn’t happen on Zapworks Studio.

EDIT
Furthermore, there is a worse problem. If you tap too quickly to switch cameras, eventually the camera feed freezes and you can’t switch anymore