diff --git a/app/assets/javascripts/new-capture.js b/app/assets/javascripts/new-capture.js new file mode 100644 index 000000000..6954fee75 --- /dev/null +++ b/app/assets/javascripts/new-capture.js @@ -0,0 +1,724 @@ +//= require graph.js +// window.webcam.getCameraList() + +flotoptions = {"crosshair":{"mode":"x"},"series":{"lines":{"show":true,"lineWidth":1}},"yaxis":{"show":true,"max":100,"min":0},"xaxis":{"show":false},"shadowSize":0,"threshold":{"below":0,"color":"#a00"},"grid":{"clickable":true,"hoverable":true,"borderWidth":0,"color":"#ccc","backgroundColor":"#111"},"colors":["#ffffff","rgba(255,0,0,0.3)","rgba(0,255,0,0.3)","rgba(0,0,255,0.3)","#ffff00"]} + + flotoptions.grid = { + clickable: true, + hoverable:true, + borderWidth: 0, + color: "#ccc", + backgroundColor: "#111" + } + flotoptions.colors = [ "#ccc", "#E02130", "#FAB243", "#429867", "#2B5166" ]//, "#482344" ] + +$W = { + data: null, + baseline: null, + full_data: [], + unflipped_data: [], + flipped: false, + rotated: false, + pos: 0, + sample_height: 1, + // height and width of the output stream container + width: 640, + height: 480, + waterfall_height: 150, + scale_h: 1, + scale_w: 1, + // width: 1280, + // height: 720, + frame: 0, + defaultConstraints: { + audio: false, + video: { + facingMode: "environment" + } + }, + + getUserMedia: function(options) { + AdapterJS.webRTCReady(() => { + // The WebRTC API is ready. + const container = document.getElementById('webcam'), + video = document.createElement('video'); + + container.appendChild(video); + video.autoplay = true; + video.id = 'webcam-video' + + const successCallback = stream => { + $('#heightIndicator').show() + $('#webcam-msg').hide() + attachMediaStream(video, stream) + if ($W.flipped == true) { + $W.flipped = false; // <= turn it false because f_h() will toggle it. messy. + $W.flip_horizontal(); + } + }; + + const errorCallback = () => console.warn(error); + + getUserMedia($W.defaultConstraints, successCallback, errorCallback); + }); + }, + + initialize: function(args) { + this.mobile = args['mobile'] || false + this.flipped = args['flipped'] == true || false + this.interface = args['interface'] || false + this.mode = args['mode'] || 'combined' + flotoptions.colors = [ "#ffffff", "rgba(255,0,0,0.3)", "rgba(0,255,0,0.3)", "rgba(0,0,255,0.3)", "#ffff00"] + this.calibrated = args['calibrated'] || false + this.width = args['width'] || this.width + this.height = args['height'] || this.height + if (args['height']) { + this.options.height = args['height'] + this.options.width = args['width'] + } + + if (args.video_row) { + this.sample_start_row = args.video_row; + } else { + // this is camera sample row, not saved image sample row! + this.sample_start_row = localStorage.getItem('sw:samplestartrow') || this.width/2; + } + this.setSampleRow(this.sample_start_row) + + this.getUserMedia(this.options, this.success, this.deviceError) + + this.canvas = document.getElementById("canvas") + $('canvas').width = this.width+"px" + this.canvas.width = this.width + this.canvas.height = this.waterfall_height + this.ctx = this.canvas.getContext("2d") + this.image = this.ctx.getImageData(0, 0, this.width, this.height); + + // create canvas for the sidebar preview if there's a "preview" canvas element: + if ($('#preview').length > 0) { + this.preview_ctx = $('#preview')[0].getContext('2d') + } + + setInterval($W.alert_overexposure, 500); // every 0.5 seconds + setInterval(function() { + + $W.getRecentCalibrations('.select-calibration'); + + }, 10000); // every 10 seconds + $('.btn-switch-calibration-configure').click(function() { + window.location = "/capture?calibration_id=" + $('.select-calibration-configure').val() + }); + + $('.btn-switch-calibration-capture').click(function() { + window.location = "/capture?calibration_id=" + $('.select-calibration-capture').val() + }); + + $W.data = [{label: "webcam",data:[]}] + if ($('video')[0]) { + $('video')[0].width = "320" + $('video')[0].height = "240" + } else { + $('video').width = "320" + $('video').height = "240" + } + }, + + deviceError: function (error) { + //console.log(error) + }, + // Draws the appropriate pixels onto the top row of the waterfall. + // Override this if you want a non-linear cross section or somethine + // else special!