CameraUI.prototype.startPreview = function()

in src/browser/CaptureProxy.js [92:128]


CameraUI.prototype.startPreview = function (count, successCB, errorCB) {
    const that = this;

    this.preview.onclick = function (e) {
        // proceed with capture here
        // We don't need to propagate click event to parent elements.
        // Otherwise click on vieo element will trigger click event handler
        // for preview root element and cause preview cancellation
        e.stopPropagation();
        // Create canvas element, put video frame on it
        // and save its contant as Data URL
        const canvas = document.createElement('canvas');
        canvas.width = this.videoWidth;
        canvas.height = this.videoHeight;
        canvas.getContext('2d').drawImage(that.preview, 0, 0);
        successCB(canvas.toDataURL('image/jpeg'));
    };

    this.container.onclick = function () {
        // Cancel capture here
        errorCB(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
    };

    navigator.getUserMedia(
        { video: true },
        function (previewStream) {
            // Save video stream to be able to stop it later
            that._previewStream = previewStream;
            that.preview.src = URL.createObjectURL(previewStream); // eslint-disable-line no-undef
            // We don't need to set visibility = true for preview element
            // since this will be done automatically in onplay event handler
        },
        function (/* err */) {
            errorCB(new CaptureError(CaptureError.CAPTURE_INTERNAL_ERR));
        }
    );
};