couple of extra tweaks to the way qrcode scanning works

This commit is contained in:
OutCast3k 2015-03-09 12:27:28 +00:00
parent c150800a5f
commit 408f3ae68a
2 changed files with 59 additions and 60 deletions

View file

@ -361,8 +361,8 @@
</div> </div>
<ul class="nav nav-tabs" id="putTabs"> <ul class="nav nav-tabs" id="putTabs">
<li class="active"><a href="#txoutputs" data-toggle="tab">Outputs <small>(<span id="totalOutput">0.0000</span>)</small></a></li> <li class="active"><a href="#txoutputs" data-toggle="tab">Outputs <small>(<span id="totalOutput">0.00000000</span>)</small></a></li>
<li><a href="#txinputs" data-toggle="tab">Inputs <small>(<span id="totalInput">0.0000</span>)</small></a></li> <li><a href="#txinputs" data-toggle="tab">Inputs <small>(<span id="totalInput">0.00000000</span>)</small></a></li>
</ul> </ul>
<br> <br>
@ -687,6 +687,7 @@
<div class="modal-body" align="center"> <div class="modal-body" align="center">
<select id="videoSource" class="form-control"></select> <select id="videoSource" class="form-control"></select>
<div id="videoReaderError" class="hidden">Your browser does not offer camera support</div>
<video id="videoReader" muted autoplay style="width:100%;height:100%"></video> <video id="videoReader" muted autoplay style="width:100%;height:100%"></video>
<div id="qrcode-scanner-callback-to" class="hidden"></div> <div id="qrcode-scanner-callback-to" class="hidden"></div>
</div> </div>

View file

@ -415,7 +415,11 @@ $(document).ready(function() {
/* code for the qr code scanner */ /* code for the qr code scanner */
function gotSources(sourceInfos) { $(".qrcodeScanner").click(function(){
if ((typeof MediaStreamTrack === 'function') && typeof MediaStreamTrack.getSources === 'function'){
MediaStreamTrack.getSources(function(sourceInfos){
var f = 0;
$("select#videoSource").html("");
for (var i = 0; i !== sourceInfos.length; ++i) { for (var i = 0; i !== sourceInfos.length; ++i) {
var sourceInfo = sourceInfos[i]; var sourceInfo = sourceInfos[i];
var option = document.createElement('option'); var option = document.createElement('option');
@ -425,29 +429,34 @@ $(document).ready(function() {
$(option).appendTo("select#videoSource"); $(option).appendTo("select#videoSource");
} }
} }
});
} else {
$("#videoSource").addClass("hidden");
} }
if (typeof MediaStreamTrack === 'undefined'){ $("#videoSource").unbind("change").change(function(){
return alert('This browser does not support MediaStreamTrack.\n\nTry Chrome Canary.'); videoStart()
} else { });
MediaStreamTrack.getSources(gotSources);
} videoStart();
$("#qrcode-scanner-callback-to").html($(this).attr('forward-result'));
});
function videoStart(){ function videoStart(){
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || false;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; if(navigator.getUserMedia){
if (!!window.stream) { if (!!window.stream) {
$("video").attr('src',null); $("video").attr('src',null);
window.stream.stop(); window.stream.stop();
} }
var videoSource = $("select#videoSource").val() var videoSource = $("select#videoSource").val();
var constraints = { var constraints = {
video: { video: {
optional: [{sourceId: videoSource}] optional: [{sourceId: videoSource}]
} }
}; };
navigator.getUserMedia(constraints, function(stream){ navigator.getUserMedia(constraints, function(stream){
window.stream = stream; // make stream available to console window.stream = stream; // make stream available to console
var videoElement = document.querySelector('video'); var videoElement = document.querySelector('video');
@ -457,28 +466,17 @@ $(document).ready(function() {
QCodeDecoder().decodeFromCamera(document.getElementById('videoReader'), function(er,data){ QCodeDecoder().decodeFromCamera(document.getElementById('videoReader'), function(er,data){
if(!er){ if(!er){
var r = ''; var match = data.match(/^bitcoin\:([13][a-z0-9]{26,33})/i);
var match = data.match(/^bitcoin\:(.*)\??$/i); var result = match ? match[1] : data;
if(match){ $(""+$("#qrcode-scanner-callback-to").html()).val(result);
r = match[1];
} else {
r = data;
}
$(""+$("#qrcode-scanner-callback-to").html()).val(r);
$("#qrScanClose").click(); $("#qrScanClose").click();
} }
}); });
} else {
$("#videoReaderError").removeClass("hidden");
$("#videoReader, #videoSource").addClass("hidden");
}
} }
$(".qrcodeScanner").click(function(){
$("select#videoSource").change(function(){
videoStart()
});
videoStart();
$("#qrcode-scanner-callback-to").html($(this).attr('forward-result'));
});
$("#redeemFromBtn").click(function(){ $("#redeemFromBtn").click(function(){
var thisbtn = this; var thisbtn = this;