             self.webView!.superview!.bringSubview(toFront: self.webView)
 //            self.webView!.superview!.sendSubview(toBack: cameraPreview!)
             cameraPreview.addPreviewLayer();
-            
+
             // Start video capture.
             captureSession?.startRunning()
-            
+
             // Move the message label and top bar to the front
             //            view.bringSubview(toFront: messageLabel)
             //            view.bringSubview(toFront: topbar)
-            
+
             // Initialize QR Code Frame to highlight the QR code
             cameraPreview.qrCodeFrameView = UIView()
-            
+
             cameraPreview.qrCodeFrameView?.layer.borderColor = UIColor.green.cgColor
             cameraPreview.qrCodeFrameView?.layer.borderWidth = 2
             self.webView?.addSubview(cameraPreview.qrCodeFrameView!)
             self.webView?.bringSubview(toFront: cameraPreview.qrCodeFrameView!)
-            
+
         } catch {
             // If any error occurs, simply print it out and don't continue any more.
             print(error)
         }
-        
+
         let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "Camera Started")
         commandDelegate!.send(pluginResult, callbackId:command.callbackId)
     }
-    
+
     func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
-        
+
         var newReadTime: Date
         var milsSinceLastRead: Double
-        
+
         // Check if the metadataObjects array is not nil and it contains at least one object.
         if metadataObjects == nil || metadataObjects.count == 0 {
             cameraPreview.qrCodeFrameView?.frame = CGRect.zero
             return
         }
-        
+
         // Get the metadata object.
         let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
-        
-        if metadataObj.type == AVMetadataObjectTypeQRCode {
+
+        if metadataObj.type == AVMetadataObject.ObjectType.qr {
             // If the found metadata is equal to the QR code metadata then update the status label's text and set the bounds
             let barCodeObject = cameraPreview.videoPreviewLayer?.transformedMetadataObject(for: metadataObj)
             cameraPreview.qrCodeFrameView?.frame = CGRect.init(x: self.xPoint + barCodeObject!.bounds.minX, y: self.yPoint + barCodeObject!.bounds.minY, width: barCodeObject!.bounds.width, height: barCodeObject!.bounds.height)
-            
+
             if metadataObj.stringValue != nil {
                 if (self.barcodeReadCallback != nil) {
                     newReadTime = Date.init()

        let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "Camera Stopped")
        commandDelegate!.send(pluginResult, callbackId:command.callbackId)
    }
    
    func hideCamera(_ command: CDVInvokedUrlCommand) {
        //hide camera
    }
    
    func showCamera(_ command: CDVInvokedUrlCommand) {
        //show camera
    }
    
    func switchCamera(_ command: CDVInvokedUrlCommand) {
        //switch camera
        if let session = captureSession {
            //Indicate that some changes will be made to the session
            session.beginConfiguration()
            
            //Remove existing input
            let currentCameraInput: AVCaptureInput = (session.inputs.first as? AVCaptureInput)!
            
            session.removeInput(currentCameraInput)
            
            //Get new input
            var newCamera: AVCaptureDevice! = nil
            if let input = currentCameraInput as? AVCaptureDeviceInput {

                    layer.frame = self.bounds;
                }
            }

            self.videoPreviewLayer?.connection?.videoOrientation = interfaceOrientationToVideoOrientation(UIApplication.shared.statusBarOrientation);
        }

        func addPreviewLayer() {
            videoPreviewLayer?.frame = self.bounds
            self.backgroundColor = UIColor.clear
            self.layer.addSublayer(videoPreviewLayer!)
        }

        func removePreviewLayer() {
            self.videoPreviewLayer?.removeFromSuperlayer()
            self.videoPreviewLayer = nil
        }
    }

    var cameraPreview: CameraPreview!
    var captureSession:AVCaptureSession?
    var barcodeReadCallback:String?

    var xPoint:CGFloat = 0.0
    var yPoint:CGFloat = 0.0
    var width:CGFloat = 0.0
