Skip to content

Commit c84bbf5

Browse files
authored
Merge pull request #7 from hypersign-protocol/experimentalQr
Experimental qr
2 parents eb75fcc + 4545cb5 commit c84bbf5

File tree

11 files changed

+20867
-557
lines changed

11 files changed

+20867
-557
lines changed

package-lock.json

Lines changed: 20222 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"bootstrap-vue": "^2.23.1",
1616
"core-js": "^3.8.3",
1717
"gh-pages": "^6.0.0",
18+
"jsqr": "^1.4.0",
1819
"less": "^4.2.0",
1920
"less-loader": "^11.1.3",
2021
"vue": "^2.6.14",

src/App.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ export default {
1515
MainPage,
1616
},
1717
methods: {
18-
...mapActions(["setSession"]),
18+
...mapActions(["setSession","setJWT"]),
1919
},
20-
created() {
21-
this.setSession();
20+
async created() {
21+
await this.setJWT()
22+
await this.setSession();
2223
},
2324
};
2425
</script>

src/components/AppClickPic.vue

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@
8686
</div>
8787
</div>
8888
<MessageBox :msg="toastMessage" :type="toastType" v-if="isToast" />
89-
<div class="card-footer"><PoweredBy /></div>
89+
<div class="card-footer">
90+
<PoweredBy />
91+
</div>
9092
</div>
9193
</template>
9294

@@ -111,11 +113,13 @@ export default {
111113
toastMessage: "",
112114
toastType: "success",
113115
isToast: false,
116+
width: 0,
117+
height: 0,
114118
};
115119
},
116120
methods: {
117121
...mapActions(["addharQRVerify", "verifyImage"]),
118-
...mapMutations(["nextStep"]),
122+
...mapMutations(["nextStep", "setImage"]),
119123
toggleCamera() {
120124
if (this.isCameraOpen) {
121125
this.isCameraOpen = false;
@@ -133,14 +137,30 @@ export default {
133137
134138
const constraints = (window.constraints = {
135139
audio: false,
136-
video: true,
140+
video: {
141+
facingMode: "user",
142+
width: {
143+
min: 640,
144+
ideal: 1280,
145+
max: 1920,
146+
},
147+
height: {
148+
min: 480,
149+
ideal: 720,
150+
max: 1080,
151+
},
152+
},
137153
});
138154
139155
navigator.mediaDevices
140156
.getUserMedia(constraints)
141157
.then((stream) => {
142158
this.isLoading = false;
143159
this.$refs.camera.srcObject = stream;
160+
161+
const track = stream.getVideoTracks()[0];
162+
this.width = track.getSettings().width;
163+
this.height = track.getSettings().height;
144164
})
145165
.catch((error) => {
146166
console.error(error);
@@ -170,18 +190,26 @@ export default {
170190
}
171191
172192
this.isPhotoTaken = !this.isPhotoTaken;
173-
193+
const canvas = this.$refs.canvas;
174194
const context = this.$refs.canvas.getContext("2d");
175-
context.drawImage(this.$refs.camera, 10, 10, 230, 230);
195+
const video = this.$refs.camera;
196+
197+
if (this.isPhotoTaken) {
198+
const size = Math.min(this.width, this.height);
199+
const x = (this.width - size) / 2;
200+
const y = (this.height - size) / 2;
201+
context.drawImage(video, x, y, size, size, 5, 7, canvas.width - 10, canvas.height);
202+
203+
const imageData = this.$refs.canvas.toDataURL();
204+
this.setImage(imageData);
205+
}
176206
},
177207
178208
downloadImage() {
179-
const download = document.getElementById("downloadPhoto");
180-
const canvas = document
181-
.getElementById("photoTaken")
182-
.toDataURL("image/jpeg")
183-
.replace("image/jpeg", "image/octet-stream");
184-
download.setAttribute("href", canvas);
209+
const link = document.createElement("a");
210+
link.download = "photo.png";
211+
link.href = this.$refs.canvas.toDataURL();
212+
link.click();
185213
},
186214
wait() {
187215
return new Promise((resolve) => {
@@ -191,20 +219,41 @@ export default {
191219
});
192220
},
193221
async submit() {
222+
const that = this;
194223
try {
195224
this.isLoadingPage = true;
196225
197-
await this.wait();
226+
// await this.wait();
198227
199228
const result = await this.verifyImage();
200229
if (result) {
230+
201231
this.stopCameraStream();
202-
this.nextStep();
232+
this.isLoadingPage = false;
233+
if (result.verified) {
234+
235+
that.toast("Match Found : " + result.verified + " " + result.userImageScore + " %")
236+
await that.wait()
237+
this.isLoadingPage = false;
238+
239+
this.nextStep();
240+
} else {
241+
that.toast("Match Not Found : " + result.verified + " " + result.userImageScore + " %", "error")
242+
243+
await that.wait()
244+
this.isLoadingPage = false;
245+
this.toggleCamera()
246+
}
247+
248+
203249
}
204250
} catch (e) {
205-
console.error(e);
251+
252+
253+
this.isLoadingPage = false;
206254
this.stopCameraStream();
207-
this.toast(e.message, "error");
255+
this.toast(e, "error");
256+
this.toggleCamera();
208257
}
209258
},
210259
toast(msg, type = "success") {
@@ -295,9 +344,11 @@ export default {
295344
0% {
296345
opacity: 1;
297346
}
347+
298348
50% {
299349
opacity: 0.4;
300350
}
351+
301352
100% {
302353
opacity: 1;
303354
}

src/components/AppOtp.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ export default {
132132
// TODO: go for verification
133133
const result = await this.getFinalResult();
134134
await this.wait(2000);
135-
if (result) {
136-
this.setFinalResult(result);
135+
if (result && result.credentialSubject) {
136+
this.setFinalResult(result.credentialSubject);
137137
this.isLoadingPage = false;
138-
if (result.verified === true) {
138+
if (result.credentialSubject.verified === true) {
139139
this.nextStep(4);
140140
} else {
141141
this.nextStep(5);

0 commit comments

Comments
 (0)