couple of extra tweaks to the way qrcode scanning works
This commit is contained in:
parent
c150800a5f
commit
408f3ae68a
2 changed files with 59 additions and 60 deletions
|
@ -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>
|
||||
|
|
114
js/coinbin.js
114
js/coinbin.js
|
@ -415,71 +415,69 @@ $(document).ready(function() {
|
|||
|
||||
/* code for the qr code scanner */
|
||||
|
||||
function gotSources(sourceInfos) {
|
||||
for (var i = 0; i !== sourceInfos.length; ++i) {
|
||||
var sourceInfo = sourceInfos[i];
|
||||
var option = document.createElement('option');
|
||||
option.value = sourceInfo.id;
|
||||
if (sourceInfo.kind === 'video') {
|
||||
option.text = sourceInfo.label || 'camera ' + ($("select#videoSource options").length + 1);
|
||||
$(option).appendTo("select#videoSource");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof MediaStreamTrack === 'undefined'){
|
||||
return alert('This browser does not support MediaStreamTrack.\n\nTry Chrome Canary.');
|
||||
} else {
|
||||
MediaStreamTrack.getSources(gotSources);
|
||||
}
|
||||
|
||||
function videoStart(){
|
||||
|
||||
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
||||
|
||||
if (!!window.stream) {
|
||||
$("video").attr('src',null);
|
||||
window.stream.stop();
|
||||
}
|
||||
|
||||
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');
|
||||
videoElement.src = window.URL.createObjectURL(stream);
|
||||
videoElement.play();
|
||||
}, function(error){ });
|
||||
|
||||
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);
|
||||
$("#qrScanClose").click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(".qrcodeScanner").click(function(){
|
||||
$("select#videoSource").change(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');
|
||||
option.value = sourceInfo.id;
|
||||
if (sourceInfo.kind === 'video') {
|
||||
option.text = sourceInfo.label || 'camera ' + ($("select#videoSource options").length + 1);
|
||||
$(option).appendTo("select#videoSource");
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("#videoSource").addClass("hidden");
|
||||
}
|
||||
|
||||
$("#videoSource").unbind("change").change(function(){
|
||||
videoStart()
|
||||
});
|
||||
videoStart();
|
||||
|
||||
videoStart();
|
||||
$("#qrcode-scanner-callback-to").html($(this).attr('forward-result'));
|
||||
});
|
||||
|
||||
function videoStart(){
|
||||
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 constraints = {
|
||||
video: {
|
||||
optional: [{sourceId: videoSource}]
|
||||
}
|
||||
};
|
||||
|
||||
navigator.getUserMedia(constraints, function(stream){
|
||||
window.stream = stream; // make stream available to console
|
||||
var videoElement = document.querySelector('video');
|
||||
videoElement.src = window.URL.createObjectURL(stream);
|
||||
videoElement.play();
|
||||
}, function(error){ });
|
||||
|
||||
QCodeDecoder().decodeFromCamera(document.getElementById('videoReader'), function(er,data){
|
||||
if(!er){
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
$("#redeemFromBtn").click(function(){
|
||||
var thisbtn = this;
|
||||
var addr = '';
|
||||
|
|
Loading…
Reference in a new issue