Skip to content

Commit f468b3b

Browse files
author
ariovistus
committed
proof of concept qr code gen and scan
1 parent b842812 commit f468b3b

File tree

13 files changed

+662
-1
lines changed

13 files changed

+662
-1
lines changed

aurelia_project/aurelia.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"options": {
22-
"minify": "stage & prod",
22+
"minify": false,
2323
"sourcemaps": "dev & stage"
2424
},
2525
"bundles": [
@@ -137,6 +137,32 @@
137137
"name": "urijs",
138138
"path": "../node_modules/urijs",
139139
"main": "./src/URI"
140+
},
141+
"qrcode-generator",
142+
{
143+
"name": "zxing",
144+
"path": "../node_modules/instascan/src",
145+
"main": "zxing"
146+
},
147+
{
148+
"name": "visibilityjs",
149+
"path": "../node_modules/visibilityjs/lib",
150+
"main": "visibility.timers"
151+
},
152+
{
153+
"name": "fs",
154+
"path": "../node_modules/uniq/",
155+
"main": "uniq"
156+
},
157+
{
158+
"name": "path",
159+
"path": "../node_modules/prr/",
160+
"main": "prr"
161+
},
162+
{
163+
"name": "crypto",
164+
"path": "../node_modules/ms/",
165+
"main": "index"
140166
}
141167
]
142168
}

aurelia_project/tasks/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ gulp.task('generate-service-worker', function (callback) {
1515
var baseUrl = project.baseUrl[env] || project.baseUrl['default'] || "/";
1616

1717
swPrecache.write(path.join('sw.js'), {
18+
maximumFileSizeToCacheInBytes: 5097152,
1819
staticFileGlobs: [
1920
'index.html',
2021
rootDir + '/**/*.{js,html,css}',

custom_typings/zxing.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module 'zxing' {
2+
}

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@
2020
"bootstrap": "^4.0.0-beta.3",
2121
"d3v4": "^4.2.2",
2222
"dexie": "^2.0.1",
23+
"instascan": "^1.0.0",
2324
"javascript-natural-sort": "^0.7.1",
2425
"lodash": "^4.17.4",
26+
"ms": "^2.1.1",
2527
"numeral": "^2.0.6",
28+
"prr": "^1.0.1",
29+
"qrcode-generator": "^1.4.1",
2630
"requirejs": "^2.3.2",
2731
"text": "github:requirejs/text#latest",
32+
"uniq": "^1.0.1",
2833
"urijs": "^1.19.1",
34+
"visibilityjs": "^2.0.2",
2935
"whatwg-fetch": "^2.0.3"
3036
},
3137
"peerDependencies": {},

src/app.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<li class='nav-item'>
1818
<a class="nav-link" route-href="route: graphtest">Graph Test</a>
1919
</li>
20+
21+
<li class='nav-item'>
22+
<a class="nav-link" route-href="route: qrtest">QR Code Test</a>
23+
</li>
2024
</ul>
2125
</div>
2226
</header>

src/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ export class App {
103103
name: "graphtest", moduleId: PLATFORM.moduleName("graphtest"),
104104
nav: true, title: "graph test", adminRoute: false,
105105
},
106+
{
107+
route: ["qrtest"],
108+
name: "qrtest", moduleId: PLATFORM.moduleName("qrcodes/test"),
109+
nav: true, title: "qrcode test", adminRoute: false,
110+
},
106111
];
107112

108113
config.map(routes);

src/qrcodes/display-dialog.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
3+
<ux-dialog>
4+
<ux-dialog-header>
5+
<button class='btn btn-danger btn-sm float-right' click.delegate='controller.cancel()'>
6+
X
7+
</button>
8+
</ux-dialog-header>
9+
<ux-dialog-body>
10+
<button click.delegate='click()'>zoop</button>
11+
<div element.ref="qrCodeElement"></div>
12+
</ux-dialog-body>
13+
<!--
14+
<ux-dialog-footer>
15+
</ux-dialog-footer>
16+
-->
17+
</ux-dialog>
18+
</template>

src/qrcodes/display-dialog.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { autoinject } from "aurelia-framework";
2+
import { QrCodeDisplayInput } from "./display-input";
3+
import * as qrcode from "qrcode-generator";
4+
import { DialogController } from "aurelia-dialog";
5+
6+
@autoinject
7+
export class QrCodeDisplayDialog {
8+
qrCodeElement: Element;
9+
10+
constructor(public controller: DialogController) {
11+
12+
}
13+
14+
activate(model: QrCodeDisplayInput) {
15+
16+
}
17+
18+
click() {
19+
// I think qrcode-generator is generating Model 2 qr codes? http://www.qrcode.com/en/codes/model12.html
20+
var qrType : TypeNumber = 25;
21+
var errorCorrection : ErrorCorrectionLevel = 'M';
22+
var mode: Mode = "Byte";
23+
var cellSize = 4; // default is 2
24+
var margin = 10; // default is cellSize * 4
25+
var data = "tacostacos";
26+
27+
var x = qrcode(qrType, errorCorrection);
28+
x.addData(data, mode);
29+
x.make();
30+
this.qrCodeElement.innerHTML = x.createImgTag(cellSize, margin);
31+
}
32+
}

src/qrcodes/display-input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface QrCodeDisplayInput {
2+
data: string;
3+
}

src/qrcodes/instascan/camera.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
export function cameraName(label) {
3+
var clean = label.replace(/\s*\([0-9a-f]+(:[0-9a-f]+)?\)\s*$/, '');
4+
return clean || label || null;
5+
}
6+
7+
export class Camera {
8+
id: any;
9+
name: string;
10+
private _streamPromise: Promise<MediaStream>;
11+
private _stream: MediaStream;
12+
13+
constructor(id, name) {
14+
this.id = id;
15+
this.name = name;
16+
this._stream = null;
17+
}
18+
19+
start(): Promise<MediaStream> {
20+
var constraints = {
21+
audio: false,
22+
video: {
23+
mandatory: {
24+
sourceId: this.id,
25+
minWidth: 600,
26+
maxWidth: 800,
27+
minAspectRatio: 1.6
28+
},
29+
optional: []
30+
}
31+
};
32+
33+
this._streamPromise = navigator.mediaDevices.getUserMedia(<MediaStreamConstraints>constraints);
34+
35+
return this._streamPromise.then(stream => {
36+
this._stream = stream;
37+
return stream;
38+
});
39+
}
40+
41+
stop() {
42+
if (!this._stream) {
43+
return;
44+
}
45+
46+
for (let stream of this._stream.getVideoTracks()) {
47+
stream.stop();
48+
}
49+
50+
this._stream = null;
51+
}
52+
53+
static getCameras(): Promise<any> {
54+
var devicesPromise = navigator.mediaDevices.enumerateDevices();
55+
56+
return devicesPromise.then(devices => {
57+
return devices
58+
.filter(d => d.kind === 'videoinput')
59+
.map(d => new Camera(d.deviceId, cameraName(d.label)));
60+
});
61+
}
62+
}

0 commit comments

Comments
 (0)