Skip to content

Commit

Permalink
Merge pull request #73 from tsedio/fix-liveview
Browse files Browse the repository at this point in the history
Fix liveview
  • Loading branch information
Romakita authored Dec 12, 2021
2 parents 27c2d16 + cf24c89 commit 8e49214
Show file tree
Hide file tree
Showing 63 changed files with 2,995 additions and 2,361 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 14.x ]
node-version: [ 12.x ]

steps:
- uses: actions/checkout@v2
Expand All @@ -32,8 +32,8 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest]
node-version: [ 12.x, 14.x, 15.x ]
os: [macos-latest]
node-version: [ 12.22.7 ]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:

strategy:
matrix:
node-version: [ 14.x ]
node-version: [ 12.x ]

steps:
- uses: actions/checkout@v2
Expand All @@ -87,7 +87,7 @@ jobs:

strategy:
matrix:
node-version: [ 14.x ]
node-version: [ 12.x ]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.18.2
12.22.7
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,26 @@ A Node.js wrapper for libgphoto2 written in TypeScript. Useful for remote contro

## Features

- Camera autodetection,
- Take a picture/movie capture,
- Take a preview,
- Retrieve camera list,
- Select camera,
- Take a liveview from camera and get binary or base64 of each frame, or write it to file,
- Display info about your camera (summary, about, manual).
- Camera autodetection,
- Take a picture/movie capture,
- Take a preview,
- Retrieve camera list,
- Select camera,
- Take a liveview from camera and get binary or base64 of each frame, or write it to file,
- Display info about your camera (summary, about, manual).

## Know issue

This package isn't compatible with Node.js 13 and higher version. `@tsed/gphoto2-driver use` `ref-array-napi` which have a
bug with some node.js version related [here](https://github.com/node-ffi-napi/ref-napi/issues/47).

The possible solutions would be:

- Find a way not to use ref-array-napi to manipulate C++ Array in Node.js,
- That the author of the module finds a solution to correct the problem,
- Redevelop the driver directly with NAPI.

Obviously any help is welcome to move the project forward :)

## Prerequisite

Expand Down
33 changes: 11 additions & 22 deletions jest.config.js → base.jest.config.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
const {join} = require("path");
const fixPath = require("normalize-path");
const packageDir = join(__dirname, 'packages');

