-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfclaim.html
126 lines (118 loc) · 4.9 KB
/
fclaim.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<html><head>
<link href="/pipe.css" media="all" rel="stylesheet" />
<title>Claim a visible device</title></head>
<script src="https://pi.pe/iot/js/sha256.js"></script>
<script src="https://pi.pe/iot/js/jquery-1.8.3.js"></script>
<script src="https://pi.pe/iot/js/phono.sdp.js"></script>
<script src="https://pi.pe/iot/js/pipeDb.js"></script>
<script src="https://pi.pe/iot/js/pipeDuct.js"></script>
<script src="https://pi.pe/iot/js/LazarQr.min.js"></script>
<script type="text/javascript">
function require(name){
console.log("fake require");
return Sha256;
}
</script>
<script src="https://pi.pe/iot/js/claim.js"></script>
<script type="text/javascript">
var nonceS;
var snap;
var sha256 = Sha256;
function startQrDecode() {
var video = document.getElementById('gumVideo');
var photo = document.getElementById('qr-canvas');
var context = photo.getContext('2d');
// set our canvas to the same size as our video
qrcode.callback = function(code) {
console.log("got qrcode of " + code);
clearInterval(tick);
navigator.vibrate(50);
var fparts = code.split(":");
$('#tofinger').val(fparts[0]);
nonceS = fparts[1];
console.log("nonce = " + nonceS);
for (var i = 1; i < 10; i++) {
var q = 1.0 - (0.1 * i);
snap = photo.toDataURL('image/jpeg', q);
console.log("snap encoded at q=" + q + " of size " + snap.length)
if (snap.length < 60000) {
break;
}
}
$("#qr-canvas").remove();
$("#gumVideo").css("display", "none");
dopair(fparts[0],fparts[1]);
};
var tick = setInterval(function() {
if ((video.videoWidth > 0) && (video.videoHeight > 0)) {
var rat = video.height / video.videoHeight;
photo.width = video.videoWidth * rat;
photo.height = video.videoHeight * rat;
console.log("set photo to " + photo.width + " x " + photo.height);
console.log("rat was " + rat);
context.drawImage(video, 0, 0, photo.width, photo.height);
qrcode.decode();
}
}, 250);
}
function startGum(sid) {
var constraints = {video: true, audio: false};
if (sid) {
constraints.video = {optional: [{sourceId: sid}]};
}
navigator.mediaDevices.getUserMedia(constraints).then(
function(stream) {
var url = window.URL || window.webkitURL;
var v = document.getElementById('gumVideo');
v.src = url ? url.createObjectURL(stream) : stream;
//v.play();
startQrDecode();
}).catch(
function(error) {
alert('Something went wrong. (error code ' + error.code + ')');
location.href = "nogum.htm";
return;
});
}
function onSourcesAcquired(sources) {
var sid;
for (var i = 0; i != sources.length; ++i) {
var source = sources[i];
console.log(source);
if ((source.kind == "videoinput") && (source.label.endsWith("back"))) {
sid = source.deviceId;
//break;
}
}
startGum(sid);
}
function askforCam() {
console.log("starting QR reader");
//frontcam...
var sid;
if ((typeof navigator.mediaDevices === 'undefined') || (typeof navigator.mediaDevices.enumerateDevices == 'undefined')) {
startGum(sid);
} else {
navigator.mediaDevices.enumerateDevices().then(onSourcesAcquired);
//MediaStreamTrack.getSources(onSourcesAcquired);
}
}
$(document).ready(function() {
PipeDb.whoAmI( function (id) {
gotId(id);
askforCam();
}, function(err) {
console.log("could not create identity " + err)
});
});
</script>
<h1>pipe Claim a device</h1>
<!--div> My Fingerprint is :
<span id="myFinger">unknown</span> </div-->
<div id="remoteVideoContainer" class="ui-video-remote-container">
<canvas width="320" height="240" id="qr-canvas"></canvas>
<video style="display:none;" width="320" height="240" id="gumVideo" autoplay="autoplay"/>
</div>
<div id='result'> </div>
</body>
</html>