Skip to content

Commit

Permalink
Merge pull request #181 from ericblade/misc
Browse files Browse the repository at this point in the history
convert default config options to typescript
  • Loading branch information
ericblade committed May 1, 2020
2 parents 9efc4c5 + 1060489 commit 21e92e9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/config/config.dev.js → src/config/config.dev.ts
@@ -1,4 +1,6 @@
module.exports = {
import { QuaggaJSConfigObject } from '../../type-definitions/quagga';

const DevConfig: QuaggaJSConfigObject = {
inputStream: {
name: 'Live',
type: 'LiveStream',
Expand Down Expand Up @@ -49,3 +51,5 @@ module.exports = {
},
},
};

export default DevConfig;
6 changes: 5 additions & 1 deletion src/config/config.node.js → src/config/config.node.ts
@@ -1,4 +1,6 @@
module.exports = {
import { QuaggaJSConfigObject } from "../../type-definitions/quagga";

const NodeConfig: QuaggaJSConfigObject = {
inputStream: {
type: 'ImageStream',
sequence: false,
Expand All @@ -23,3 +25,5 @@ module.exports = {
patchSize: 'medium', // x-small, small, medium, large, x-large
},
};

export default NodeConfig;
6 changes: 5 additions & 1 deletion src/config/config.prod.js → src/config/config.prod.ts
@@ -1,4 +1,6 @@
module.exports = {
import { QuaggaJSConfigObject } from "../../type-definitions/quagga";

const ProdConfig: QuaggaJSConfigObject = {
inputStream: {
name: 'Live',
type: 'LiveStream',
Expand Down Expand Up @@ -29,3 +31,5 @@ module.exports = {
patchSize: 'medium', // x-small, small, medium, large, x-large
},
};

export default ProdConfig;
6 changes: 3 additions & 3 deletions src/config/config.ts
@@ -1,7 +1,7 @@
import { QuaggaBuildEnvironment, QuaggaJSConfigObject } from "../../type-definitions/quagga";
import * as DevConfig from './config.dev';
import * as NodeConfig from './config.node';
import * as ProdConfig from './config.prod';
import DevConfig from './config.dev';
import NodeConfig from './config.node';
import ProdConfig from './config.prod';

declare var ENV: QuaggaBuildEnvironment;

Expand Down
59 changes: 36 additions & 23 deletions src/quagga/setupInputStream.ts
@@ -1,31 +1,44 @@
import InputStream from "../input/input_stream";

export type InputStreamType = 'VideoStream' | 'ImageStream' | 'LiveStream';

function createVideoStream() {
const video = document.createElement('video');
return {
video,
inputStream: InputStream.createVideoStream(video),
};
}

function createImageStream() {
return { inputStream: InputStream.createImageStream() };
}

function createLiveStream(viewport: Element) {
let video: HTMLVideoElement | null = null;
if (viewport) {
video = viewport.querySelector('video');
if (!video) {
video = document.createElement('video');
viewport.appendChild(video);
}
}
return {
video,
inputStream: InputStream.createLiveStream(video),
};
}


// TODO: need to create an InputStream typescript interface, so we don't have an "any" in the next line
export default function setupInputStream(type: InputStreamType, viewport: HTMLElement, InputStream: any) {
export default function setupInputStream(type: InputStreamType, viewport: Element) {
switch (type) {
case 'VideoStream': {
const video = document.createElement('video');
return {
video,
inputStream: InputStream.createVideoStream(video),
};
}
case 'VideoStream':
return createVideoStream();
case 'ImageStream':
return { inputStream: InputStream.createImageStream() };
case 'LiveStream': { // TODO: test to see what happens if you run in node and ask for LiveStream, it probably fails spectacularly, and should fail gracefully
let video: HTMLVideoElement | null = null;
if (viewport) {
video = viewport.querySelector('video');
if (!video) {
video = document.createElement('video');
viewport.appendChild(video);
}
}
return {
video,
inputStream: InputStream.createLiveStream(video),
};
}
return createImageStream();
case 'LiveStream':
return createLiveStream(viewport);
default:
console.error(`* setupInputStream invalid type ${type}`);
return { video: null, inputStream: null };
Expand Down

0 comments on commit 21e92e9

Please sign in to comment.