Update readme
This commit is contained in:
88
README.md
88
README.md
@@ -12,69 +12,45 @@ yarn add web-gphoto2
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
**Note: This package ONLY runs in the browser context**. It will not work in NodeJS. If you are using a build-tool make sure to dynamically import this package so it is only imported in the browser context.
|
|
||||||
|
|
||||||
|
A short example on how to use this package:
|
||||||
```ts
|
```ts
|
||||||
let initModule: any;
|
import Camera from 'web-gphoto2';
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
let camera = new Camera();
|
||||||
import('web-gphoto2').then((module) => {
|
|
||||||
initModule = module.default;
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error("Error loading web-gphoto2", error);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.warn("web-gphoto2 is only available in the browser");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
A short example on how to use this package to obtain the camera config:
|
async function connectCamera() {
|
||||||
```ts
|
// @ts-ignore
|
||||||
// After importing the initModule from web-gphoto2
|
|
||||||
const ModulePromise = initModule();
|
|
||||||
|
|
||||||
export function rethrowIfCritical(err) {
|
|
||||||
if (err.constructor !== Error) throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function connect() {
|
|
||||||
const Module = await ModulePromise;
|
|
||||||
|
|
||||||
let context = await new Module.Context();
|
|
||||||
let supportedOps = await context.supportedOps();
|
|
||||||
|
|
||||||
let queue = Promise.resolve();
|
|
||||||
|
|
||||||
function schedule(op) {
|
|
||||||
let res = queue.then(() => op(context));
|
|
||||||
queue = res.catch(rethrowIfCritical);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
supportedOps,
|
|
||||||
schedule,
|
|
||||||
disconnect() {
|
|
||||||
context.delete();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select the camera, connect, and obtain the config. Error handling is omitted for brevity but should be included, check the example for details.
|
|
||||||
await navigator.usb.requestDevice({
|
await navigator.usb.requestDevice({
|
||||||
filters: [
|
filters: [{ classCode: 6, subclassCode: 1 }]
|
||||||
{
|
|
||||||
classCode: 6, // PTP
|
|
||||||
subclassCode: 1 // MTP
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
let connection = await connect();
|
await camera.connect();
|
||||||
let config = await connection.schedule((context: any) => context.configToJS());
|
}
|
||||||
console.log('Obtained config: ', config);
|
|
||||||
```
|
|
||||||
|
|
||||||
More information can be found in the example included in the Github repository.
|
async function getSupportedOps() {
|
||||||
|
const ops = await camera.getSupportedOps();
|
||||||
|
console.log('Supported Ops:', ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCameraConfig() {
|
||||||
|
const config = await camera.getConfig();
|
||||||
|
console.log('Config:', config);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateConfig() {
|
||||||
|
await camera.setConfigValue('iso', '800');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function capturePreviewAsBlob() {
|
||||||
|
const blob = await camera.capturePreviewAsBlob();
|
||||||
|
console.log('Blob:', blob);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function captureImageAsFile() {
|
||||||
|
const file = await camera.captureImageAsFile();
|
||||||
|
console.log('File:', file);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Common Issues
|
## Common Issues
|
||||||
### SharedArrayBuffer can not be found
|
### SharedArrayBuffer can not be found
|
||||||
|
|||||||
Reference in New Issue
Block a user