diff --git a/.travis.yml b/.travis.yml index 9673bab6..12393c01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js - '6' -install: npm install +install: + - npm install + - npm i -g gulp script: gulp release env: global: diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..dad0b72a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, + "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..02fbae5a --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,18 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "gulp", + "task": "build", + "problemMatcher": [ + "$gulp-tsc" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 739f14a7..614e0a37 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,28 @@ Real-time webcam-driven HTML5 QR code scanner. [Try the live demo](https://schmi `npm install --save instascan` +JavaScript: + ```javascript const Instascan = require('instascan'); + +... + +Instascan.Camera.getCameras().then(cameras => { + // do something with the camera list +}); +``` + +TypeScript + +```typescript +import { Camera, Scanner } from "instascan"; + +... + +let cameras: Camera[] = await Camera.getCameras(); + +// do something with the camera list ``` ### Bower @@ -43,7 +63,8 @@ Copy `instascan.min.js` from the [releases](https://github.com/schmich/instascan }); Instascan.Camera.getCameras().then(function (cameras) { if (cameras.length > 0) { - scanner.start(cameras[0]); + scanner.camera = cameras[0]; + scanner.start(); } else { console.error('No cameras found.'); } @@ -67,6 +88,10 @@ let opts = { // If true, the scanner emits the "scan" event when a QR code is scanned. Default true. continuous: true, + // The camera to use for scanning. This can either be specified here in the options, or it + // can be set at a later time by setting the "scanner.camera" property. + camera: null, + // The HTML element to use for the camera's video preview. Must be a