module.exports = {
rootDir: __dirname,
module.exports = (rootDir) => ({
rootDir: fixPath(rootDir),
// Automatically clear mock calls and instances between every test
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: ["packages/gphoto2-*/src/**"],
collectCoverageFrom: ["<rootDir>/src/**"],

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",

// moduleDirectories: ["node_modules", "packages"],
// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: [],
coveragePathIgnorePatterns: ["index.ts", "GPUtils.ts", "__mock__"],
moduleNameMapper: {
"^@tsed/gphoto-(.*)$": "<rootDir>/packages/gphoto-$1/src"
},
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 17.22,
functions: 11.66,
lines: 23.32,
statements: 23.16
}
"^@tsed/gphoto2-core$": fixPath(join(packageDir, "gphoto2-core/src")),
"^@tsed/gphoto2-driver$": fixPath(join(packageDir, "gphoto2-driver/src")),
},

// An array of file extensions your modules use
Expand All @@ -37,20 +32,14 @@ module.exports = {
// The test environment that will be used for testing
testEnvironment: "node",

// The glob patterns Jest uses to detect test files
testMatch: [
"**/packages/*/src/**/__tests__/**/*.[jt]s?(x)",
"**/packages/*/src/**/?(*.)+(spec|test).[tj]s?(x)",
"**/packages/*/test/**/?(*.)+(spec|test).[tj]s?(x)"
],
// A map from regular expressions to paths to transformers
transform: {
"\\.(ts)$": "ts-jest"
},

preset: "ts-jest",

modulePathIgnorePatterns: ["<rootDir>/packages/*/lib", "<rootDir>/dist"],
modulePathIgnorePatterns: ["<rootDir>/lib", "<rootDir>/dist"],
// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: []
};
});
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"npmClient": "npm",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
"packages/*"
Expand Down
46 changes: 27 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"scripts": {
"configure": "monorepo ci configure",
"test": "yarn test:lint && yarn test:coverage",
"test:unit": "cross-env NODE_ENV=test jest",
"test:coverage": "yarn test:unit",
"test:unit": "cross-env NODE_ENV=test lerna run test",
"test:coverage": "yarn test:unit && yarn coverage:merge",
"coverage:merge": "istanbul-merge --out coverage/coverage-final.json 'packages/*/coverage/coverage-final.json' && nyc report --temp-dir ./coverage --reporter clover --reporter lcov --report-dir ./coverage",
"test:lint": "eslint packages --ext .ts",
"test:lint:fix": "eslint packages --ext .ts --fix",
"build": "monorepo build",
Expand All @@ -41,30 +42,37 @@
"start:widgets": "lerna run start:widgets"
},
"dependencies": {
"lerna": "4.0.0",
"@tsed/monorepo-utils": "1.17.0",
"@types/jest": "26.0.22",
"@types/ffi-napi": "4.0.4",
"@types/ref-napi": "3.0.4",
"@tsed/monorepo-utils": "1.19.3",
"@types/jest": "27.0.3",
"@types/node": "16.11.11",
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"cross-env": "7.0.3",
"eslint": "^7.10.0",
"eslint": "^8.4.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "24.3.5",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-jest": "25.3.0",
"eslint-plugin-prettier": "4.0.0",
"gflow": "5.1.2",
"husky": "6.0.0",
"jest": "26.6.3",
"lint-staged": "10.5.4",
"prettier": "2.2.1",
"istanbul-merge": "^1.1.1",
"nyc": "^15.1.0",
"jest": "27.4.3",
"lerna": "4.0.0",
"lint-staged": "12.1.2",
"normalize-path": "^3.0.0",
"prettier": "2.5.1",
"segfault-handler": "1.3.0",
"semantic-release": "17.4.2",
"ts-node": "9.1.1",
"ts-jest": "26.5.6",
"typescript": "4.2.4",
"tsconfig-paths": "3.9.0"
"semantic-release": "17.4.7",
"ts-jest": "27.0.7",
"ts-node": "10.4.0",
"tsconfig-paths": "3.12.0",
"typescript": "4.5.2"
},
"resolutions": {
"ref-napi": "3.0.3"
},
"devDependencies": {},
"workspaces": {
"packages": [
"packages/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"start:camera:autoselect": "ts-node -r tsconfig-paths/register src/camera-autoselect.ts",
"start:camera:info": "ts-node -r tsconfig-paths/register src/camera-info.ts",
"start:camera:list:autodetect": "ts-node -r tsconfig-paths/register src/camera-info.ts",
"start:camera:list:liveview": "ts-node -r tsconfig-paths/register src/camera-liveview.ts",
"start:camera:list:liveview:file": "ts-node -r tsconfig-paths/register src/list-liveview-file.ts",
"start:camera:list:liveview": "yarn ts-node -r tsconfig-paths/register src/camera-liveview.ts",
"start:camera:list:liveview:file": "yarn ts-node -r tsconfig-paths/register src/camera-liveview-file.ts",
"start:camera:scenario": "ts-node -r tsconfig-paths/register src/camera-scenario.ts",
"start:camera:scenario:async": "ts-node -r tsconfig-paths/register src/camera-scenario-async.ts",
"start:port:list": "ts-node -r tsconfig-paths/register src/port-list.ts",
Expand Down
12 changes: 11 additions & 1 deletion packages/gphoto2-core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
module.exports = require("../../jest.config");
module.exports = {
...require("../../base.jest.config")(__dirname),
coverageThreshold: {
global: {
branches: 91.89,
functions: 100,
lines: 100,
statements: 100
}
}
}
36 changes: 23 additions & 13 deletions packages/gphoto2-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
"name": "@tsed/gphoto2-core",
"version": "3.0.3",
"description": "Node.js wrapper of C library libgphoto2 written in TypeScript",
"main": "lib/index.js",
"typings": "lib/index.d.js",
"private": false,
"source": "./src/index.ts",
"main": "./lib/cjs/index.js",
"typings": "./lib/types/index.d.ts",
"exports": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js",
"default": "./lib/esm/index.js"
},
"author": "Romain Lenzotti",
"contributors": [
"Alexander Gusez (https://github.com/goooseman)"
Expand All @@ -25,26 +33,28 @@
"reflex"
],
"scripts": {
"build": "tsc --build tsconfig.compile.json",
"build:doc": "tsc --build tsconfig.doc.json"
"build": "yarn run build:esm && yarn run build:cjs",
"build:cjs": "tsc --build tsconfig.compile.json",
"build:esm": "tsc --build tsconfig.compile.esm.json",
"test": "cross-env NODE_ENV=test jest"
},
"dependencies": {
"@tsed/core": "6.92.0",
"@tsed/logger": "5.14.0",
"@tsed/core": "6.94.0",
"@tsed/logger": "6.0.0",
"ffi-napi": "4.0.3",
"ref-array-napi": "1.2.2",
"ref-napi": "3.0.2",
"ref-napi": "3.0.3",
"ref-struct-napi": "1.1.1",
"tslib": "2.2.0"
},
"devDependencies": {
"@types/ffi-napi": "2.4.3",
"@types/ref-napi": "^1.4.1"
"tslib": "2.3.1"
},
"devDependencies": {},
"directories": {
"lib": "lib",
"src": "src",
"test": "test"
},
"peerDependencies": {}
"peerDependencies": {
"@types/ffi-napi": ">=4.0.4",
"@types/ref-napi": ">=3.0.4"
}
}
57 changes: 55 additions & 2 deletions packages/gphoto2-core/src/GPhoto2Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IGPWidgetModule
} from "./modules";
import {getLibLocation} from "./utils/getLibLocation";
import {checkCode, CheckCodeException} from "./utils/checkCode";

