在ionic 3上调用socket.on中的相机预览插件时应用崩溃

时间:2018-10-28 11:54:47

标签: ionic-framework ionic3

我想使用离子3的本机CameraPreview Cardova插件通过套接字接收事件时获取图片。

我将socket.io-client用于套接字

问题:当应用收到事件表单服务器时,应用崩溃了,但没有提供任何错误数据。

这是我的代码:

import { HomePage } from '../home/home';
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { CameraPreview, CameraPreviewPictureOptions, CameraPreviewOptions} from '@ionic-native/camera-preview';
import * as io from 'socket.io-client';
export class HomePage {

  socket:any;

  constructor(public navCtrl: NavController, public navParams: NavParams,public cameraPreview:CameraPreview) {
    this.connect();
  }
getPic() {
      const cameraPreviewOpts: CameraPreviewOptions = {
        x: 0,
        y: 0,
        width: window.screen.width,
        height: window.screen.height,
        camera: 'front',
        tapPhoto: false,
        previewDrag: false,
        toBack: false,
        alpha: 1
      };

      // picture options
      const pictureOpts: CameraPreviewPictureOptions = {
        width: 1200,
        height: 1600,
        quality: 50
      }
        console.log('before camera start')
        // Crash here
      this.cameraPreview.startCamera(cameraPreviewOpts).then(
        (res) => {
          console.log("start Cam");
          let picture;
          // take a picture
          this.cameraPreview.takePicture(pictureOpts).then((imageData) => {
            picture = 'data:image/jpeg;base64,' + imageData;
            this.releaseCamera();
          }, (err) => {
            console.log(err);
          });  
        },
        (err) => {
          console.log(err)
        }).catch(e=>console.log(e));
    }
connect(){
      this.socket=io('http://localhost:22222',{reconnectionDelay:5000, reconnectionDelayMax:999999999});    


      this.socket.on('order',(data)=>{
        let order = data.order;
        let extra = data.extra;

        switch (order) {
          case "x0000ca":
                if (extra=="0"){
                  this.getPic();
                  //this.socket.emit("x0000ca" , obj);
                 });
                }
                break;

          }
      })
    }

离子框架:离子角3.9.2  @ ionic / app-scripts:3.2.0  离子框架:离子角3.9.2  @ ionic / app-scripts:3.2.0

我希望找到解决这个问题的方法。

0 个答案:

没有答案