                 return AVCaptureVideoOrientation.portraitUpsideDown;
             }
         }
-        
+
         override func layoutSubviews() {
             super.layoutSubviews();
             if let sublayers = self.layer.sublayers {

            }
        }
    }
    
    func cameraWithPosition(position: AVCaptureDevicePosition) -> AVCaptureDevice? {
        if let potentialDevices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) {
            for device in potentialDevices {
                let device = device as! AVCaptureDevice
                if device.position == position {
                    return device
                }
            }
        }
        
        return nil
    }
    
    //API methods for cordova
    
    func startListening(_ command: CDVInvokedUrlCommand) {
        //add addListener
        print("listening")
        barcodeReadCallback = command.callbackId
    }
    
    func stopReading(_ command: CDVInvokedUrlCommand) {
        //stop camera
        captureSession?.stopRunning()

                err = err1
                newVideoInput = nil
            }

            if newVideoInput == nil || err != nil {
                print("Error creating capture device input")
            } else {
                session.addInput(newVideoInput)
            }

            //Commit all the configuration changes at once
            session.commitConfiguration()

            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "Camera Switched")
            commandDelegate!.send(pluginResult, callbackId:command.callbackId)
        } else {
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "Couldn't switch")
            commandDelegate!.send(pluginResult, callbackId:command.callbackId)
        }

    }

    func getSupportedFlashModes(_ command: CDVInvokedUrlCommand) {
        //get supported flash modes
    }

    func setFlashMode(_ command: CDVInvokedUrlCommand) {
        //set flash mode
    }

    func setPreviewSize(_ command: CDVInvokedUrlCommand) {
        //set preview size
    }