/**
*
Expand All @@ -34,7 +35,8 @@ export interface GPhoto2Driver
IGPPortInfoModule {}

// tslint:disable-next-line
export let GPhoto2Driver: GPhoto2Driver & Record<string, any>;
export let GPhoto2Driver: GPhoto2Driver & Record<string, any> & RunnableDriverMethods;

export const driverFunctions = {
// CONTEXT
...GPContextModuleDescription,
Expand All @@ -58,8 +60,14 @@ export const driverFunctions = {
...GPWidgetModuleDescription
};

export interface RunnableDriverMethods {
run<T = any>(method: keyof GPhoto2Driver, ...args: any[]): T;

runAsync<T = any>(method: keyof GPhoto2Driver, ...args: any[]): Promise<T>;
}

// istanbul ignore next
export function getGPhoto2Driver(): GPhoto2Driver & Record<string, any> {
export function getGPhoto2Driver(): GPhoto2Driver & Record<string, any> & RunnableDriverMethods {
if (!GPhoto2Driver) {
const libPath = getLibLocation();

Expand All @@ -71,7 +79,52 @@ export function getGPhoto2Driver(): GPhoto2Driver & Record<string, any> {
});

GPhoto2Driver = driver;

driver.run = runMethod;
driver.runAsync = runAsyncMethod;
}

return GPhoto2Driver;
}

// istanbul ignore next
export function runMethod<T = any>(method: keyof GPhoto2Driver, ...args: any[]): T {
const driver = getGPhoto2Driver();

if (!driver[method]) {
throw new Error(`GPhoto2Driver.${method} doesn't exists`);
}

try {
const result = (driver[method] as any)(...args);
return checkCode(result, method);
} catch (er) {
if (er instanceof CheckCodeException) {
throw er;
}

$log.error(`Error when calling method GPhoto2Driver.${method}. ${er.message}`, er.stack);
process.exit(-1);
}
}

// istanbul ignore next
export async function runAsyncMethod<T = any>(method: keyof GPhoto2Driver, ...args: any[]): Promise<T> {
const driver = getGPhoto2Driver();

if (!driver[method]) {
throw new Error(`GPhoto2Driver.${method} doesn't exists`);
}
try {
const result = await (driver[method] as any)(...args);

return checkCode(result, method);
} catch (er) {
if (er instanceof CheckCodeException) {
throw er;
}

$log.error(`Error when calling method GPhoto2Driver.${method}. ${er.message}`, er.stack);
process.exit(-1);
}
}
3 changes: 1 addition & 2 deletions packages/gphoto2-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export * from "./types";
export * from "./GPhoto2Driver";
export * from "./utils/GPUtils";
export * from "./utils/GPPointer";
export * from "./utils/GPPointerRef";

getGPhoto2Driver();
process.env.NODE_ENV !== "test" && getGPhoto2Driver();
Loading

0 comments on commit 8e49214

Please sign in to comment.