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>
<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><a href="#txinputs" data-toggle="tab">Inputs <small>(<span id="totalInput">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.00000000</span>)</small></a></li>
</ul>
<br>
@ -687,6 +687,7 @@
<div class="modal-body" align="center">
<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>
<div id="qrcode-scanner-callback-to" class="hidden"></div>
</div>

View file

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